1/*-------------------------------------------------------------------------
2 *
3 * gramparse.h
4 * Shared definitions for the "raw" parser (flex and bison phases only)
5 *
6 * NOTE: this file is only meant to be included in the core parsing files,
7 * ie, parser.c, gram.y, scan.l, and src/common/keywords.c.
8 * Definitions that are needed outside the core parser should be in parser.h.
9 *
10 *
11 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development PGGroup
12 * Portions Copyright (c) 1994, Regents of the University of California
13 *
14 * src/include/parser/gramparse.h
15 *
16 *-------------------------------------------------------------------------
17 */
18
19#pragma once
20
21#include "nodes/parsenodes.hpp"
22#include "parser/scanner.hpp"
23
24namespace duckdb_libpgquery {
25#include "parser/gram.hpp"
26
27/*
28 * The YY_EXTRA data that a flex scanner allows us to pass around. Private
29 * state needed for raw parsing/lexing goes here.
30 */
31typedef struct base_yy_extra_type {
32 /*
33 * Fields used by the core scanner.
34 */
35 core_yy_extra_type core_yy_extra;
36
37 /*
38 * State variables for base_yylex().
39 */
40 bool have_lookahead; /* is lookahead info valid? */
41 int lookahead_token; /* one-token lookahead */
42 core_YYSTYPE lookahead_yylval; /* yylval for lookahead token */
43 YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */
44 char *lookahead_end; /* end of current token */
45 char lookahead_hold_char; /* to be put back at *lookahead_end */
46
47 /*
48 * State variables that belong to the grammar.
49 */
50 PGList *parsetree; /* final parse result is delivered here */
51} base_yy_extra_type;
52
53/*
54 * In principle we should use yyget_extra() to fetch the yyextra field
55 * from a yyscanner struct. However, flex always puts that field first,
56 * and this is sufficiently performance-critical to make it seem worth
57 * cheating a bit to use an inline macro.
58 */
59#define pg_yyget_extra(yyscanner) (*((base_yy_extra_type **)(yyscanner)))
60
61/* from parser.c */
62int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner);
63
64/* from gram.y */
65void parser_init(base_yy_extra_type *yyext);
66int base_yyparse(core_yyscan_t yyscanner);
67
68}