vppapigen: allow decimal number in NUM token 63/20463/2
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Tue, 2 Jul 2019 17:00:58 +0000 (13:00 -0400)
committerDave Barach <openvpp@barachs.net>
Wed, 3 Jul 2019 11:29:39 +0000 (11:29 +0000)
Needed to set f64 default values.

Type: feature

Change-Id: Ic58ebc0d9d890bf0e7821894285e61a5bee13199
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
src/tools/vppapigen/vppapigen.py

index 9c6b21e..8ae991c 100755 (executable)
@@ -77,9 +77,12 @@ class VPPAPILexer(object):
     t_ignore_LINE_COMMENT = '//.*'
 
     def t_NUM(self, t):
-        r'0[xX][0-9a-fA-F]+|-?\d+'
+        r'0[xX][0-9a-fA-F]+|-?\d+\.?\d*'
         base = 16 if t.value.startswith('0x') else 10
-        t.value = int(t.value, base)
+        if '.' in t.value:
+            t.value = float(t.value)
+        else:
+            t.value = int(t.value, base)
         return t
 
     def t_ID(self, t):
@@ -123,6 +126,7 @@ def crc_block_combine(block, crc):
     s = str(block).encode()
     return binascii.crc32(s, crc) & 0xffffffff
 
+
 class Service():
     def __init__(self, caller, reply, events=None, stream=False):
         self.caller = caller