Change balanced token handling to allow mismatched gt/lt tokens

- These can be used for math, so we just assume the code is doing that
This commit is contained in:
Dustin Spicuzza
2022-12-09 03:26:16 -05:00
parent b08d8783d4
commit 8a0568c0f5
2 changed files with 91 additions and 10 deletions

View File

@@ -230,16 +230,24 @@ class CxxParser:
if tok.type in self._end_balanced_tokens:
expected = match_stack.pop()
if tok.type != expected:
# hack: ambiguous right-shift issues here, really
# should be looking at the context
if tok.type == ">":
tok = self.lex.token_if(">")
if tok:
consumed.append(tok)
match_stack.append(expected)
continue
# hack: we only claim to parse correct code, so if this
# is less than or greater than, assume that the code is
# doing math and so this unexpected item is correct.
#
# If one of the other items on the stack match, pop back
# to that. Otherwise, ignore it and hope for the best
if tok.type != ">" and expected != ">":
raise self._parse_error(tok, expected)
for i, maybe in enumerate(reversed(match_stack)):
if tok.type == maybe:
for _ in range(i + 1):
match_stack.pop()
break
else:
match_stack.append(expected)
continue
raise self._parse_error(tok, expected)
if len(match_stack) == 0:
return consumed