4 #include "../token_id.h"
6 void STATE_SET (int state
)
11 int on_help_proc (register const char *str
, register unsigned int len
)
21 /*********************************************************************
23 *********************************************************************/
25 int on_token_proc (int ret
)
27 // extern char str_buff[8192];
28 // extern int str_idx;
29 extern SRC_FILE_DESC
*gpcurr_src_file
;
32 TOKEN_PROC_STATE
*pstTokenState
= gpcurr_src_file
->pstCurrTokenState
;
33 const char *str
= NULL
;
36 * display token id, token name, and it's content.
38 str
= name_look_up_token(ret
);
41 printf("<%d> %s: ", ret
, str
);
42 if (!strcmp(str
, "T_EOL"))
47 else if (!strcmp(str
, "T_HELPTEXT"))
49 else if (!strcmp(str
, "T_WORD_QUOTE"))
51 else if (!strcmp(str
, "T_C89_CMNT"))
55 if (is_empty_string(&strbuff
))
56 pstr
= pstTokenState
->token_str
;
60 // printf("str_idx = %d\n", str_idx);
61 // printf("pstr = %d\n", pstr);
67 if (yylval.id->token == ret)
68 printf("%s\n", yylval.id->name);
70 printf("%s\n", yylval.string);
75 // TBD: append gmr parser func here.
81 * set content flag automatically.
82 * referenced from script.l(script.lex.c).
84 #define RETURN(token) g_content_before_cmnt=1; return token;
86 int const_string (CACHING_STR
*pstr_cache
, int token
)
88 if (is_unallocated_string(&strbuff
))
90 alloc_string(&strbuff
, yytext
, yyleng
);
91 yylval
.string
= strbuff
.text
;
97 append_string(&strbuff
, yytext
, yyleng
);
109 int lex_c_preproc_hdr (void)
111 /* only works with newline started. */
112 if (g_content_before_cmnt
== 0)
115 * XXX: lookup macro rsv-word name table, if not matching, it's a comment string.
116 * XXX: invoke OnCPreProc().
118 printf("C-PREPROC:\n%s", yytext
);
125 printf("SH-CMNT:\n%s", yytext
);
126 BEGIN(SH_CMNT_STATE
);
133 int lex_sh_cmnt (void)
135 // printf("%s\n", yytext);
138 if (!is_unallocated_string(&strbuff
))
141 yylval
.string
= strbuff
.text
;
148 int lex_c_preproc_param (void)
150 printf("%s\n", yytext
);
152 if (g_cpreproc_flag
== 1)
154 // XXX: replace cpreproc code here.
164 if (!is_unallocated_string(&strbuff
))
167 yylval
.string
= strbuff
.text
;
174 void lex_c89_cmnt_nl (void)
177 * if there are content before comment, matching '\n' same as '* /' for ending expr.
178 * if there are no content before comment, just matching '* /' for ending expr.
179 * this kind of implementation is in order to avoid conflect with shell cmd '/ *'.
182 * @ there should be a piece of code to caching token and string if in this condition.
183 * if '\n' detected as a ending expr for comment, get token from caching buffer.
185 if (g_cmnt_state
== EN_CMNT_BEGIN
)
186 g_cmnt_state
=EN_CMNT
;
188 if (g_content_before_cmnt
!= 0 && g_cmnt_state
!= EN_CMNT_EXTEND
)
191 * treat '/*' as a normal string.
192 * put back other string to buffer.
193 * TBD: append to T_WORD or other token.
195 /* do not unput() idx=0, or it will be treated as a comment again. */
196 for (int i
=cmnt_idx
; i
>0; i
--)
200 // return T_CMNT_STR;
204 cmnt_buff
[cmnt_idx
]='\n';
206 cmnt_buff
[cmnt_idx
]=0;
210 void lex_c89_cmnt_tail (void)
212 if (g_cmnt_state
!= EN_CMNT_EXTEND
)
214 g_cmnt_state
=EN_CMNT_NONE
;
215 printf("C89-CMNT: \n%s%s\n", cmnt_buff
, yytext
);
217 // g_content_before_cmnt=0;
218 // return T_CMNT_STR;
225 * ignore / * * / comment in / ** ** /
227 cmnt_buff
[cmnt_idx
]='*';
229 cmnt_buff
[cmnt_idx
]='/';
231 cmnt_buff
[cmnt_idx
]=0;
235 // '\*\*\/' ext comment
236 g_cmnt_state
=EN_CMNT_NONE
;
237 printf("C89-EXT-CMNT: \n%s%s\n", cmnt_buff
, yytext
);
239 g_content_before_cmnt
=0;
240 // return T_CMNT_STR;
246 enum ENM_PUNCT_TYPE {
255 int lex_punct (int state
)
257 const struct token_id
*id
= punct_look_up_token(yytext
[0]);
262 * no opr-char and pfx-char matched,
263 * punct will be seen as a normal char in string word.
266 append_string(&strbuff
, yytext
, yyleng
);
269 else if (TOKEN_FLAG(id
->flags
) == TF_OPCHAR
)
271 /* return token if it is a signature */
275 else if (TOKEN_FLAG(id
->flags
) == T_PFX_CHAR
)
278 * if it is a T_PFX_CHAR char, entering state
281 // const struct token_id *id = punct_look_up_token(yytext, yyleng);
282 // push_state(curr_state);
287 printf("err: (%s)should not be running here.\n", yytext
);
292 int lex_token_word (void)
295 * if there are chars before a symbol string,
296 * symbol is seen as a word.
298 if (!is_unallocated_string(&strbuff
))
300 // printf("T_WORD:%s\n", yytext);
301 append_string(&strbuff
, yytext
, yyleng
);
302 yylval
.string
= strbuff
.text
;
306 const struct token_id
*id
= token_id_lookup(yytext
, yyleng
);
310 // printf("SYM(0x%02x): %s\n", yylval.id, yytext);
313 // printf("WORD: %s\n", yytext);
316 current_pos
.file
= current_file
;
317 current_pos
.lineno
= yylineno
;
318 // TBD: non-command token does not effective.
319 if (id
&& id
->flags
& TF_COMMAND
)
322 (id->flags & TF_COMMAND ||
323 id->flags & TF_PARAM ||
324 id->flags & TF_OPTION))
330 alloc_string(&strbuff
, yytext
, yyleng
);
331 yylval
.string
= strbuff
.text
;