summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/defconf-00.conf4
-rw-r--r--core/lexer.c36
-rw-r--r--core/parser.c5
-rw-r--r--head/defconf/token.h1
4 files changed, 45 insertions, 1 deletions
diff --git a/conf/defconf-00.conf b/conf/defconf-00.conf
index 028c8c5..fed0f7a 100644
--- a/conf/defconf-00.conf
+++ b/conf/defconf-00.conf
@@ -1,3 +1,7 @@
+//
+// Below are some variables to serve as a demonstration on how defconf can be used to generate
+// preprocessor define flags for C compilers.
+//
define MEOW_YES true
define MEOW_NO false
define MEOW_COUNT 3
diff --git a/core/lexer.c b/core/lexer.c
index 59aaa13..4f1b4aa 100644
--- a/core/lexer.c
+++ b/core/lexer.c
@@ -213,6 +213,29 @@ lexer_check_kw(const char *kw, struct token *result)
return -1;
}
+/*
+ * Skips an entire line, this is useful for comments
+ *
+ * @state: Defconf state
+ */
+static void
+lexer_skip_line(struct defconf_state *state)
+{
+ int c;
+
+ if (state == NULL) {
+ return;
+ }
+
+ for (;;) {
+ c = lexer_nom(state, false);
+ if (c == EOF)
+ return;
+ if (c == '\n')
+ return;
+ }
+}
+
int
lexer_scan(struct defconf_state *state, struct token *result)
{
@@ -228,6 +251,19 @@ lexer_scan(struct defconf_state *state, struct token *result)
return -1;
}
+ /* Check for single characters */
+ switch (c) {
+ case '/':
+ /* Is this a comment? */
+ if ((c = lexer_nom(state, false)) == '/') {
+ lexer_skip_line(state);
+ result->type = TT_COMMENT;
+ return 0;
+ }
+
+ break;
+ }
+
/* Scan for an identifier */
if ((ident = lexer_scan_ident(state, c)) != NULL) {
if (lexer_check_kw(ident, result) == 0) {
diff --git a/core/parser.c b/core/parser.c
index 79fda93..b5dc915 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -31,7 +31,8 @@ static const char *toktab[_TT_MAX] = {
[TT_TRUE] = TOKLIT("true"),
[TT_FALSE] = TOKLIT("false"),
[TT_INTLIT] = SYMTOK("int"),
- [TT_IDENT] = SYMTOK("ident")
+ [TT_IDENT] = SYMTOK("ident"),
+ [TT_COMMENT] = SYMTOK("comment")
};
static int
@@ -157,6 +158,8 @@ parse_begin(struct defconf_state *state)
}
break;
+ case TT_COMMENT:
+ break;
default:
trace_fatal(state, "got unexpected token: %s\n", TOKSTR(tok.type));
return -1;
diff --git a/head/defconf/token.h b/head/defconf/token.h
index 9db1a7e..e5b9c0d 100644
--- a/head/defconf/token.h
+++ b/head/defconf/token.h
@@ -16,6 +16,7 @@ typedef enum {
TT_FALSE, /* 'false' */
TT_INTLIT, /* [0-9]+ */
TT_IDENT, /* [ident] */
+ TT_COMMENT, /* [comment: ignored] */
_TT_MAX
} tt_t;