diff options
Diffstat (limited to 'projects/hackc/tokens.py')
-rw-r--r-- | projects/hackc/tokens.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/projects/hackc/tokens.py b/projects/hackc/tokens.py index 7ae37ce..50c4173 100644 --- a/projects/hackc/tokens.py +++ b/projects/hackc/tokens.py @@ -35,7 +35,7 @@ class Token: self.column = column @classmethod - def from_line(cls, line: str, line_no: int, column: int): + def from_line(cls, line: str, line_no: int, column: int, extensions=[]): """Extract first token from line and return it as an instance of Token.""" if not line: return None @@ -47,7 +47,11 @@ class Token: if int_match is not None: return Token("integer", int_match.group(1), line_no, column) - str_match = re.match('(".*")', line) + if "escape" in extensions: + str_match = re.match(r'("(.|\\")+?[^\\]")', line) + else: + str_match = re.match('(".*?")', line) + if str_match is not None: return Token("string", str_match.group(1), line_no, column) |