core: lexer: Add comment skipping
Signed-off-by: Chloe M. <chloe@mirocom.org>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
static const char *toktab[] = {
|
||||
[TT_NONE] = symtok("none"),
|
||||
[TT_IDENT] = symtok("ident"),
|
||||
[TT_COMMENT] = symtok("comment"),
|
||||
[TT_INTLIT] = symtok("number"),
|
||||
[TT_LPAREN] = qtok("("),
|
||||
[TT_RPAREN] = qtok(")"),
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
typedef enum {
|
||||
TT_NONE, /* [none] */
|
||||
TT_IDENT, /* [identifier] */
|
||||
TT_COMMENT, /* [comment : ignored] */
|
||||
TT_INTLIT, /* [0-9]+ */
|
||||
TT_LPAREN, /* '(' */
|
||||
TT_RPAREN, /* '( */
|
||||
|
||||
Reference in New Issue
Block a user