parser: preserve number base

pull/12152/head
Charles Brunet 1 year ago
parent 3ff3b8abf6
commit 5707d39017
  1. 2
      mesonbuild/cargo/builder.py
  2. 2
      mesonbuild/cmake/interpreter.py
  3. 12
      mesonbuild/mparser.py

@ -45,7 +45,7 @@ def number(value: int, filename: str) -> mparser.NumberNode:
:param filename: the file that the value came from :param filename: the file that the value came from
:return: A NumberNode :return: A NumberNode
""" """
return mparser.NumberNode(_token('number', filename, value)) return mparser.NumberNode(_token('number', filename, str(value)))
def bool(value: builtins.bool, filename: str) -> mparser.BooleanNode: def bool(value: builtins.bool, filename: str) -> mparser.BooleanNode:

@ -966,7 +966,7 @@ class CMakeInterpreter:
return IdNode(token(val=value)) return IdNode(token(val=value))
def number(value: int) -> NumberNode: def number(value: int) -> NumberNode:
return NumberNode(token(val=value)) return NumberNode(token(val=str(value)))
def nodeify(value: TYPE_mixed_list) -> BaseNode: def nodeify(value: TYPE_mixed_list) -> BaseNode:
if isinstance(value, str): if isinstance(value, str):

@ -217,7 +217,7 @@ class Lexer:
lineno += len(lines) - 1 lineno += len(lines) - 1
line_start = mo.end() - len(lines[-1]) line_start = mo.end() - len(lines[-1])
elif tid == 'number': elif tid == 'number':
value = int(match_text, base=0) value = match_text
elif tid == 'eol_cont': elif tid == 'eol_cont':
lineno += 1 lineno += 1
line_start = loc line_start = loc
@ -285,8 +285,16 @@ class IdNode(ElementaryNode[str]):
def __str__(self) -> str: def __str__(self) -> str:
return "Id node: '%s' (%d, %d)." % (self.value, self.lineno, self.colno) return "Id node: '%s' (%d, %d)." % (self.value, self.lineno, self.colno)
@dataclass(unsafe_hash=True)
class NumberNode(ElementaryNode[int]): class NumberNode(ElementaryNode[int]):
pass
raw_value: str = field(hash=False)
def __init__(self, token: Token[str]):
BaseNode.__init__(self, token.lineno, token.colno, token.filename)
self.raw_value = token.value
self.value = int(token.value, base=0)
self.bytespan = token.bytespan
class StringNode(ElementaryNode[str]): class StringNode(ElementaryNode[str]):
def __str__(self) -> str: def __str__(self) -> str:

Loading…
Cancel
Save