feat(ast): add newline token
This commit is contained in:
@@ -124,8 +124,10 @@ class Lexer:
|
|||||||
self.scan_comment_multiline()
|
self.scan_comment_multiline()
|
||||||
else:
|
else:
|
||||||
self.add_token(TokenType.SLASH_EQUAL if self.match("=") else TokenType.SLASH)
|
self.add_token(TokenType.SLASH_EQUAL if self.match("=") else TokenType.SLASH)
|
||||||
case " " | "\r" | "\t" | "\n":
|
case "\n":
|
||||||
while self.peek().isspace() and not self.is_at_end():
|
self.add_token(TokenType.NEWLINE)
|
||||||
|
case " " | "\r" | "\t":
|
||||||
|
while self.peek().isspace() and self.peek() != "\n" and not self.is_at_end():
|
||||||
self.advance()
|
self.advance()
|
||||||
self.add_token(TokenType.WHITESPACE)
|
self.add_token(TokenType.WHITESPACE)
|
||||||
case '"':
|
case '"':
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ class Parser:
|
|||||||
def synchronize(self):
|
def synchronize(self):
|
||||||
self.advance()
|
self.advance()
|
||||||
while not self.is_at_end():
|
while not self.is_at_end():
|
||||||
# TODO: if self.previous().type == TokenType.NEWLINE: return
|
if self.previous().type == TokenType.NEWLINE:
|
||||||
|
return
|
||||||
if self.peek().type in self.STATEMENT_BOUNDARY:
|
if self.peek().type in self.STATEMENT_BOUNDARY:
|
||||||
return
|
return
|
||||||
self.advance()
|
self.advance()
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class TokenType(Enum):
|
|||||||
COMMENT = auto()
|
COMMENT = auto()
|
||||||
WHITESPACE = auto()
|
WHITESPACE = auto()
|
||||||
EOF = auto()
|
EOF = auto()
|
||||||
|
NEWLINE = auto()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user