Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

parser.c File Reference

#include "postgres.h"
#include "parser/gramparse.h"
#include "parser/parser.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Functions

Listraw_parser (const char *str)
int base_yylex (YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)

Function Documentation

int base_yylex ( YYSTYPE *  lvalp,
YYLTYPE *  llocp,
core_yyscan_t  yyscanner 
)

Definition at line 82 of file parser.c.

References core_yylex(), base_yy_extra_type::have_lookahead, base_yy_extra_type::lookahead_token, base_yy_extra_type::lookahead_yylloc, base_yy_extra_type::lookahead_yylval, pg_yyget_extra, and YYLTYPE.

Referenced by filtered_base_yylex().

{
    base_yy_extra_type *yyextra = pg_yyget_extra(yyscanner);
    int         cur_token;
    int         next_token;
    core_YYSTYPE cur_yylval;
    YYLTYPE     cur_yylloc;

    /* Get next token --- we might already have it */
    if (yyextra->have_lookahead)
    {
        cur_token = yyextra->lookahead_token;
        lvalp->core_yystype = yyextra->lookahead_yylval;
        *llocp = yyextra->lookahead_yylloc;
        yyextra->have_lookahead = false;
    }
    else
        cur_token = core_yylex(&(lvalp->core_yystype), llocp, yyscanner);

    /* Do we need to look ahead for a possible multiword token? */
    switch (cur_token)
    {
        case NULLS_P:

            /*
             * NULLS FIRST and NULLS LAST must be reduced to one token
             */
            cur_yylval = lvalp->core_yystype;
            cur_yylloc = *llocp;
            next_token = core_yylex(&(lvalp->core_yystype), llocp, yyscanner);
            switch (next_token)
            {
                case FIRST_P:
                    cur_token = NULLS_FIRST;
                    break;
                case LAST_P:
                    cur_token = NULLS_LAST;
                    break;
                default:
                    /* save the lookahead token for next time */
                    yyextra->lookahead_token = next_token;
                    yyextra->lookahead_yylval = lvalp->core_yystype;
                    yyextra->lookahead_yylloc = *llocp;
                    yyextra->have_lookahead = true;
                    /* and back up the output info to cur_token */
                    lvalp->core_yystype = cur_yylval;
                    *llocp = cur_yylloc;
                    break;
            }
            break;

        case WITH:

            /*
             * WITH TIME must be reduced to one token
             */
            cur_yylval = lvalp->core_yystype;
            cur_yylloc = *llocp;
            next_token = core_yylex(&(lvalp->core_yystype), llocp, yyscanner);
            switch (next_token)
            {
                case TIME:
                    cur_token = WITH_TIME;
                    break;
                default:
                    /* save the lookahead token for next time */
                    yyextra->lookahead_token = next_token;
                    yyextra->lookahead_yylval = lvalp->core_yystype;
                    yyextra->lookahead_yylloc = *llocp;
                    yyextra->have_lookahead = true;
                    /* and back up the output info to cur_token */
                    lvalp->core_yystype = cur_yylval;
                    *llocp = cur_yylloc;
                    break;
            }
            break;

        default:
            break;
    }

    return cur_token;
}

List* raw_parser ( const char *  str  ) 

Definition at line 35 of file parser.c.

References base_yyparse(), base_yy_extra_type::core_yy_extra, base_yy_extra_type::have_lookahead, NumScanKeywords, parser_init(), base_yy_extra_type::parsetree, ScanKeywords, scanner_finish(), scanner_init(), and yyscanner.

Referenced by ATPostAlterTypeParse(), parseTypeString(), and pg_parse_query().

{
    core_yyscan_t yyscanner;
    base_yy_extra_type yyextra;
    int         yyresult;

    /* initialize the flex scanner */
    yyscanner = scanner_init(str, &yyextra.core_yy_extra,
                             ScanKeywords, NumScanKeywords);

    /* base_yylex() only needs this much initialization */
    yyextra.have_lookahead = false;

    /* initialize the bison parser */
    parser_init(&yyextra);

    /* Parse! */
    yyresult = base_yyparse(yyscanner);

    /* Clean up (release memory) */
    scanner_finish(yyscanner);

    if (yyresult)               /* error */
        return NIL;

    return yyextra.parsetree;
}