summaryrefslogtreecommitdiff
path: root/core/lexer.c
diff options
context:
space:
mode:
authorChloe M. <chloe@mirocom.org>2026-05-23 08:09:05 -0400
committerChloe M. <chloe@mirocom.org>2026-05-23 08:13:45 -0400
commit3e3ccae003ad0990555d17590588672aedc428c4 (patch)
tree897ee125560e4b183e96230e040999bdb8ebd559 /core/lexer.c
parent50bd6324feb9c129067cb60586e8690fee1a81bf (diff)
core: lexer: Add comment skipping
Signed-off-by: Chloe M. <chloe@mirocom.org>
Diffstat (limited to 'core/lexer.c')
-rw-r--r--core/lexer.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/lexer.c b/core/lexer.c
index 617ba41..26ab451 100644
--- a/core/lexer.c
+++ b/core/lexer.c
@@ -183,6 +183,27 @@ lexer_check_kw(struct cescal_state *state, struct token *res)
}
}
+/*
+ * Skip anything after a comment
+ *
+ * @state: Compiler state
+ */
+static void
+lexer_skip_comment(struct cescal_state *state)
+{
+ char c;
+
+ if (state == NULL) {
+ return;
+ }
+
+ while ((c = lexer_consume_single(state, false)) != '\n') {
+ if (c == '\0') {
+ break;
+ }
+ }
+}
+
int
lexer_nom(struct cescal_state *state, struct token *res)
{
@@ -210,6 +231,15 @@ lexer_nom(struct cescal_state *state, struct token *res)
res->type = TT_COMMA;
res->c = c;
return 0;
+ case '/':
+ if (lexer_consume_single(state, true) == '/') {
+ res->type = TT_COMMENT;
+ res->c = c;
+ lexer_skip_comment(state);
+ return 0;
+ }
+
+ return -1;
default:
if (lexer_scan_ident(state, c, res) == 0) {
lexer_check_kw(state, res);