X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/95612cfa608188fc323ed3f8560cc6aea953ff32..b25d88f6d2e2f4b59927aacecdc0a9e44a34b5d9:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index 74a6574f..8af3e885 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -40,7 +40,7 @@ #include "reader.h" #include "conflicts.h" -/* Produce verbose parse errors. */ +/* Produce verbose syntax errors. */ #define YYERROR_VERBOSE 1 #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ @@ -64,7 +64,7 @@ do { \ correctly typed access to it. */ #define yycontrol ((gram_control_t *) gram_control) -/* Request detailed parse error messages, and pass them to GRAM_ERROR. +/* Request detailed syntax error messages, and pass them to GRAM_ERROR. FIXME: depends on the undocumented availability of YYLLOC.t */ #undef yyerror #define yyerror(Msg) \ @@ -158,7 +158,8 @@ braced_code_t current_braced_code = action_braced_code; %type STRING string_content - BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action + BRACED_CODE code_content action + PROLOGUE EPILOGUE %type TYPE %type INT %type ID symbol string_as_id @@ -170,7 +171,6 @@ input: declarations "%%" grammar epilogue.opt { yycontrol->errcode = 0; - epilogue_set ($4, @4); } ; @@ -194,14 +194,20 @@ declaration: | "%expect" INT { expected_conflicts = $2; } | "%file-prefix" "=" string_content { spec_file_prefix = $3; } | "%glr-parser" { glr_parser = 1; } -| "%lex-param" string_content "," string_content - { muscle_pair_list_grow ("lex_param", $2, $4); } +| "%lex-param" code_content "," code_content + { + muscle_pair_list_grow ("lex_param", $2, $4); + scanner_last_string_free (); + } | "%locations" { locations_flag = 1; } | "%name-prefix" "=" string_content { spec_name_prefix = $3; } | "%no-lines" { no_lines_flag = 1; } | "%output" "=" string_content { spec_outfile = $3; } -| "%parse-param" string_content "," string_content - { muscle_pair_list_grow ("parse_param", $2, $4); } +| "%parse-param" code_content "," code_content + { + muscle_pair_list_grow ("parse_param", $2, $4); + scanner_last_string_free (); + } | "%pure-parser" { pure_parser = 1; } | "%skeleton" string_content { skeleton = $2; } | "%token-table" { token_table_flag = 1; } @@ -416,14 +422,21 @@ string_content: }; +/* A BRACED_CODE used for its contents. Strip the braces. */ +code_content: + BRACED_CODE + { + $$ = $1 + 1; + $$[strlen ($$) - 1] = '\0'; + }; + + epilogue.opt: /* Nothing. */ - { - $$ = xstrdup (""); - } | "%%" EPILOGUE { - $$ = $2; + epilogue_augment ($2, @2); + scanner_last_string_free (); } ; @@ -464,6 +477,10 @@ yyprint (FILE *file, case EPILOGUE: fprintf (file, " = {{ %s }}", value->string); break; + + default: + fprintf (file, "unknown token type"); + break; } }