#ifndef LEX_H #define LEX_H #include "typeutils.h" typedef struct ExpansionRegion ExpansionRegion; 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; ExpansionRegion* reg_ptr; char* varname; } as; } Chunk; DECLARE_VEC(Chunk, ChunkVec) typedef enum { TOK_WORD, TOK_SPECIAL, } TokenKind; typedef enum { PIPE, WRITE_REDIR_TRUNC, WRITE_REDIR_APPEND, READ_REDIR, L_PROC_SUB_IN, L_PROC_SUB_OUT, PAREN, EOL, } SpecialToken; typedef struct { TokenKind kind; union { ChunkVec word; SpecialToken spec; } as; } Token; DECLARE_VEC(Token, TokenVec) DECLARE_MAYBE(SpecialToken) typedef enum { CMD_SUB, ARITHM, } RegionMode; struct ExpansionRegion { RegionMode mode; TokenVec tokens; }; DECLARE_MAYBE(Chunk); DECLARE_VEC(ExpansionRegion, ExpansionRegionVec) typedef struct { TokenVec top_tokens; ExpansionRegionVec reg_arena; } LexResult; LexResult lex(char* input); #endif