📄 phpbrowser.l
字号:
tok->vars = NULL; tok->next = NULL; /* append to token list */ if (tokens_tail == NULL) { tokens_head = tokens_tail = tok; } else { tokens_tail->next = tok; tokens_tail = tok; }}Token* pop_head_token() { Token* tok; assert(tokens_head); tok = tokens_head; if (tokens_head == tokens_tail) { tokens_head = tokens_tail = (Token*) NULL; } else { tokens_head = tokens_head->next; } token_index++; return tok;}void free_head_token() { FreeToken(pop_head_token());}/* * This method is invoked when nested brackets within an * array name are encountered. For example: $arr1[++$arr2[0]] */void push_bracket_counter() { NestedBracket* nbp = (NestedBracket*) ckalloc(sizeof(NestedBracket)); nbp->var = current_array_token; nbp->count = current_array_bracket_count; nbp->prefix_incr = current_array_prefix_incr; if (array_nest_head == NULL) { array_nest_head = array_nest_tail = nbp; } else { nbp->next = array_nest_head; array_nest_head = nbp; }}void pop_bracket_counter() { if (array_nest_head != NULL) { NestedBracket* nbp = array_nest_head; if (array_nest_head == array_nest_tail) { array_nest_head = array_nest_tail = (NestedBracket*) NULL; } else { array_nest_head = array_nest_head->next; } current_array_token = nbp->var; current_array_bracket_count = nbp->count; current_array_prefix_incr = nbp->prefix_incr; ckfree((char*) nbp); }}/* * This method is invoked when a nested function is * encountered. */void push_function() { NestedFunction* n = (NestedFunction*) ckalloc(sizeof(NestedFunction)); n->name = current_function; n->args = current_function_args; n->high_line = current_function_highlight_line; n->high_col_start = current_function_highlight_column_start; n->high_col_end = current_function_highlight_column_end; n->line_start = current_function_line_start; n->line_end = current_function_line_end; n->col_start = current_function_column_start; n->col_end = current_function_column_end; n->brace_count = current_function_brace_count; if (function_nest_head == NULL) { function_nest_head = function_nest_tail = n; } else { n->next = function_nest_head; function_nest_head = n; }}void pop_function() { if (function_nest_head != NULL) { NestedFunction* n = function_nest_head; if (function_nest_head == function_nest_tail) { function_nest_head = function_nest_tail = (NestedFunction*) NULL; } else { function_nest_head = function_nest_head->next; } current_function = n->name; current_function_args = n->args; current_function_highlight_line = n->high_line; current_function_highlight_column_start = n->high_col_start; current_function_highlight_column_end = n->high_col_end; current_function_line_start = n->line_start; current_function_line_end = n->line_end; current_function_column_start = n->col_start; current_function_column_end = n->col_end; current_function_brace_count = n->brace_count; ckfree((char*) n); }}char * TokenTypeToString(Token *tok) { switch(tok->type) { case OPEN_PAREN: return "OPEN_PAREN"; case CLOSE_PAREN: return "CLOSE_PAREN"; case OPEN_BRACE: return "OPEN_BRACE"; case CLOSE_BRACE: return "CLOSE_BRACE"; case OPEN_BRACKET: return "OPEN_BRACKET"; case CLOSE_BRACKET: return "CLOSE_BRACKET"; case SEMICOLON: return "SEMICOLON"; case COMMA: return "COMMA"; case PERIOD: return "PERIOD"; case VARIABLE: return "VARIABLE"; case ASSIGNMENT_OPERATOR: return "ASSIGNMENT_OPERATOR"; case ASSIGNMENT_OPERATORS: return "ASSIGNMENT_OPERATORS"; case COMPARISON_OPERATORS: return "COMPARISON_OPERATORS"; case INCREMENT_OPERATORS: return "INCREMENT_OPERATORS"; case REFERENCE_OPERATOR: return "REFERENCE_OPERATOR"; case SOMEWORD: return "SOMEWORD"; case KEYWORD: return "KEYWORD"; case FUNCTION_KEYWORD: return "FUNCTION_KEYWORD"; case GLOBAL_KEYWORD: return "GLOBAL_KEYWORD"; case INCLUDE_KEYWORD: return "INCLUDE_KEYWORD"; case VDOUBLE_QUOTED_STRING: return "VDOUBLE_QUOTED_STRING"; case DOUBLE_QUOTED_STRING: return "DOUBLE_QUOTED_STRING"; case SINGLE_QUOTED_STRING: return "SINGLE_QUOTED_STRING"; case UNKNOWN: return "UNKNOWN"; case COMMENT: return "COMMENT"; case HTML: return "HTML"; default: return "TOKEN_NOT_MATCHED"; }}/* Called when the closing brace of a function is found * or when we hit EOF without finding the end of the * function. */void emit_function_declaration() { result = sn_insert_symbol(SN_FUNC_DEF, NULL, current_function, sn_current_file(), current_function_line_start, current_function_column_start, current_function_line_end, current_function_column_end, 0 /* attribute */, NULL /* return type */, NULL /* argument types */, current_function_args /* argument names */, NULL /* comment */, current_function_highlight_line, current_function_highlight_column_start, current_function_highlight_line, current_function_highlight_column_end ); assert(result == 0); ckfree(current_function); current_function = NULL; ckfree(current_function_args); current_function_args = NULL; if (global_var_table) { global_var_table->destroy( &global_var_table ); global_var_table = NULL; }}void emit_comment() { char* comment = mode_buff.buf;#if COMMENT_DUMP fprintf(stderr, "emit comment \"%s\"\n", comment);#endif /* If dumping tokens, emit a special COMMENT token. * Otherwise, insert a comment symbol and a highlight. */ if (token_dump_file) { append_token(COMMENT, comment, mode_start_line, mode_start_column - 2, sn_line(), sn_column() + 2); } else { sn_insert_comment( /* classname */ NULL, /* funcname */ NULL, sn_current_file(), comment, mode_start_line, mode_start_column); sn_highlight(SN_HIGH_COMMENT, mode_start_line, mode_start_column - 2, sn_line(), sn_column() + 2); } mode_buff.free(&mode_buff);}void emit_dqstring() { char* dqstring = mode_buff.buf; char * x; char * var;#if DQSTRING_DUMP fprintf(stderr, "creating dqstring token \"%s\"\n", dqstring);#endif append_dqstring_token(dqstring, mode_start_line, mode_start_column, sn_line(), sn_column()); mode_buff.free(&mode_buff);}void emit_sqstring() { char* sqstring = mode_buff.buf;#if SQSTRING_DUMP fprintf(stderr, "creating sqstring token \'%s\'\n", sqstring);#endif append_token(SINGLE_QUOTED_STRING, sqstring, mode_start_line, mode_start_column, sn_line(), sn_column()); mode_buff.free(&mode_buff);}void emit_hdstring() { char* hdstring = mode_buff.buf; /* Nuke trailing newline in hdstring */ char * end = hdstring + strlen(hdstring) - 1; if (*end == '\n') { *end = '\0'; }#if HDSTRING_DUMP fprintf(stderr, "creating hdstring token \"%s\"\n", hdstring);#endif /* sn_column() should be at the ; at the end of a heredoc */ append_dqstring_token(hdstring, mode_start_line, mode_start_column, sn_line(), sn_column()); /* A heredoc string is followed by a SEMICOLON */ append_token(SEMICOLON, NULL, sn_line(), sn_column(), sn_line(), sn_column()+1); mode_buff.free(&mode_buff);}/* Helper method to enter HTML mode. * Should be called in place of BEGIN(HTML_MODE) */void enter_html_mode() { if (token_dump_file) { LongStringInit(&mode_buff,0); mode_start_line = sn_line(); mode_start_column = sn_column(); } BEGIN(HTML_MODE);}void emit_html() { if (token_dump_file) { char * html_text = mode_buff.buf;#if HTML_DUMP fprintf(stderr, "creating html token \"%s\"\n", html_text);#endif append_token(HTML, html_text, mode_start_line, mode_start_column, sn_line(), sn_column()); mode_buff.free(&mode_buff); }}/* Write out read xrefs for variables embedded in this * VDOUBLE_QUOTED_STRING token */void emit_var_access_for_dqstring(Token* tok) { assert(tok->vars); for (tok = tok->vars; tok; tok = tok->next) { emit_var_access(tok, VAR_READ); }}/* This method is invoked when a var write operation is matched. * in the token stream. */void emit_var_access(Token *tok, VarAccess acc) { char* varname = tok->strval; SearchEntry entry; int ref_to_symbol_type, ref_to_symbol_scope; int ref_from_scope_type; int line_start, line_end, column_start, column_end; line_start = tok->start_line; column_start = tok->start_column; line_end = tok->end_line; column_end = tok->end_column; /* * A var is global if not currently in a function, * if the variable is in the super global table, * or if in the global table. */ entry.key = varname; entry.key_len = -1; if ((current_function == NULL) || (super_global_var_table->search( &super_global_var_table, entry ) != NULL) || (global_var_table && (global_var_table->search( &global_var_table, entry ) != NULL))) { ref_to_symbol_type = SN_REF_TO_GLOB_VAR; ref_to_symbol_scope = SN_REF_SCOPE_GLOBAL;#ifdef TOKEN_DEBUG fprintf(tokenout, "global var \"%s\"\n", varname);#endif } else { ref_to_symbol_type = SN_REF_TO_LOCAL_VAR; ref_to_symbol_scope = SN_REF_SCOPE_LOCAL;#ifdef TOKEN_DEBUG fprintf(tokenout, "local var \"%s\"\n", varname);#endif } /* * Pass SN_GLOBAL_NAMESPACE if the xref is outside of * a function, otherwise pass SN_FUNC_DEF. */ if (current_function == NULL) { ref_from_scope_type = SN_GLOBAL_NAMESPACE; } else { ref_from_scope_type = SN_FUNC_DEF; } if ((ref_to_symbol_type == SN_REF_TO_GLOB_VAR) || ((ref_to_symbol_type == SN_REF_TO_LOCAL_VAR) && ((int) sn_getopt(SN_OPT_LOCAL_VARS) != 0))) { if ((acc == VAR_READ) || (acc == VAR_READWRITE)) { result = sn_insert_xref(ref_to_symbol_type, ref_from_scope_type, ref_to_symbol_scope, NULL, current_function, NULL, NULL, varname, "UNDECLARED", sn_current_file(), line_start, SN_REF_READ); assert(result == 0); } if ((acc == VAR_WRITE) || (acc == VAR_READWRITE)) { result = sn_insert_xref(ref_to_symbol_type, ref_from_scope_type, ref_to_symbol_scope, NULL, current_function, NULL, NULL, varname, "UNDECLARED", sn_current_file(), line_start, SN_REF_WRITE); assert(result == 0); } } if (ref_to_symbol_type == SN_REF_TO_GLOB_VAR) { sn_highlight(SN_HIGH_VAR_GLOBAL, line_start, column_start, line_end, column_end); } else { sn_highlight(SN_HIGH_VAR_LOCAL, line_start, column_start, line_end, column_end); }}int get_num_tokens_matched(char *match) { char *x; int tokens; assert(*match != '\0'); /* match must have some text */ assert(*match != ' '); /* match can't start with a space */ for (x=match, tokens=0; *x; x++) { if (*x == ' ') { /* We just got to the end of a token */ assert(*(x-1) != ' '); /* two spaces in a row is not allowed */ tokens++; } } if (*(x-1) != ' ') { tokens++; } return tokens;}voidreset(){ assert(!current_function); sn_reset_line(); sn_reset_column(); sn_reset_encoding();}intmain(int argc, char *argv[]){ /* Init the super globals lookup table before starting * since it will never change during parsing. */ int i; SearchEntry entry; char* super_globals[] = { "GLOBALS", "_SERVER", "_GET", "_POST", "_COOKIE", "_FILES", "_ENV", "_REQUEST", "_SESSION", NULL }; super_global_var_table = SearchTableCreate(20, SEARCH_HASH_TABLE, FreeGlobalEntry); for (i=0; super_globals[i]; i++) { entry.key = super_globals[i]; entry.key_len = -1; entry.flag = SEARCH_DUP_KEY; /* add copy of entry.key */ super_global_var_table->add( &super_global_var_table, entry ); } return sn_main(argc, argv, group, &yyin, yylex, reset);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -