summaryrefslogtreecommitdiff
path: root/head
diff options
context:
space:
mode:
authorChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
committerChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
commit78b925a4d86b57e58e6322b7cad7bc47098618fd (patch)
treee66da7a598bb4be1ca869f72600112dda34a4067 /head
initial commit
There is some work to be done on top of this such as creating a way to manage memory to be freed later without needing to manually manage every pointer. Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'head')
-rw-r--r--head/defconf/lexer.h23
-rw-r--r--head/defconf/state.h41
-rw-r--r--head/defconf/token.h36
3 files changed, 100 insertions, 0 deletions
diff --git a/head/defconf/lexer.h b/head/defconf/lexer.h
new file mode 100644
index 0000000..6fb3828
--- /dev/null
+++ b/head/defconf/lexer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef DEFCONF_LEXER_H
+#define DEFCONF_LEXER_H 1
+
+#include <stdint.h>
+#include "defconf/token.h"
+#include "defconf/state.h"
+
+/*
+ * Scan for a single token
+ *
+ * @state: Defconf state machine
+ * @result: Result is written here
+ *
+ * Returns zero
+ */
+int lexer_scan(struct defconf_state *state, struct token *result);
+
+#endif /* !_DEFCONF_LEXER_H_ */
diff --git a/head/defconf/state.h b/head/defconf/state.h
new file mode 100644
index 0000000..524af3b
--- /dev/null
+++ b/head/defconf/state.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef DEFCONF_STATE_H
+#define DEFCONF_STATE_H 1
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdio.h>
+
+/*
+ * DEFCONF state machine
+ *
+ * @in_fp: Input file pointer
+ * @lex_cache: Putback cache
+ */
+struct defconf_state {
+ FILE *in_fp;
+ int lex_cache;
+};
+
+/*
+ * Initialize the defconf state machine
+ *
+ * @in_path: Input path
+ * @state: State machine result
+ *
+ * Returns zero on success
+ */
+int defconf_state_init(const char *in_path, struct defconf_state *state);
+
+/*
+ * Destroy the defconf state machine
+ *
+ * @state: State machine to destroy
+ */
+void defconf_state_destroy(struct defconf_state *state);
+
+#endif /* !DEFCONF_STATE_H */
diff --git a/head/defconf/token.h b/head/defconf/token.h
new file mode 100644
index 0000000..e1abd0a
--- /dev/null
+++ b/head/defconf/token.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef DEFCONF_TOKEN_H
+#define DEFCONF_TOKEN_H 1
+
+/*
+ * Valid token types
+ */
+typedef enum {
+ TT_NONE, /* [none] */
+ TT_DEFINE, /* 'define' */
+ TT_TRUE, /* 'true' */
+ TT_FALSE, /* 'false' */
+ TT_INTLIT, /* [0-9]+ */
+ TT_IDENT, /* [ident] */
+} tt_t;
+
+/*
+ * Represents a token
+ *
+ * @type: Token type
+ * @c: Associated character
+ * @s: Associated string
+ */
+struct token {
+ tt_t type;
+ union {
+ char c;
+ char *s;
+ };
+};
+
+#endif /* !DEFCONF_TOKEN_H */