Add dump_tokens.py
This commit is contained in:
parent
9e68c529bf
commit
5c02a9f858
10
dump_tokens.py
Normal file
10
dump_tokens.py
Normal 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())
|
@ -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
|
||||
|
@ -106,3 +106,6 @@ class Token:
|
||||
loc: Location
|
||||
value: str
|
||||
contents: TokenContents
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.loc}: {self.contents}"
|
||||
|
Loading…
Reference in New Issue
Block a user