diff --git a/lexer/annotations.py b/lexer/annotations.py index f72f81a..3ee18af 100644 --- a/lexer/annotations.py +++ b/lexer/annotations.py @@ -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 diff --git a/lexer/keyword.py b/lexer/keyword.py index a4f03cf..b66f21a 100644 --- a/lexer/keyword.py +++ b/lexer/keyword.py @@ -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, } diff --git a/lexer/midas.py b/lexer/midas.py index 86bfafe..42d8e6b 100644 --- a/lexer/midas.py +++ b/lexer/midas.py @@ -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):