changed author email
[guish.git] / src / tokenizer.h
blob9db9707f30cee1038459caa718534864d9ced847
1 /*************************************************************************
2 * Copyright (C) 2024 Francesco Palumbo <phranz.dev@gmail.com>, Naples (Italy)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *************************************************************************/
18 #ifndef TOKENIZER_H
19 #define TOKENIZER_H
22 typedef struct vec_token_t vec_token_t;
23 typedef struct vec_token_t phrase_t;
24 typedef struct block_t block_t;
26 enum toktype {
27 T_ELEM,
28 T_DEFINE,
29 T_DEFATTR,
30 T_RANGE,
31 T_CODE,
32 T_ENDCODE,
33 T_QUOTE,
34 T_DQUOTE,
35 T_CMD,
36 T_EXPR,
37 T_ENDEXPR,
38 T_SLICE,
39 T_ENDSLICE,
40 T_SHELLSUB,
41 T_WIDSUB,
42 T_VARSUB,
43 T_ARGSSUB,
44 T_ATTR,
45 T_GLOB,
46 T_INVALID,
47 T_BLOCK,
48 T_END,
51 #define TOKNAMES() \
52 const char* toknames[] = { \
53 "T_ELEM", \
54 "T_DEFINE", \
55 "T_DEFATTR", \
56 "T_RANGE", \
57 "T_CODE", \
58 "T_ENDCODE", \
59 "T_QUOTE", \
60 "T_DQUOTE", \
61 "T_CMD", \
62 "T_EXPR", \
63 "T_ENDEXPR", \
64 "T_SLICE", \
65 "T_ENDSLICE", \
66 "T_SHELLSUB", \
67 "T_WIDSUB", \
68 "T_VARSUB", \
69 "T_ARGSSUB", \
70 "T_ATTR", \
71 "T_GLOB", \
72 "T_INVALID", \
73 "T_BLOCK", \
74 "T_END", \
77 typedef struct token_t {
78 int type;
79 union {
80 char* data;
81 block_t* block;
83 unsigned long long lineno;
84 char* source;
85 void (*free)(struct token_t*);
86 } token_t;
88 token_t* copy_token(token_t*);
89 token_t* token_t_init(token_t*);
90 void token_t_free(token_t*);
92 void release_phrase(vec_token_t*);
93 phrase_t* copy_phrase(phrase_t*);
94 phrase_t* tokenize();
96 #endif