X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/24fad99e2bb2bdb0d5bd62571a0be8d60b97e2f8..cae601224e356773fcd101dce0677f558e7c4357:/src/parse-skel.y diff --git a/src/parse-skel.y b/src/parse-skel.y index 8cf7fcd5..34445f3f 100644 --- a/src/parse-skel.y +++ b/src/parse-skel.y @@ -22,18 +22,27 @@ %debug %defines %verbose -%error-verbose +%locations +%name-prefix="skel_" +%pure-parser %{ #include "system.h" #include "obstack.h" +#include "quotearg.h" #include "files.h" +#include "getargs.h" #include "output.h" #include "skeleton.h" #include "muscle_tab.h" -extern FILE* yyin; -extern int yylineno; +#define YYERROR_VERBOSE 1 + +/* Pass the control structure to YYPARSE but not YYLEX (yet?). */ +#define YYPARSE_PARAM skel_control +/* YYPARSE receives SKEL_CONTROL as a void *. Provide a correctly + typed access to it. */ +#define yycontrol ((skel_control_t *) skel_control) char* prefix = NULL; FILE* parser = NULL; @@ -41,28 +50,37 @@ FILE* parser = NULL; size_t output_line; size_t skeleton_line; -static int merror PARAMS ((const char* error)); -static int yyerror PARAMS ((const char* error)); +static void merror PARAMS ((const char* error)); + +/* Request detailed parse error messages, and pass them to + YLEVAL_ERROR. */ +#undef yyerror +#define yyerror(Msg) \ + skel_error (yycontrol, &yylloc, Msg) +/* When debugging our pure parser, we want to see values and locations + of the tokens. */ +#define YYPRINT(File, Type, Value) \ + yyprint (File, &yylloc, Type, &Value) +static void yyprint (FILE *file, const yyltype *loc, + int type, const yystype *value); %} %union { - char *muscle; char *string; - char *literal; char character; - int yacc; + int boolean; } /* Name of a muscle. */ -%token MUSCLE +%token MUSCLE /* A string dedicated to Bison (%%"foo"). */ %token STRING /* Raw data, to output directly. */ -%token RAW +%token RAW /* Spaces. */ -%token BLANKS +%token BLANKS /* Raw data, but char by char. */ %token CHARACTER @@ -76,11 +94,14 @@ static int yyerror PARAMS ((const char* error)); %token TOKENS %token ACTIONS -%type section.yacc +%type section.yacc -%start skeleton +%start input %% +input: + { LOCATION_RESET (yylloc) } skeleton + ; skeleton : /* Empty. */ { } | section skeleton { } @@ -165,19 +186,53 @@ section.body } ; %% +/*------------------------------------------------------------------. +| When debugging the parser, display tokens' locations and values. | +`------------------------------------------------------------------*/ -static int +static void +yyprint (FILE *file, + const yyltype *loc, int type, const yystype *value) +{ + fputs (" (", file); + LOCATION_PRINT (file, *loc); + fputs (")", file); + switch (type) + { + case MUSCLE: + case STRING: + case RAW: + case BLANKS: + fprintf (file, " = %s", quotearg_style (c_quoting_style, + value->string)); + break; + + case CHARACTER: + fprintf (file, " = '%c'", value->character); + break; + + case YACC: + fprintf (file, " = %s", value->boolean ? "true" : "false"); + break; + } +} + + +static void merror (const char* error) { printf ("line %d: %%{%s} undeclared.\n", skeleton_line, error); - return 0; } -static int -yyerror (const char* error) +void +skel_error (skel_control_t *control, + const yyltype *loc, const char *msg) { - fprintf (stderr, "%s\n", error); - return 0; + /* Neutralize GCC warnings for unused parameters. */ + skel_control_t *c = control; + c++; + LOCATION_PRINT (stderr, *loc); + fprintf (stderr, "%s\n", msg); } void @@ -192,9 +247,11 @@ process_skeleton (const char* skel) skeleton_line = 1; /* Output. */ - yyin = fopen (skel, "r"); - yydebug = 0; - yyparse (); + skel_in = fopen (skel, "r"); + /* FIXME: This is not acceptable for a release. */ + skel__flex_debug = getenv ("BISON_TRACE_SCAN") ? 1 : 0; + skel_debug = getenv ("BISON_TRACE_PARSE") ? 1 : 0; + skel_parse (NULL); /* Close the last parser. */ if (parser)