summaryrefslogtreecommitdiff
path: root/lex.h
diff options
context:
space:
mode:
Diffstat (limited to 'lex.h')
-rw-r--r--lex.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/lex.h b/lex.h
new file mode 100644
index 0000000..db4d713
--- /dev/null
+++ b/lex.h
@@ -0,0 +1,72 @@
+#include "typeutils.h"
+
+
+typedef struct Region Region;
+
+
+typedef enum {
+ UN_Q,
+ SINGLE_Q,
+ DOUBLE_Q,
+} QuotationMode;
+
+
+typedef enum {
+ LITERAL,
+ CMD_SUB,
+ ARITHM,
+ VAR_EXP, // TODO: Later include other exps
+} ChunkKind;
+
+
+typedef struct {
+ ChunkKind kind;
+ QuotationMode mode;
+
+ union {
+ char* lit_str;
+ Region* sub_cmd_region;
+ Region* arithm_expr_region;
+ char* param_string;
+ } as;
+} Chunk;
+
+
+DECLARE_VEC(Chunk, ChunkVec)
+
+typedef enum {
+ TOK_WORD,
+ TOK_SPECIAL,
+} TokenKind;
+
+typedef enum {
+ PIPE,
+ WRITE_REDIR_TRUNC,
+ WRITE_REDIR_APPEND,
+ READ_REDIR,
+ EOL,
+} SpecialToken;
+
+typedef struct {
+ TokenKind kind;
+
+ union {
+ ChunkVec word;
+ SpecialToken spec;
+ } as;
+} Token;
+
+
+DECLARE_VEC(Token, TokenVec)
+
+DECLARE_MAYBE(SpecialToken)
+
+
+struct Region {
+ QuotationMode mode;
+ TokenVec tokens;
+};
+
+DECLARE_MAYBE(Chunk);
+
+DECLARE_VEC(Region, RegionVec)