summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorChloe M. <chloe@mirocom.org>2026-05-23 19:03:15 -0400
committerChloe M. <chloe@mirocom.org>2026-05-23 19:03:15 -0400
commit8483d3c4456108cfaf469d4d3867608458f39138 (patch)
tree1f948bd59c83313353e6d10f2d7bb5bb674fc40f /core
parent71f232282a6bb3a45bd020e3681ac0dd90371c63 (diff)
core: parser: Add initial preprocessing stubs
Signed-off-by: Chloe M. <chloe@mirocom.org>
Diffstat (limited to 'core')
-rw-r--r--core/cescal.c6
-rw-r--r--core/parser.c52
-rw-r--r--core/state.c1
3 files changed, 52 insertions, 7 deletions
diff --git a/core/cescal.c b/core/cescal.c
index 0121389..c41f7cd 100644
--- a/core/cescal.c
+++ b/core/cescal.c
@@ -29,8 +29,10 @@ compile(const char *pathname)
return -1;
}
- if (parser_parse(&st) < 0) {
- return -1;
+ for (int i = 0; i < 2; ++i) {
+ if (parser_parse(&st) < 0) {
+ return -1;
+ }
}
state_close(&st);
diff --git a/core/parser.c b/core/parser.c
index 4779803..48640d8 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -58,6 +58,35 @@ static const char *toktab[] = {
[TT_U64] = qtok("u64")
};
+/*
+ * Push a token to the token buffer in the preprocessing stage
+ *
+ * @tokbuf: Token buffer to push to
+ * @tok: Token to push
+ *
+ * Returns zero on success
+ */
+static int
+preprocessor_push(struct tokbuf *tokbuf, struct token *tok)
+{
+ if (tokbuf == NULL || tok == NULL) {
+ return -1;
+ }
+
+ switch (tok->type) {
+ case TT_IFNDEF:
+ case TT_IFDEF:
+ case TT_DEFINE:
+ break;
+ default:
+ if (tokbuf_push(tokbuf, tok) < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
static int
parser_nom(struct cescal_state *state, struct token *res)
{
@@ -68,12 +97,24 @@ parser_nom(struct cescal_state *state, struct token *res)
return -1;
}
- if (lexer_nom(state, &tok) < 0) {
- return -1;
- }
+ switch (state->pass) {
+ case 0: /* Pre-processor */
+ if (lexer_nom(state, &tok) < 0) {
+ return -1;
+ }
- if (tokbuf_push(&state->tokbuf, &tok) < 0) {
- return -1;
+ printf("* %s\n", tokstr(&tok));
+ if (preprocessor_push(&state->tokbuf, &tok) < 0) {
+ return -1;
+ }
+
+ break;
+ case 1: /* Parse */
+ if (tokbuf_pop(&state->tokbuf, &tok) < 0) {
+ return -1;
+ }
+
+ break;
}
*res = tok;
@@ -94,5 +135,6 @@ parser_parse(struct cescal_state *state)
cc_trace("got token %s\n", tokstr(&tok));
}
+ ++state->pass;
return 0;
}
diff --git a/core/state.c b/core/state.c
index fe9f9fa..f6ed48e 100644
--- a/core/state.c
+++ b/core/state.c
@@ -6,6 +6,7 @@
#include <stdint.h>
#include <stddef.h>
#include <fcntl.h>
+#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "cescal/state.h"