mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
parser.y: GLR -> LALR
This commit is contained in:
parent
6e3b9e6a4d
commit
18db46a6cb
2 changed files with 14 additions and 4 deletions
|
@ -20,6 +20,7 @@ struct StringToken
|
||||||
operator std::string_view() const { return {p, l}; }
|
operator std::string_view() const { return {p, l}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This type must be trivially copyable; see YYLTYPE_IS_TRIVIAL in parser.y.
|
||||||
struct ParserLocation
|
struct ParserLocation
|
||||||
{
|
{
|
||||||
int beginOffset;
|
int beginOffset;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
%glr-parser
|
%define api.location.type { ::nix::ParserLocation }
|
||||||
%define api.pure
|
%define api.pure
|
||||||
%locations
|
%locations
|
||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
|
@ -9,7 +9,6 @@
|
||||||
%lex-param { void * scanner }
|
%lex-param { void * scanner }
|
||||||
%lex-param { nix::ParserState * state }
|
%lex-param { nix::ParserState * state }
|
||||||
%expect 0
|
%expect 0
|
||||||
%expect-rr 0
|
|
||||||
|
|
||||||
%code requires {
|
%code requires {
|
||||||
|
|
||||||
|
@ -27,7 +26,17 @@
|
||||||
#include "eval-settings.hh"
|
#include "eval-settings.hh"
|
||||||
#include "parser-state.hh"
|
#include "parser-state.hh"
|
||||||
|
|
||||||
#define YYLTYPE ::nix::ParserLocation
|
// Bison seems to have difficulty growing the parser stack when using C++ with
|
||||||
|
// a custom location type. This undocumented macro tells Bison that our
|
||||||
|
// location type is "trivially copyable" in C++-ese, so it is safe to use the
|
||||||
|
// same memcpy macro it uses to grow the stack that it uses with its own
|
||||||
|
// default location type. Without this, we get "error: memory exhausted" when
|
||||||
|
// parsing some large Nix files. Our other options are to increase the initial
|
||||||
|
// stack size (200 by default) to be as large as we ever want to support (so
|
||||||
|
// that growing the stack is unnecessary), or redefine the stack-relocation
|
||||||
|
// macro ourselves (which is also undocumented).
|
||||||
|
#define YYLTYPE_IS_TRIVIAL 1
|
||||||
|
|
||||||
#define YY_DECL int yylex \
|
#define YY_DECL int yylex \
|
||||||
(YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner, nix::ParserState * state)
|
(YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner, nix::ParserState * state)
|
||||||
|
|
||||||
|
@ -77,7 +86,7 @@ YY_DECL;
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
#define CUR_POS state->at(*yylocp)
|
#define CUR_POS state->at(yyloc)
|
||||||
|
|
||||||
|
|
||||||
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParserState * state, const char * error)
|
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParserState * state, const char * error)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue