mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
tokenizer: Fix number parsing
This commit is contained in:
parent
99e428d93c
commit
f479e2bac5
1 changed files with 3 additions and 3 deletions
|
@ -40,7 +40,7 @@ _tokens = [
|
||||||
(TokenType.IDENT, r"[A-Za-z_][\d\w\-_]*"),
|
(TokenType.IDENT, r"[A-Za-z_][\d\w\-_]*"),
|
||||||
(TokenType.QUOTED, r'"(\\"|[^"\n])*"'),
|
(TokenType.QUOTED, r'"(\\"|[^"\n])*"'),
|
||||||
(TokenType.QUOTED, r"'(\\'|[^'\n])*'"),
|
(TokenType.QUOTED, r"'(\\'|[^'\n])*'"),
|
||||||
(TokenType.NUMBER, r"0x[A-Fa-f0-9]+"),
|
(TokenType.NUMBER, r"0x[A-Fa-f0-9_]+"),
|
||||||
(TokenType.NUMBER, r"[-+]?[\d_]*\d(\.[\d_]*\d)?"),
|
(TokenType.NUMBER, r"[-+]?[\d_]*\d(\.[\d_]*\d)?"),
|
||||||
(TokenType.NUMBER, r"[-+]?\.[\d_]*\d"),
|
(TokenType.NUMBER, r"[-+]?\.[\d_]*\d"),
|
||||||
(TokenType.WHITESPACE, r"\s+"),
|
(TokenType.WHITESPACE, r"\s+"),
|
||||||
|
@ -66,11 +66,11 @@ class Token:
|
||||||
if self.type != TokenType.NUMBER:
|
if self.type != TokenType.NUMBER:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
string = str(self)
|
string = str(self).replace("_", "")
|
||||||
if string.startswith("0x"):
|
if string.startswith("0x"):
|
||||||
return int(string, 16)
|
return int(string, 16)
|
||||||
else:
|
else:
|
||||||
return float(string)
|
return float(string.replace("_", ""))
|
||||||
|
|
||||||
|
|
||||||
def _tokenize(ui_ml: str):
|
def _tokenize(ui_ml: str):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue