X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/05e25f2384b96708ffaaf01e77f432736bd99d83..8bf276d8207dd31432305002f3a9e81c80ca62af:/tests/actions.at diff --git a/tests/actions.at b/tests/actions.at index b1695132..7d876709 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -1,6 +1,6 @@ e# Executing Actions. -*- Autotest -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -286,8 +286,8 @@ m4_popdef([AT_TEST]) ## Location Print. ## ## ---------------- ## -# AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1]) -# ----------------------------------------------------------------------- +# AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES]) +# ----------------------------------------------------- # Check that the initial location is correct. m4_pushdef([AT_TEST], [AT_SETUP([Location print: $1 $2]) @@ -475,7 +475,7 @@ AT_DATA_GRAMMAR([[input.y]], /* Display the symbol type Symbol. */ #define V(Symbol, Value, Location, Sep) \ - fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location)) + fprintf (stderr, #Symbol " (%d@%d-%d)%s", Value, RANGE(Location), Sep) } $5 @@ -490,15 +490,17 @@ AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[ ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE]) [} -]m4_ifval([$6], [%type '(' 'x' 'y' ')' ';' thing line input END])[ +]m4_ifval([$6], +[%type '(' 'x' 'y' ')' ';' thing line input + '!' raise check-spontaneous-errors END])[ /* FIXME: This %printer isn't actually tested. */ %printer { - ]AT_LALR1_CC_IF([debug_stream () << $$;], - [fprintf (yyoutput, "%d", $$)])[; + ]AT_LALR1_CC_IF([yyo << $$;], + [fprintf (yyo, "%d", $$)])[; } - input line thing 'x' 'y' + '(' 'x' 'y' ')' ';' thing line input '!' raise check-spontaneous-errors END %destructor { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); } @@ -512,6 +514,14 @@ AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[ { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); } thing +%destructor + { fprintf (stderr, "Freeing raise thing (%d@%d-%d)\n", $$, RANGE (@$)); } + raise + +%destructor + { fprintf (stderr, "Freeing check-spontaneous-errors thing (%d@%d-%d)\n", $$, RANGE (@$)); } + check-spontaneous-errors + %destructor { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); } 'x' @@ -534,7 +544,7 @@ AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[ */ input: - /* Nothing. */ + %empty { $$ = 0; V(input, $$, @$, ": /* Nothing */\n"); @@ -547,6 +557,38 @@ input: V(line, $1, @1, " "); V(input, $2, @2, "\n"); } +| '!' check-spontaneous-errors + { + $$ = $2; + } +; + +check-spontaneous-errors: + raise { abort(); $$ = $1; } +| '(' raise ')' { abort(); $$ = $2; } +| error + { + $$ = 5; + V(check-spontaneous-errors, $$, @$, ": "); + fprintf (stderr, "error (@%d-%d)\n", RANGE(@1)); + } +; + +raise: + %empty + { + $$ = 4; + V(raise, $$, @$, ": %empty\n"); + YYERROR; + } +| '!' '!' + { + $$ = 5; + V(raise, $$, @$, ": "); + V(!, $1, @2, " "); + V(!, $2, @2, "\n"); + YYERROR; + } ; line: @@ -596,7 +638,7 @@ thing: ; %% /* Alias to ARGV[1]. */ -const char *source = YY_NULL; +const char *source = YY_NULLPTR; ]AT_YYERROR_DEFINE[ @@ -605,11 +647,11 @@ static { static unsigned int counter = 0; - int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++; + unsigned int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++; /* As in BASIC, line numbers go from 10 to 10. */ ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c; ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9; - assert (0 <= c && c <= strlen (source)); + assert (c <= strlen (source)); if (source[c]) fprintf (stderr, "sending: '%c'", source[c]); else @@ -633,7 +675,7 @@ main (int argc, const char *argv[]) { int status; yydebug = !!getenv ("YYDEBUG"); - assert (argc == 2); + assert (argc == 2); (void) argc; source = argv[1]; status = yyparse (); switch (status) @@ -668,6 +710,38 @@ Freeing nterm input (2@0-29) Successful parse. ]]) +# Check the location of empty reductions raising an error +# ------------------------------------------------------- +# Here, the error is after token "!@0-9", so the error is raised from +# @9-9, and the error recovery detects that it starts from @9-9 and +# ends where starts the next token: END@10-19. +# +# So error recovery reports error@9-19. +AT_PARSER_CHECK([./input '!'], 0, [], +[[sending: '!' (0@0-9) +sending: END (1@10-19) +raise (4@9-9): %empty +check-spontaneous-errors (5@9-19): error (@9-19) +Freeing token END (1@10-19) +Freeing nterm input (5@0-19) +Successful parse. +]]) + +# Check the location of not empty reductions raising an error +# ----------------------------------------------------------- +# This time the error is raised from a rule with 2 rhs symbols: @10-29. +# It is recovered @10-29. +AT_PARSER_CHECK([[./input '!!!']], 0, [], +[[sending: '!' (0@0-9) +sending: '!' (1@10-19) +sending: '!' (2@20-29) +raise (5@10-29): ! (1@20-29) ! (2@20-29) +check-spontaneous-errors (5@10-29): error (@10-29) +sending: END (3@30-39) +Freeing token END (3@30-39) +Freeing nterm input (5@0-29) +Successful parse. +]]) # Check locations in error recovery # --------------------------------- @@ -848,13 +922,13 @@ AT_CLEANUP AT_CHECK_PRINTER_AND_DESTRUCTOR([]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([], [ with union]) AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [ with union]) AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser]) -AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union]) +AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [ with union]) @@ -1530,10 +1604,13 @@ AT_DATA_GRAMMAR([[input.y]], ]AT_SKEL_CC_IF([[ # include - static void - report (std::ostream& yyo, int ival, float fval) + namespace { - yyo << "ival: " << ival << ", fval: " << fval; + void + report (std::ostream& yyo, int ival, float fval) + { + yyo << "ival: " << ival << ", fval: " << fval; + } } ]], [[ # include