main+lexer: add support for single-line comments

This commit is contained in:
Antoine Viallon 2023-05-24 00:44:46 +02:00
parent 3f84890b52
commit ab7ee592c3
Signed by: aviallon
GPG key ID: D126B13AB555E16F
2 changed files with 2 additions and 1 deletions

View file

@ -38,7 +38,7 @@ def main():
print("Source:\n", data)
tokens = Lexer(data)
tokens = [token for token in tokens if token.kind not in [Tokens.Blank, Tokens.Newline]]
tokens = [token for token in tokens if token.kind not in [Tokens.Blank, Tokens.Newline, Tokens.Comment]]
if rootLogger.level <= LogLevel.Debug:
pprint(tokens)

View file

@ -45,6 +45,7 @@ class Tokens(enum.Enum):
Colon = re.compile(r":")
Semicolon = re.compile(r";")
Comma = re.compile(r",")
Comment = re.compile(r"//.*")
Newline = re.compile(r"\n", flags=re.MULTILINE)
EOF = re.compile(r"\Z")