Skip to content

Commit

Permalink
fix parsing of nans
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Aug 7, 2024
1 parent 79e9bc5 commit e2e188f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions FrontEnd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class TK_KIND(enum.Enum):
(TK_KIND.MSTR.name, string_re.MULTI_START),
(TK_KIND.RMSTR.name, string_re.MULTI_START_R),
(TK_KIND.XMSTR.name, string_re.MULTI_START_X),
(TK_KIND.COMPOUND_ASSIGN.name, "(?:" + "|".join(_compound_assignment)) + r")(?=\s|$)"),
(TK_KIND.COMPOUND_ASSIGN.name,
"(?:" + "|".join(_compound_assignment) + r")(?=\s|$)"),
(TK_KIND.ID.name, ID_RE),
# require binary ops to be followed by whitespace, this helps with
# disambiguating unary +/-
Expand All @@ -157,12 +158,14 @@ class TK_KIND(enum.Enum):

TOKEN_RE = re.compile("|".join(f'(?P<{a}>{b})' for a, b in _token_spec))


def assert_match(a, b=None):
# note that re.fullmatch tries harder to match the full string than match
if b is None:
b = a
assert TOKEN_RE.match(a).group() == b


assert_match("0.0_r64")
assert_match("5_u16")
assert_match("5_u16")
Expand Down Expand Up @@ -837,10 +840,12 @@ def _ParseStatement(inp: Lexer):
else:
# this happends inside a macro body
if not kw.text.startswith("$"):
cwast.CompilerError(kw.srcloc, f"expect macro var but got {kw.text}")
cwast.CompilerError(
kw.srcloc, f"expect macro var but got {kw.text}")
return cwast.MacroId(kw.text)
if kw.kind is not TK_KIND.KW:
cwast.CompilerError(kw.srcloc, f"expected statement keyword but got: {kw}")
cwast.CompilerError(
kw.srcloc, f"expected statement keyword but got: {kw}")
if kw.text in ("let", "let!", "mlet", "mlet!"):
name = inp.match_or_die(TK_KIND.ID)
if inp.match(TK_KIND.ASSIGN):
Expand Down

0 comments on commit e2e188f

Please sign in to comment.