2 ##############################################################################
4 # this file list token (rsv-word/signature), normal word, quated string, and
5 # append processing code after it if it needed.
6 # generally, those content should be defined:
7 # charset: fundamental char set name.
8 # blank/newline: ignore blank, or recognized in other defination. record
11 # maskchar: char of "\". some will process it in quated string, but some will
12 # process it in code as a mask char.
14 # symbol: it can be used for variable name.
15 # rsv-word(token): some fixed word defined as token.
16 # signature(token): punct char set.
17 # quatedstr: quated string with ", ', `.
18 # specialchar: such as $ in shell.
19 # EOF: file terminator processing.
20 # <some-others>: some particular content.
21 # rsv-word/signature/specialchar can be defined in other place. in code, or
22 # another lxr define file.
23 # lexer processing variables define.
24 # yytext, yyleng: current matching string pointer
27 # unput(yytext[0]): put a char back to original processing content.
28 # BEGIN COMMAND: entering state. INITIAL is the default state.
29 ##############################################################################
32 # define T_WORD, T_TOKEN
35 # it let return with a string value.
42 ##############################################################################
44 ##############################################################################
49 # tmp str for quote char type storage.
55 # current matching string and length.
59 # if $attr_domain is null, use env var access.
67 # fdesc: swith to dest state, set domain.
71 if [[ $1 == INITIAL ]]; then
81 # init a new string in buffer variable.
85 declare -g str_buff=""
89 # fsyntax: append_string <str> [len]
90 # fdesc: append string to curr string buffer.
94 eval "str_buff+=\"\${1: 0:$2}\""
98 # fdesc: check if stack is empty.
114 # fdesc: push string.
131 ##############################################################################
133 ##############################################################################
146 def_blank='[[:blank:]]*'
147 def_blank_ln='[[:blank:]]*\n'
154 # comment, sh-lang and c style.
156 def_sh_cmnt='[ \t]*#.*'
157 def_sh_cmnt_ln='[[:blank:]]*#.*\n'
162 def_cpp_cmnt_ln=[[:blank:]]*//.*\n
167 def_cpp_cmnt_nl='[[:blank:]]*/\*'
174 state_list+=" COMMENT"
175 state_array+=( "COMMENT" )
176 attr COMMENT::def_c_cmnt='[^*/]*'
177 COMMENT::on_c_cmnt ()
179 #append_string(yytext, yyleng);
180 if [[ yytext =~ "\n" ]]; then
184 attr COMMENT::def_c_cmnt_end='\*/'
185 COMMENT::on_c_cmnt_end ()
190 if [[ cmnt_flag == 1 ]]; then
191 # if comment is multi line, return as a T_EOL.#
195 attr COMMENT::def_c_cmnt_star='*'
196 COMMENT::on_c_cmnt_star ()
198 # append_string("*", 1);
201 attr COMMENT::def_c_cmnt_slash='*'
202 COMMENT::on_c_cmnt_slash ()
204 # append_string("*", 1);
208 #attr COMMENT::def_c_cmnt_eof=''
209 #COMMENT::on_c_cmnt_slash ()
215 # signature token define.
217 def_token_sign_langle="<"
218 on_token_sign_langle ()
219 { last="<"; return T_LANGLE; }
220 def_token_sign_rangle=">"
221 on_token_sign_rangle ()
222 { last=">"; return T_RANGLE; }
223 def_token_sign_lbrace="{"
224 on_token_sign_lbrace ()
225 { last="{"; return T_LBRACE; }
226 def_token_sign_rbrace="}"
227 on_token_sign_rbrace ()
228 { last="}"; return T_RBRACE; }
229 def_token_sign_lbracket="["
230 on_token_sign_lbracket ()
231 { last="["; return T_LBRACKET; }
232 def_token_sign_rbracket="]"
233 on_token_sign_rbracket ()
234 { last="]"; return T_RBRACKET; }
237 # signature token define.
239 def_token_sign_general="${s}+"
240 on_token_sign_general ()
242 const struct kconf_id
245 id=$(kconf_id_lookup "$yytext" $yyleng);
246 # current_pos.file = current_file;
247 # current_pos.lineno = yylineno;
248 if [[ id && id_flags == TF_COMMAND ]]; then
253 alloc_string "$yytext" $yyleng;
254 yylval.string = text;
259 # symbol word or rsv-word.
261 def_token_symb_general="${a}${n}+"
262 on_token_symb_general ()
264 # const struct kconf_id
267 id = kconf_id_lookup "$yytext" $yyleng;
268 # current_pos.file = current_file;
269 # current_pos.lineno = yylineno;
270 if [[ -n id && id_flags == TF_COMMAND ]]; then
274 alloc_string "$yytext" $yyleng;
275 # yylval.string = text;
282 def_token_word_general="${n}+"
283 on_token_word_general ()
285 # const struct kconf_id
288 id = kconf_id_lookup "$yytext" $yyleng;
289 # current_pos.file = current_file;
290 # current_pos.lineno = yylineno;
291 if [[ id && id_flags == TF_COMMAND ]]; then
295 alloc_string "$yytext" $yyleng;
296 # yylval.string = text;
302 # text without blanks, and include none-blank display char.
303 # it's used as regex string.
305 def_string_word_general="[[:space:]]${t}+[[:space:]]"
306 on_string_word_general ()
308 const struct kconf_id
311 id=$(kconf_id_lookup "$yytext" $yyleng);
312 # current_pos.file = current_file;
313 # current_pos.lineno = yylineno;
314 if [[ id && id_flags == TF_COMMAND ]]; then
318 alloc_string "$yytext" $yyleng;
319 # yylval.string = text;
325 { warn_ignored_character "$yytext"; }
340 def_quate_begin="\"|'"
347 # single line string just for symbol#
348 state_list+=" STRING"
349 state_array+=( "STRING" )
350 attr STRING::def_quate_string="[^'\"\\]*"
351 STRING::on_quate_string ()
353 append_string "$yytext" yyleng;
355 attr STRING::def_quote_mask='\\.?'
356 STRING::on_quote_mask ()
358 # '\' mask signature#
359 append_string "${yytext:1}" $((yyleng - 1));
361 attr STRING::def_quote_end="'|\""
362 STRING::on_quote_end ()
364 if [[ $str == ${yytext[0]} ]]; then
366 # yylval.string = text;
370 append_string "$yytext" 1;
378 # multi-line string for code block.
379 # entering this state by function enter_state("BLOCK").
381 def_block_begin="[[:space:]]\{[[:space:]]"
384 if [[ "$last" =~ ">" ]]; then
385 # BRACE in state define
389 # it's a response code of lex define.
392 append_string "{\n" 2;
398 # entering from "[[:space:]]\{[[:space:]]", and end with
399 # "[[:space:]]\}[[:space:]]". append string with "[^\{\}]*".
400 # since the single "{" or "}" should be recognized, this
401 # will avoid "}" mis-matching with multi "{}" pair in block.
402 # so, the ending "}" should be matching with
403 # "[^\{\}]*[[:space:]]\}[[:space:]]". if mathcing "[^\{\}]*"
404 # and "[[:space:]]\}[[:space:]]" seperatly, "[^\{\}]*" will
405 # matching with "[[:space:]]", which is before "}", then,
406 # "[[:space:]]\}[[:space:]]" is not matched, but "}" is matched.
407 # if put checking code in "}" process code,
410 state_array+=( "BLOCK" )
412 # code block is terminated with a } and a newline, whatever
413 # there are comments between them.
415 attr BLOCK::def_block_str_end='[^\{\}]*[[:space:]]\}[[:space:]]*(\#[^\n]*)?\n'
416 BLOCK::on_block_str_end ()
418 append_string "$yytext" $yyleng;
419 if [[ $(stk_empty) == true ]]; then
427 attr BLOCK::def_block_str='[^\{\}]*'
428 BLOCK::on_block_str ()
430 append_string "$yytext" $yyleng;
432 attr BLOCK::def_block_lbrace='\{'
433 BLOCK::on_block_lbrace ()
438 attr BLOCK::def_block_rbrace='\}'
439 BLOCK::on_block_rbrace ()
441 if [[ $(stk_empty) == true ]]; then
443 # should not entering here.
444 # it means there are no "[[:space:]]" char matching before "{".
445 # or, it will matching the first item of syntax define.
447 #dbgout("there must be blank char before and after '}'.\n");
448 append_string "\n}" 2;
462 # if (current_file) {