summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2020-04-05 13:46:47 -0400
committergumi <git@gumi.ca>2020-05-07 16:09:29 -0400
commit61d48481b607d2cee780e0141d3dfcf96bcefe15 (patch)
tree326a342123e0e322780a174f8b9c195581d3efd8 /tools
parentfc77e102b35e38a375dd0f419bf490b7fe4c379c (diff)
downloadhercules-61d48481b607d2cee780e0141d3dfcf96bcefe15.tar.gz
hercules-61d48481b607d2cee780e0141d3dfcf96bcefe15.tar.bz2
hercules-61d48481b607d2cee780e0141d3dfcf96bcefe15.tar.xz
hercules-61d48481b607d2cee780e0141d3dfcf96bcefe15.zip
add support for binary and octal literals in the python libconf parser
Diffstat (limited to 'tools')
-rw-r--r--tools/utils/libconf.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/utils/libconf.py b/tools/utils/libconf.py
index 3858b93b5..be4d67e54 100644
--- a/tools/utils/libconf.py
+++ b/tools/utils/libconf.py
@@ -141,6 +141,8 @@ class IntToken(Token):
super(IntToken, self).__init__(*args, **kwargs)
self.is_long = self.text.endswith('L')
self.is_hex = (self.text[1:2].lower() == 'x')
+ self.is_oct = (self.text[1:2].lower() == 'o')
+ self.is_bin = (self.text[1:2].lower() == 'b')
self.value = int(self.text.rstrip('L'), 0)
@@ -184,6 +186,10 @@ class Tokenizer:
r'([-+]?(\d+)(\.\d*)?[eE][-+]?\d+)'),
(IntToken, 'hex64', r'0[Xx][0-9A-Fa-f]+(L(L)?)'),
(IntToken, 'hex', r'0[Xx][0-9A-Fa-f]+'),
+ (IntToken, 'oct64', r'0[Oo][0-7]+(L(L)?)'),
+ (IntToken, 'oct', r'0[Oo][0-7]+'),
+ (IntToken, 'bin64', r'0[Bb][01]+(L(L)?)'),
+ (IntToken, 'bin', r'0[Bb][01]+'),
(BoolToken, 'boolean', r'(?i)(true|false)\b'),
(StrToken, 'string', r'"([^"\\]|\\.)*"'),
(StrToken, 'string', r'<"(?<=<")([\S\s]*?)(?=">)">'),
@@ -422,7 +428,8 @@ class Parser:
def scalar_value(self):
# This list is ordered so that more common tokens are checked first.
acceptable = [self.string, self.boolean, self.integer, self.float,
- self.hex, self.integer64, self.hex64]
+ self.hex, self.oct, self.bin, self.integer64, self.hex64,
+ self.oct64, self.bin64]
return self._parse_any_of(acceptable)
def value_list_or_empty(self):
@@ -455,6 +462,18 @@ class Parser:
def hex64(self):
return self._create_value_node('hex64')
+ def oct(self):
+ return self._create_value_node('oct')
+
+ def oct64(self):
+ return self._create_value_node('oct64')
+
+ def bin(self):
+ return self._create_value_node('bin')
+
+ def bin64(self):
+ return self._create_value_node('bin64')
+
def float(self):
return self._create_value_node('float')