use strbuff instead of str_buff & str_idx
[build-config.git] / src / config / lxrgmr-code / token / code.var
blobad727789663707f4d9055d21df56e022ae07a130
2 /*
3  * code:
4  * it's a default state for script.
5  */
7 enum {
8         FLAG_INIT = 0,
9         FLAG_CODE,
10 //      FLAG_FIRST_TOKEN,
12         FLAG_STATEMENT,
13         FLAG_CMD,
14         FLAG_DOLLAR,
15 } PARSING_FLAGS;
18 /**
19  ** c preproc cmd char.
20  **/
21 const struct token_id macro_array[] = {
22         { "include",                            "T_MINCLUDE",           STATE_CODE,                     T_MINCLUDE,             TF_MACRO,               NULL },
23         { "ifndef",                                     "T_MIFNDEF",            STATE_CODE,                     T_MIFNDEF,              TF_MACRO,               NULL },
24         { "define",                                     "T_MDEFINE",            STATE_CODE,                     T_MDEFINE,              TF_MACRO,               NULL },
25         { "pragma",                                     "T_MPRAGMA",            STATE_CODE,                     T_MPRAGMA,              TF_MACRO,               NULL },
26         { "ifdef",                                      "T_MIFDEF",                     STATE_CODE,                     T_MIFDEF,               TF_MACRO,               NULL },
27         { "endif",                                      "T_MENDIF",                     STATE_CODE,                     T_MENDIF,               TF_MACRO,               NULL },
28         { "else",                                       "T_MELSE",                      STATE_CODE,                     T_MELSE,                TF_MACRO,               NULL },
29         { "link",                                       "T_MLINK",                      STATE_CODE,                     T_MLINK,                TF_MACRO,               NULL },
30         { "if",                                         "T_MIF",                        STATE_CODE,                     T_MIF,                  TF_MACRO,               NULL },
31         
32         { NULL,                                         NULL,                           0,                                      0,                              0,                              0 },
34 short au16MacroTokenLen[ARRAY_SIZE(macro_array)];
36 /**
37  ** prefix char.
38  **/
39 const struct token_id pfx_char_array[] = {
40         { .chars={"//"},                        "T_C99_CMNT_HDR",       STATE_CODE,                     T_C99_CMNT_HDR, TF_PFX,                 &on_c99_cmnt_proc },
41         { .chars={"#"},                         "T_SH_CMNT_HDR",        STATE_CODE,                     T_SH_CMNT_HDR,  TF_PFX,                 &on_sh_cmnt_proc },
42         
43         { .chars={"!"},                         "T_EXCLAM",                     STATE_CODE,                     T_EXCLAM,               TF_PFX,                 &on_dollar_proc },
45         { .chars={"$"},                         "T_DOLLAR",                     STATE_CODE,                     T_DOLLAR,               TF_PFX,                 &on_dollar_proc },
46         { .chars={"<"},                         "T_LT",                 0,                                              T_LT,           TF_PFX,                 &on_dollar_proc },
47         { .chars={">"},                         "T_GT",                 0,                                              T_GT,           TF_PFX,                 &on_dollar_proc },
48         
49         { {NULL},                                       NULL,                           0,                                      0,                              0,                              NULL },
52 int on_dollar_proc (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
53 int on_c99_cmnt_proc (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
54 int on_sh_cmnt_proc (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
55 int on_ext_cmnt (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
56 int on_c89_cmnt (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
57 int on_dquote (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
58 int on_quote (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
59 int on_bquote (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
60 int on_bracket1 (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
61 int on_bracket2 (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
62 int on_bracket3 (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
64 int on_statement (int evt, int token, register const char *str, register unsigned int len, SRC_FILE_DESC *psrcfile);
68  * eg: (), it is used in sh-script in those kinds.
69  * @ $(), sub-script. it seperate $ and (). $ is a pfx char, it set 'dollar' flags,
70  * @ (), sub-script. if '(' is detected, it check 'dollar' flags to entering $() sub-script state.
71  *   if no 'dollar' flags, it checks if it is first token in curr statement.
72  * @ func(), function parameter.
73  *    
74  */
75 const struct token_id paired_char_array[] = {
76         /*
77          * XXX: maybe use "|" as a seperator in token string, it does not need to use token str len.
78          */
79         { {"/****/"},                   "T_EXT_CMNT_HDR",               STATE_TEXT_CMNT,        T_EXT_CMNT_HDR, TF_OPCHAR,              on_ext_cmnt },
80         { {"/**/"},                             "T_C89_CMNT_HDR",               STATE_TEXT_CMNT,        T_C89_CMNT_HDR, TF_OPCHAR,              on_c89_cmnt },
81         
82         { {"\"\""},                             "T_DQUOTE",                             STATE_STRING,           T_DQUOTE,               TF_OPCHAR,              on_dquote },
83         { {"''"},                               "T_QUOTE",                              0,                                      T_QUOTE,                TF_OPCHAR,              on_quote },
84         { {"``"},                               "T_BACK_QUOTE",                 STATE_CODEBLOCK,        T_BACK_QUOTE,   TF_OPCHAR,              on_bquote },
86         { {"()"},                               "T_LBRACKET1",                  STATE_EXPR,                     T_LBRACKET1,    TF_OPCHAR,              on_bracket1 },
87         { {"{}"},                               "T_LBRACKET3",                  0,                                      T_LBRACKET3,    TF_OPCHAR,              on_bracket3 },
89         { {"(())"},                             "T_DLBRACKET1",                 STATE_EXPR,                     T_DLBRACKET1,   TF_OPCHAR,              on_bracket2 },
90         { {"[]"},                               "T_LBRACKET2",                  STATE_EXPR,                     T_LBRACKET2,    TF_OPCHAR,              on_bracket2 },
91         
92         { {"[[]]"},                             "T_DLBRACKET2",                 STATE_EXPR,                     T_DLBRACKET2,   TF_OPCHAR,              on_bracket2 },
93         
94         { {NULL},                               NULL,                                   0,                                      0,                              0,                              NULL },
97 /**
98  ** calc-expr opr char.
99  **/
100 const struct token_id opr_char_array[] = {
101         /* cmdline token */
102         { .chars={"||"},                "T_DOR",                                STATE_CODE,                     T_DOR,                  TF_OPCHAR,      NULL },
103         { .chars={"&&"},                "T_DAND",                               STATE_CODE,                     T_DAND,                 TF_OPCHAR,      NULL },
104         
105         { .chars={"&"},                 "T_BACKGROUND",                         STATE_CODE,                     T_BACKGROUND,           TF_OPCHAR,      NULL },
106         { .chars={"|"},                 "T_PIPE",                                       STATE_CODE,                     T_PIPE,                 TF_OPCHAR,      NULL },
108         { .chars={";;"},                "T_DSEMI",                              STATE_CODE,                     T_DSEMI,                TF_OPCHAR,      NULL },
109         { .chars={";"},                 "T_SEMI",                               STATE_CODE,                     T_SEMI,                 TF_OPCHAR,      NULL },
110         
111         { .chars={","},                 "T_COMMA",                              STATE_CODE,                     T_COMMA,                TF_OPCHAR,      NULL },
112         
113         /* defined as pfx-char */
114 //      { .chars={"<"},                 "T_LT",                                 STATE_CODE,                     T_LT,                   TF_OPCHAR,      NULL },
115 //      { .chars={">"},                 "T_GT",                                 STATE_CODE,                     T_GT,                   TF_OPCHAR,      NULL },
117         { .chars={"<<<"},               "T_TLT",                                STATE_CODE,                     T_TLT,                  TF_OPCHAR,      NULL },
118         { .chars={"<<"},                "T_DLT",                                STATE_CODE,                     T_DLT,                  TF_OPCHAR,      NULL },
119         { .chars={">>"},                "T_DGT",                                STATE_CODE,                     T_DGT,                  TF_OPCHAR,      NULL },
120         { .chars={"<>"},                "T_LTGT",                               STATE_CODE,                     T_LTGT,                 TF_OPCHAR,      NULL },
121         { .chars={">&"},                "T_GT_AND",                             STATE_CODE,                     T_GT_AND,               TF_OPCHAR,      NULL },
122         { .chars={"<&"},                "T_LT_AND",                             STATE_CODE,                     T_LT_AND,               TF_OPCHAR,      NULL },
123         { .chars={"<>&"},               "T_LTGT_AND",                   STATE_CODE,                     T_LTGT_AND,             TF_OPCHAR,      NULL },
124         { .chars={">&-"},               "T_GT_AND_BAR",                         STATE_CODE,                     T_GT_AND_BAR,           TF_OPCHAR,      NULL },
125         { .chars={"<&-"},               "T_LT_AND_BAR",                         STATE_CODE,                     T_LT_AND_BAR,           TF_OPCHAR,      NULL },
126         { {"<>&-"},                             "T_LTGT_AND_BAR",                       STATE_CODE,                     T_LTGT_AND_BAR,         TF_OPCHAR,      NULL },
127         
128         { .chars={"="},                 "T_EQUAL",                                      STATE_CODE,                     T_EQUAL,                TF_OPCHAR,      NULL },
129         { .chars={"+="},                "T_ADDEQUAL",                           STATE_CODE,                     T_ADDEQUAL,             TF_OPCHAR,      NULL },
131         { .chars={"-="},                "T_SUBEQUAL",                           STATE_CODE,                     T_SUBEQUAL,             TF_OPCHAR,      NULL },
132         { .chars={"*="},                "T_MULEQUAL",                           STATE_CODE,                     T_MULEQUAL,             TF_OPCHAR,      NULL },
133         { .chars={"/="},                "T_DIVEQUAL",                           STATE_CODE,                     T_DIVEQUAL,             TF_OPCHAR,      NULL },
134         { .chars={"%="},                "T_MODEQUAL",                           STATE_CODE,                     T_MODEQUAL,             TF_OPCHAR,      NULL },
135         { .chars={"^^="},               "T_POWEQUAL",                           STATE_CODE,                     T_POWEQUAL,             TF_OPCHAR,      NULL },
136         { .chars={"&="},                "T_ANDEQUAL",                           STATE_CODE,                     T_ANDEQUAL,             TF_OPCHAR,      NULL },
137         { .chars={"|="},                "T_OREQUAL",                            STATE_CODE,                     T_OREQUAL,              TF_OPCHAR,      NULL },
138         { .chars={"^="},                "T_XOREQUAL",                           STATE_CODE,                     T_XOREQUAL,             TF_OPCHAR,      NULL },
139         { .chars={"<<="},               "T_LSHIFTEQUAL",                                STATE_CODE,                     T_LSHIFTEQUAL,          TF_OPCHAR,      NULL },
140         { .chars={">>="},               "T_RSHIFTEQUAL",                                STATE_CODE,                     T_RSHIFTEQUAL,          TF_OPCHAR,      NULL },
142         { .chars={"."},                 "T_POINT",                              STATE_CODE,                     T_POINT,                TF_OPCHAR,      NULL },
143         { .chars={"->"},                        "T_POINTER",                            STATE_CODE,                     T_POINTER,              TF_OPCHAR,      NULL },
144         { .chars={"::"},                        "T_DCOLON",                             STATE_CODE,                             T_DCOLON,               TF_OPCHAR,      NULL },
145         { .chars={"=>"},                        "T_REF_PTR",                            STATE_CODE,                     T_REF_PTR,              TF_OPCHAR,      NULL },
147         { .chars={"##"},                "T_DSHARP",                             STATE_CODE,                     T_DSHARP,               TF_OPCHAR,      NULL },
148         
149         { {NULL},                               NULL,                                   0,                                      0,                              0,                      NULL },
152 const struct token_id token_id_array[] = {
153         /*
154          * c-lang statement
155          */
156         { "if",                                 "T_IF",                         STATE_CODE,                     T_IF,                   TF_COMMAND },
157         { "else",                               "T_ELSE",                               STATE_CODE,                     T_ELSE,                 TF_COMMAND },
158         { "for",                                "T_FOR",                                STATE_CODE,                     T_FOR,                  TF_COMMAND },
159         { "do",                         "T_DO",                         STATE_CODE,                     T_DO,                   TF_COMMAND },
160         { "while",                              "T_WHILE",                              STATE_CODE,                     T_WHILE,                        TF_COMMAND },
161         { "until",                              "T_UNTIL",                              STATE_CODE,                     T_UNTIL,                        TF_COMMAND },
162         { "switch",                             "T_SWITCH",                             STATE_CODE,                     T_SWITCH,                       TF_COMMAND },
163         { "case",                               "T_CASE",                               STATE_CODE,                     T_CASE,                 TF_COMMAND },
164         { "continue",                           "T_CONTINUE",                           STATE_CODE,                     T_CONTINUE,                     TF_COMMAND },
165         { "break",                              "T_BREAK",                              STATE_CODE,                     T_BREAK,                        TF_COMMAND },
166         { "default",                            "T_DEFAULT",                            STATE_CODE,                     T_DEFAULT,                      TF_COMMAND },
167         { "return",                             "T_RETURN",                             STATE_CODE,                     T_RETURN,                       TF_COMMAND },
169         { "sizeof",                             "T_SIZEOF",                             STATE_CODE,                     T_SIZEOF,                       TF_COMMAND },
170         { "typeof",                             "T_TYPEOF",                             STATE_CODE,                     T_TYPEOF,                       TF_COMMAND },
172         /* storage qualifier */
173         { "auto",                       "T_AUTO",                               STATE_CODE,                     T_AUTO,                 TF_COMMAND },
174         { "register",                   "T_REGISTER",                           STATE_CODE,                     T_REGISTER,                     TF_COMMAND },
175         { "const",                              "T_CONST",                              STATE_CODE,                     T_CONST,                        TF_COMMAND },
176         { "static",                             "T_STATIC",                             STATE_CODE,                     T_STATIC,                       TF_COMMAND },
177         { "volatile",                   "T_VOLATILE",                           STATE_CODE,                     T_VOLATILE,                     TF_COMMAND },
178         { "extern",                             "T_EXTERN",                             STATE_CODE,                     T_EXTERN,                       TF_COMMAND },
180         /* struct ... */
181         { "typedef",                    "T_TYPEDEF",                    STATE_CODE,                     T_TYPEDEF,              STATE_CODE,             NULL },
182         { "struct",                             "T_STRUCT",                             STATE_CODE,                     T_STRUCT,               TF_COMMAND },
183         { "union",                              "T_UNION",                              STATE_CODE,                     T_UNION,                        TF_COMMAND },
184         { "enum",                               "T_ENUM",                               STATE_CODE,                     T_ENUM,                 TF_COMMAND },
186         /*
187          * sh-script
188          */
189         { "function",                           "T_FUNC",                               STATE_CODE,                     T_FUNC,                 TF_COMMAND },
190         { "then",                               "T_THEN",                               STATE_CODE,                     T_THEN,                 TF_COMMAND },
191         { "fi",                                 "T_FI",                         STATE_CODE,                     T_FI,                   TF_COMMAND },
192         { "elif",                               "T_ELIF",                               STATE_CODE,                     T_ELIF,                 TF_COMMAND },
193         { "esac",                               "T_ESAC",                               STATE_CODE,                     T_ESAC,                 TF_COMMAND },
194         { "done",                               "T_DONE",                               STATE_CODE,                     T_DONE,                 TF_COMMAND },
195         { "in",                                 "T_IN",                         STATE_CODE,                     T_IN,                   TF_COMMAND },
196         { "select",                             "T_SELECT",                             STATE_CODE,                     T_SELECT,                       TF_COMMAND },
198         /*
199          * extension
200          */
201         { "packet",                             "T_PACKET",                             STATE_CODE,                     T_PACKET,                       TF_COMMAND },
203         { "foreach",                    "T_FOREACH",                            STATE_CODE,                     T_FOREACH,                      TF_COMMAND },
204         { "judge",                              "T_JUDGE",                              STATE_CODE,                     T_JUDGE,                        TF_COMMAND },
205         { "judgement",                  "T_JUDGEMENT",                          STATE_CODE,                     T_JUDGEMENT,                    TF_COMMAND },
206         { "condition",                          "T_CONDITION",                          STATE_CODE,                     T_CONDITION,                    TF_COMMAND },
207         { "cond",                               "T_COND",                               STATE_CODE,                     T_COND,                 TF_COMMAND },
208         { "condef",                             "T_CONDEF",                             STATE_CODE,                     T_CONDEF,                       TF_COMMAND },
209         { "res",                                "T_RES",                                STATE_CODE,                     T_RES,                  TF_COMMAND },
210         { "request",                            "T_REQUEST",                            STATE_CODE,                     T_REQUEST,                      TF_COMMAND },
211         { "failed",                             "T_FAILED",                             STATE_CODE,                     T_FAILED,                       TF_COMMAND },
213 //      { "try",                                "T_TRY",                                STATE_CODE,                     T_TRY,                  TF_COMMAND },
214         { "exception",                          "T_EXCEPTION",                          STATE_CODE,                     T_EXCEPTION,                    TF_COMMAND },
215 //      { "throw",                              "T_THROW",                              STATE_CODE,                     T_THROW,                        TF_COMMAND },
216         { "run",                                "T_RUN",                                STATE_CODE,                     T_RUN,                  TF_COMMAND },
217         { "trig",                               "T_TRIG",                               STATE_CODE,                     T_TRIG,                 TF_COMMAND },
219         { "api",                                "T_API",                                STATE_CODE,                     T_API,                  TF_COMMAND },
220         { "public",                             "T_PUBLIC",                             STATE_CODE,                     T_PUBLIC,                       TF_COMMAND },
221         { "private",                            "T_PRIVATE",                            STATE_CODE,                     T_PRIVATE,                      TF_COMMAND },
222         { "property",                           "T_PROPERTY",                           STATE_CODE,                     T_PROPERTY,                     TF_COMMAND },
223         { "rtf",                                "T_RTF",                                STATE_CODE,                     T_RTF,                  TF_COMMAND },
224         { "overide",                            "T_OVERIDE",                            STATE_CODE,                     T_OVERIDE,                      TF_COMMAND },
225         { "weak",                               "T_WEAK",                               STATE_CODE,                     T_WEAK,                 TF_COMMAND },
226         { "alias",                              "T_ALIAS",                              STATE_CODE,                     T_ALIAS,                        TF_COMMAND },
227         { "cort",                               "T_CORT",                               STATE_CODE,                     T_CORT,                 TF_COMMAND },
228         { "init",                               "T_INIT",                               STATE_CODE,                     T_INIT,                 TF_COMMAND },
230         { "this",                               "T_THIS",                               STATE_CODE,                     T_THIS,                 TF_COMMAND },
231         { "thus",                               "T_THUS",                               STATE_CODE,                     T_THUS,                 TF_COMMAND },
233         { "global",                             "T_GLOBAL",                             STATE_CODE,                     T_GLOBAL,                       TF_COMMAND },
234         { "local",                              "T_LOCAL",                              STATE_CODE,                     T_LOCAL,                        TF_COMMAND },
235         { "system",                             "T_SYSTEM",                             STATE_CODE,                     T_SYSTEM,                       TF_COMMAND },
237         { "condition",                          "T_DEFAULT",                            STATE_CODE,                     T_DEFAULT,                      TF_COMMAND },
239         { "numof",                              "T_NUMOF",                              STATE_CODE,                     T_NUMOF,                        TF_COMMAND },
241         { NULL,                                 NULL,                                   0,                                      0,                              0 },
245  ** reserved-word.
246  **/
247 const struct token_id token_id_array_tmp[] = {
248         /* use string instead of {}, if string longer then 3 char. */
249         { "typedef",                    "T_TYPEDEF",                    STATE_CODE,                     T_TYPEDEF,              STATE_CODE,             NULL },
250         { "struct",                             "T_STRUCT",                             STATE_CODE,                     T_STRUCT,               TF_COMMAND },
251         { "enum",                               "T_ENUM",                               STATE_CODE,                     T_ENUM,                 TF_COMMAND },
252         
253         { NULL,                                 NULL,                                   0,                                      0,                              0 },