mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Replace yyscan_t with another pointer type that we control.
This prevents the circuluar dependency between parser.gen.h and lexer.gen.h. Newer versions of bison add a prototype for yyparse() to parser.gen.h that include the as-yet-undeclared yyscan_t type.
This commit is contained in:
3
lexer.l
3
lexer.l
@ -1,5 +1,8 @@
|
|||||||
%{
|
%{
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
|
||||||
|
struct lexer_param;
|
||||||
|
|
||||||
#include "parser.gen.h" /* Generated by bison. */
|
#include "parser.gen.h" /* Generated by bison. */
|
||||||
|
|
||||||
#define YY_USER_ACTION \
|
#define YY_USER_ACTION \
|
||||||
|
36
parser.y
36
parser.y
@ -3,7 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
|
||||||
typedef void* yyscan_t;
|
struct lexer_param;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
%code requires {
|
%code requires {
|
||||||
@ -35,11 +35,11 @@ typedef void* yyscan_t;
|
|||||||
%parse-param {block* answer}
|
%parse-param {block* answer}
|
||||||
%parse-param {int* errors}
|
%parse-param {int* errors}
|
||||||
%parse-param {struct locfile* locations}
|
%parse-param {struct locfile* locations}
|
||||||
%parse-param {yyscan_t lexer}
|
%parse-param {struct lexer_param* lexer_param_ptr}
|
||||||
%lex-param {block* answer}
|
%lex-param {block* answer}
|
||||||
%lex-param {int* errors}
|
%lex-param {int* errors}
|
||||||
%lex-param {struct locfile* locations}
|
%lex-param {struct locfile* locations}
|
||||||
%lex-param {yyscan_t lexer}
|
%lex-param {struct lexer_param* lexer_param_ptr}
|
||||||
|
|
||||||
|
|
||||||
%token INVALID_CHARACTER
|
%token INVALID_CHARACTER
|
||||||
@ -88,21 +88,25 @@ typedef void* yyscan_t;
|
|||||||
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String
|
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String
|
||||||
%{
|
%{
|
||||||
#include "lexer.gen.h"
|
#include "lexer.gen.h"
|
||||||
#define FAIL(loc, msg) \
|
struct lexer_param {
|
||||||
do { \
|
yyscan_t lexer;
|
||||||
location l = loc; \
|
};
|
||||||
yyerror(&l, answer, errors, locations, lexer, msg); \
|
#define FAIL(loc, msg) \
|
||||||
/*YYERROR*/; \
|
do { \
|
||||||
|
location l = loc; \
|
||||||
|
yyerror(&l, answer, errors, locations, lexer_param_ptr, msg); \
|
||||||
|
/*YYERROR*/; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void yyerror(YYLTYPE* loc, block* answer, int* errors,
|
void yyerror(YYLTYPE* loc, block* answer, int* errors,
|
||||||
struct locfile* locations, yyscan_t lexer, const char *s){
|
struct locfile* locations, struct lexer_param* lexer_param_ptr, const char *s){
|
||||||
(*errors)++;
|
(*errors)++;
|
||||||
locfile_locate(locations, *loc, "error: %s", s);
|
locfile_locate(locations, *loc, "error: %s", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, block* answer, int* errors,
|
int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, block* answer, int* errors,
|
||||||
struct locfile* locations, yyscan_t lexer) {
|
struct locfile* locations, struct lexer_param* lexer_param_ptr) {
|
||||||
|
yyscan_t lexer = lexer_param_ptr->lexer;
|
||||||
while (1) {
|
while (1) {
|
||||||
int tok = jq_yylex(yylval, yylloc, lexer);
|
int tok = jq_yylex(yylval, yylloc, lexer);
|
||||||
if (tok == INVALID_CHARACTER) {
|
if (tok == INVALID_CHARACTER) {
|
||||||
@ -444,15 +448,15 @@ MkDictPair
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
int jq_parse(struct locfile* locations, block* answer) {
|
int jq_parse(struct locfile* locations, block* answer) {
|
||||||
yyscan_t scanner;
|
struct lexer_param scanner;
|
||||||
YY_BUFFER_STATE buf;
|
YY_BUFFER_STATE buf;
|
||||||
jq_yylex_init_extra(0, &scanner);
|
jq_yylex_init_extra(0, &scanner.lexer);
|
||||||
buf = jq_yy_scan_bytes(locations->data, locations->length, scanner);
|
buf = jq_yy_scan_bytes(locations->data, locations->length, scanner.lexer);
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
*answer = gen_noop();
|
*answer = gen_noop();
|
||||||
yyparse(answer, &errors, locations, scanner);
|
yyparse(answer, &errors, locations, &scanner);
|
||||||
jq_yy_delete_buffer(buf, scanner);
|
jq_yy_delete_buffer(buf, scanner.lexer);
|
||||||
jq_yylex_destroy(scanner);
|
jq_yylex_destroy(scanner.lexer);
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
block_free(*answer);
|
block_free(*answer);
|
||||||
*answer = gen_noop();
|
*answer = gen_noop();
|
||||||
|
Reference in New Issue
Block a user