summaryrefslogtreecommitdiff
path: root/src/preproc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/preproc.h')
-rw-r--r--src/preproc.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/preproc.h b/src/preproc.h
new file mode 100644
index 0000000..7907f9d
--- /dev/null
+++ b/src/preproc.h
@@ -0,0 +1,116 @@
+#pragma once
+
+#include "utils.h"
+
+typedef struct Region Region;
+
+
+// Lexing stage
+typedef enum {
+ UN_Q,
+ SINGLE_Q,
+ DOUBLE_Q,
+} QuotationMode;
+
+typedef enum {
+ LITERAL,
+ REGION_EXP,
+ VAR_EXP, // TODO: Later include other exps
+} ChunkKind;
+
+typedef struct {
+ ChunkKind kind;
+ QuotationMode qmode;
+ union {
+ char* literal_str;
+ Region* reg_ptr;
+ char* varname;
+ } as;
+} Chunk;
+DECLARE_MAYBE(Chunk, MaybeChunk);
+DECLARE_VEC(Chunk*, Word)
+
+typedef enum {
+ TOK_WORD,
+ TOK_SPECIAL,
+ TOK_PROCSUB_IN,
+ TOK_PROCSUB_OUT,
+} TokenKind;
+
+typedef enum {
+ PIPE,
+ WRITE_REDIR_TRUNC,
+ WRITE_REDIR_APPEND,
+ READ_REDIR,
+ EOL,
+} SpecialToken;
+DECLARE_MAYBE(SpecialToken, MaybeSpecialToken)
+
+typedef struct {
+ TokenKind kind;
+
+ union {
+ Word word;
+ SpecialToken spec;
+ Region* procsub_region;
+ } as;
+} Token;
+
+
+DECLARE_VEC(Token*, TokenPtrVec)
+
+
+typedef enum {
+ CMDS,
+ ARITHM,
+} RegionMode;
+
+struct Region {
+ RegionMode mode;
+ TokenPtrVec tokens;
+};
+DECLARE_VEC(Region, RegionVec)
+
+
+
+DECLARE_VEC(Chunk, ChunkVec)
+DECLARE_VEC(Token, TokenVec)
+
+
+
+// Lexing
+
+typedef struct {
+ RegionVec regions;
+ TokenVec tokens;
+ ChunkVec chunks;
+} PreprocArena;
+
+
+TokenPtrVec lex(char* input, PreprocArena* arena);
+
+
+// Parsing
+
+typedef enum {
+ CONN_PIPE,
+ CONN_EOL,
+ // TODO: add the |& thingy
+} Connector;
+
+DECLARE_MAYBE(Connector, MaybeConnector)
+
+typedef struct {
+ TokenVec cmd_toks;
+ Connector conn;
+} PipelineElement;
+
+DECLARE_VEC(PipelineElement, Pipeline)
+
+Pipeline parse_tokstream(Token* tokstream);
+
+
+
+
+
+