diff --git a/frontend/lexer.c b/frontend/lexer.c index 4dbd0f6..63bcffe 100644 --- a/frontend/lexer.c +++ b/frontend/lexer.c @@ -312,6 +312,23 @@ lexer_scan_shellblock(struct quip_state *state, struct token *tokres) return 0; } +/* + * Skip a source code comment + * + * @state: Quip state + */ +static void +lexer_skip_comment(struct quip_state *state) +{ + char c; + + while ((c = lexer_consume(state, false)) != '\n') { + if (c == '\0') { + break; + } + } +} + int lexer_scan(struct quip_state *state, struct token *tokres) { @@ -335,6 +352,11 @@ lexer_scan(struct quip_state *state, struct token *tokres) return -1; } + return 0; + case '#': + tokres->type = TT_COMMENT; + tokres->c = c; + lexer_skip_comment(state); return 0; case ':': tokres->c = c; diff --git a/frontend/parser.c b/frontend/parser.c index 833f495..bc1ca78 100644 --- a/frontend/parser.c +++ b/frontend/parser.c @@ -38,6 +38,7 @@ static const char *toktab[] = { [TT_NAME] = symtok("name"), [TT_NEWLINE] = symtok("newline"), [TT_SHELLBLOCK] = symtok("shellblock"), + [TT_COMMENT] = symtok("comment"), [TT_CC] = qtok(".cc"), [TT_LD] = qtok(".ld"), [TT_COLON] = qtok(":") diff --git a/include/frontend/token.h b/include/frontend/token.h index 4aa507c..a877eb3 100644 --- a/include/frontend/token.h +++ b/include/frontend/token.h @@ -19,6 +19,7 @@ typedef enum { TT_NAME, /* [name] */ TT_NEWLINE, /* [newline] */ TT_SHELLBLOCK, /* [shellblock] */ + TT_COMMENT, /* [comment] */ TT_CC, /* '.cc' */ TT_LD, /* '.ld' */ TT_COLON, /* ':' */