2
0

gramparse.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-2022, PostgreSQL Global Development Group
  12. * Portions Copyright (c) 1994, Regents of the University of California
  13. *
  14. * src/include/parser/gramparse.h
  15. *
  16. *-------------------------------------------------------------------------
  17. */
  18. #ifndef GRAMPARSE_H
  19. #define GRAMPARSE_H
  20. #include "nodes/parsenodes.h"
  21. #include "parser/scanner.h"
  22. /*
  23. * NB: include gram.h only AFTER including scanner.h, because scanner.h
  24. * is what #defines YYLTYPE.
  25. */
  26. #include "parser/gram.h"
  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. */
  31. typedef struct base_yy_extra_type
  32. {
  33. /*
  34. * Fields used by the core scanner.
  35. */
  36. core_yy_extra_type core_yy_extra;
  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. * State variables that belong to the grammar.
  48. */
  49. List *parsetree; /* final parse result is delivered here */
  50. } base_yy_extra_type;
  51. /*
  52. * In principle we should use yyget_extra() to fetch the yyextra field
  53. * from a yyscanner struct. However, flex always puts that field first,
  54. * and this is sufficiently performance-critical to make it seem worth
  55. * cheating a bit to use an inline macro.
  56. */
  57. #define pg_yyget_extra(yyscanner) (*((base_yy_extra_type **) (yyscanner)))
  58. /* from parser.c */
  59. extern int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp,
  60. core_yyscan_t yyscanner);
  61. /* from gram.y */
  62. extern void parser_init(base_yy_extra_type *yyext);
  63. extern int base_yyparse(core_yyscan_t yyscanner);
  64. #endif /* GRAMPARSE_H */