* raw_parser * Given a query in string form, do lexical and grammatical analysis. * * Returns a list of raw (un-analyzed) parse trees. The contents of the * list have the form required by the specified RawParseMode. */
| 40 | * list have the form required by the specified RawParseMode. |
| 41 | */ |
| 42 | List * |
| 43 | raw_parser(const char *str, RawParseMode mode) |
| 44 | { |
| 45 | core_yyscan_t yyscanner; |
| 46 | base_yy_extra_type yyextra; |
| 47 | int yyresult; |
| 48 | |
| 49 | /* |
| 50 | * In GPDB, temporarily disable escape_string_warning, if we're in a QE |
| 51 | * node. When we're parsing a PL/pgSQL function, e.g. in a CREATE FUNCTION |
| 52 | * command, you should've gotten the same warning from the QD node already. |
| 53 | * We could probably disable the warning in QE nodes altogether, not just |
| 54 | * in PL/pgSQL, but it can be useful for catching escaping bugs, when |
| 55 | * internal queries are dispatched from QD to QEs. |
| 56 | */ |
| 57 | bool save_escape_string_warning = escape_string_warning; |
| 58 | PG_TRY(); |
| 59 | { |
| 60 | if (Gp_role == GP_ROLE_EXECUTE) |
| 61 | escape_string_warning = false; |
| 62 | |
| 63 | /* initialize the flex scanner */ |
| 64 | yyscanner = scanner_init(str, &yyextra.core_yy_extra, |
| 65 | &ScanKeywords, ScanKeywordTokens); |
| 66 | |
| 67 | if (Gp_role == GP_ROLE_EXECUTE) |
| 68 | escape_string_warning = save_escape_string_warning; |
| 69 | } |
| 70 | PG_CATCH(); |
| 71 | { |
| 72 | if (Gp_role == GP_ROLE_EXECUTE) |
| 73 | escape_string_warning = save_escape_string_warning; |
| 74 | PG_RE_THROW(); |
| 75 | } |
| 76 | PG_END_TRY(); |
| 77 | |
| 78 | yyextra.tail_partition_magic = false; |
| 79 | /* base_yylex() only needs us to initialize the lookahead token, if any */ |
| 80 | if (mode == RAW_PARSE_DEFAULT) |
| 81 | yyextra.have_lookahead = false; |
| 82 | else |
| 83 | { |
| 84 | /* this array is indexed by RawParseMode enum */ |
| 85 | static const int mode_token[] = { |
| 86 | 0, /* RAW_PARSE_DEFAULT */ |
| 87 | MODE_TYPE_NAME, /* RAW_PARSE_TYPE_NAME */ |
| 88 | MODE_PLPGSQL_EXPR, /* RAW_PARSE_PLPGSQL_EXPR */ |
| 89 | MODE_PLPGSQL_ASSIGN1, /* RAW_PARSE_PLPGSQL_ASSIGN1 */ |
| 90 | MODE_PLPGSQL_ASSIGN2, /* RAW_PARSE_PLPGSQL_ASSIGN2 */ |
| 91 | MODE_PLPGSQL_ASSIGN3 /* RAW_PARSE_PLPGSQL_ASSIGN3 */ |
| 92 | }; |
| 93 | |
| 94 | yyextra.have_lookahead = true; |
| 95 | yyextra.lookahead_token = mode_token[mode]; |
| 96 | yyextra.lookahead_yylloc = 0; |
| 97 | yyextra.lookahead_end = NULL; |
| 98 | } |
| 99 | /* initialize the bison parser */ |
no outgoing calls
no test coverage detected