From ab7ee592c3c278a2c196c5cfca0f06d6be1ca128 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Wed, 24 May 2023 00:44:46 +0200 Subject: [PATCH] main+lexer: add support for single-line comments --- compiler/__main__.py | 2 +- compiler/lexer.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/__main__.py b/compiler/__main__.py index 3cae61c..fca3eb2 100644 --- a/compiler/__main__.py +++ b/compiler/__main__.py @@ -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) diff --git a/compiler/lexer.py b/compiler/lexer.py index 603b429..77187dd 100644 --- a/compiler/lexer.py +++ b/compiler/lexer.py @@ -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")