Add dump_tokens.py

This commit is contained in:
germax26 2024-10-01 19:02:20 +10:00
parent 9e68c529bf
commit 5c02a9f858
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM
3 changed files with 14 additions and 1 deletions

10
dump_tokens.py Normal file
View File

@ -0,0 +1,10 @@
import sys
from ppp_lexer import Lexer
from ppp_tokens import EofToken
_program, file_path = sys.argv
lexer = Lexer.from_file(file_path)
while not lexer.check_token(EofToken()): print(lexer.next_token())

View File

@ -60,9 +60,9 @@ class Lexer:
return self._token(loc, word, IdentifierToken(word))
case '"':
# TODO: Proper escaping
loc = self._loc()
self._advance()
start_location = self._location
loc = self._loc()
escaping = False
while self._location < len(self._source) and (self._source[self._location] != '"' or escaping):
escaping = self._source[self._location] == '\\' if not escaping else False

View File

@ -106,3 +106,6 @@ class Token:
loc: Location
value: str
contents: TokenContents
def __repr__(self) -> str:
return f"{self.loc}: {self.contents}"