summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/lexer.c30
-rw-r--r--core/parser.c23
2 files changed, 42 insertions, 11 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);
diff --git a/core/parser.c b/core/parser.c
index a584a56..3b3e91b 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -30,17 +30,18 @@
* Converts numeric tokens into human readable strings
*/
static const char *toktab[] = {
- [TT_NONE] = symtok("none"),
- [TT_IDENT] = symtok("ident"),
- [TT_INTLIT] = symtok("number"),
- [TT_LPAREN] = qtok("("),
- [TT_RPAREN] = qtok(")"),
- [TT_COMMA] = qtok(","),
- [TT_RETURN] = qtok("return"),
- [TT_PUB] = qtok("pub"),
- [TT_PROC] = qtok("proc"),
- [TT_BEGIN] = qtok("begin"),
- [TT_END] = qtok("end")
+ [TT_NONE] = symtok("none"),
+ [TT_IDENT] = symtok("ident"),
+ [TT_COMMENT] = symtok("comment"),
+ [TT_INTLIT] = symtok("number"),
+ [TT_LPAREN] = qtok("("),
+ [TT_RPAREN] = qtok(")"),
+ [TT_COMMA] = qtok(","),
+ [TT_RETURN] = qtok("return"),
+ [TT_PUB] = qtok("pub"),
+ [TT_PROC] = qtok("proc"),
+ [TT_BEGIN] = qtok("begin"),
+ [TT_END] = qtok("end")
};
int