feat(parser): split annotation and Midas keywords
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from lexer.base import Lexer
|
||||
from lexer.keyword import ANNOTATION_KEYWORDS
|
||||
from lexer.token import TokenType
|
||||
|
||||
|
||||
@@ -86,7 +87,10 @@ class AnnotationLexer(Lexer):
|
||||
"""
|
||||
while self.peek().isalnum() or self.peek() == "_":
|
||||
self.advance()
|
||||
self.add_token(TokenType.IDENTIFIER)
|
||||
|
||||
lexeme: str = self.source[self.start : self.idx]
|
||||
token_type: TokenType = ANNOTATION_KEYWORDS.get(lexeme, TokenType.IDENTIFIER)
|
||||
self.add_token(token_type)
|
||||
|
||||
def scan_comment(self):
|
||||
"""Scan the rest of a comment and add it as a token
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
from lexer.token import TokenType
|
||||
|
||||
KEYWORDS: dict[str, TokenType] = {
|
||||
ANNOTATION_KEYWORDS: dict[str, TokenType] = {
|
||||
"True": TokenType.TRUE,
|
||||
"False": TokenType.FALSE,
|
||||
"None": TokenType.NONE,
|
||||
}
|
||||
|
||||
MIDAS_KEYWORDS: dict[str, TokenType] = {
|
||||
"type": TokenType.TYPE,
|
||||
"op": TokenType.OP,
|
||||
"constraint": TokenType.CONSTRAINT,
|
||||
"true": TokenType.TRUE,
|
||||
"false": TokenType.FALSE,
|
||||
"none": TokenType.NONE,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from lexer.base import Lexer
|
||||
from lexer.keyword import KEYWORDS
|
||||
from lexer.keyword import MIDAS_KEYWORDS
|
||||
from lexer.token import TokenType
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ class MidasLexer(Lexer):
|
||||
self.advance()
|
||||
|
||||
lexeme: str = self.source[self.start : self.idx]
|
||||
token_type: TokenType = KEYWORDS.get(lexeme, TokenType.IDENTIFIER)
|
||||
token_type: TokenType = MIDAS_KEYWORDS.get(lexeme, TokenType.IDENTIFIER)
|
||||
self.add_token(token_type)
|
||||
|
||||
def scan_comment(self):
|
||||
|
||||
Reference in New Issue
Block a user