mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
tokenizer: Fix number parsing (again)
This commit is contained in:
parent
4fefa0bd73
commit
75475d1a45
1 changed files with 10 additions and 7 deletions
|
@ -40,9 +40,9 @@ _tokens = [
|
|||
(TokenType.IDENT, r"[A-Za-z_][\d\w\-_]*"),
|
||||
(TokenType.QUOTED, r'"(\\"|[^"\n])*"'),
|
||||
(TokenType.QUOTED, r"'(\\'|[^'\n])*'"),
|
||||
(TokenType.NUMBER, r"0x[A-Fa-f0-9_]+"),
|
||||
(TokenType.NUMBER, r"[-+]?[\d_]*\d(\.[\d_]*\d)?"),
|
||||
(TokenType.NUMBER, r"[-+]?\.[\d_]*\d"),
|
||||
(TokenType.NUMBER, r"0x[A-Za-z0-9_]+"),
|
||||
(TokenType.NUMBER, r"[-+]?[\d_]+(\.[\d_]+)?"),
|
||||
(TokenType.NUMBER, r"[-+]?\.[\d_]+"),
|
||||
(TokenType.WHITESPACE, r"\s+"),
|
||||
(TokenType.COMMENT, r"\/\*[\s\S]*?\*\/"),
|
||||
(TokenType.COMMENT, r"\/\/[^\n]*"),
|
||||
|
@ -67,10 +67,13 @@ class Token:
|
|||
return None
|
||||
|
||||
string = str(self).replace("_", "")
|
||||
try:
|
||||
if string.startswith("0x"):
|
||||
return int(string, 16)
|
||||
else:
|
||||
return float(string.replace("_", ""))
|
||||
except:
|
||||
raise CompileError(f"{str(self)} is not a valid number literal", self.start, self.end)
|
||||
|
||||
|
||||
def _tokenize(ui_ml: str):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue