From c705968292968e0fd62566954424f9c21f84686c Mon Sep 17 00:00:00 2001 From: alitaso345 Date: Sun, 11 Jun 2023 11:53:53 +0900 Subject: [PATCH 1/2] Add user argument to some macros used by bison Template file on ruby/ruby/tool/lrama was changed by https://github.com/ruby/ruby/commit/bdaa491565e31e3615d5da61551e08c7868db272 . Ported changes from ruby/ruby to ruby/lrama. --- .github/workflows/test.yaml | 4 +-- template/bison/yacc.c | 66 +++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 97e32986..61074782 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -58,9 +58,7 @@ jobs: - run: mkdir -p tool/lrama working-directory: ../ruby - name: Copy Lrama to ruby/tool - run: cp -r exe lib ../ruby/tool/lrama - # TODO: Consider how to manage changes on ruby/ruby master and ruby/lrama - # run: cp -r exe lib template ../ruby/tool/lrama + run: cp -r exe lib template ../ruby/tool/lrama working-directory: - run: tree tool/lrama working-directory: ../ruby diff --git a/template/bison/yacc.c b/template/bison/yacc.c index 8a123ebb..857afb26 100644 --- a/template/bison/yacc.c +++ b/template/bison/yacc.c @@ -114,7 +114,7 @@ #ifndef YYDEBUG # define YYDEBUG 0 #endif -#if YYDEBUG +#if YYDEBUG && !defined(yydebug) extern int yydebug; #endif <%-# b4_percent_code_get([[requires]]). %code is not supported -%> @@ -731,7 +731,7 @@ do { \ /* Temporary convenience wrapper in case some people defined the undocumented and private YY_LOCATION_PRINT macros. */ -# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) +# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) YY_LOCATION_PRINT(File, *(Loc)<%= output.user_args %>) # elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL @@ -767,11 +767,11 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) /* Temporary convenience wrapper in case some people defined the undocumented and private YY_LOCATION_PRINT macros. */ -# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) +# define YY_LOCATION_PRINT(File, Loc<%= output.user_args %>) YYLOCATION_PRINT(File, &(Loc)<%= output.user_args %>) # else -# define YYLOCATION_PRINT(File, Loc) ((void) 0) +# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) ((void) 0) /* Temporary convenience wrapper in case some people defined the undocumented and private YY_LOCATION_PRINT macros. */ # define YY_LOCATION_PRINT YYLOCATION_PRINT @@ -780,13 +780,13 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) # endif /* !defined YYLOCATION_PRINT */ -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Kind, Value, Location, p); \ + Kind, Value, Location<%= output.user_args %>); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -828,9 +828,9 @@ yy_symbol_print (FILE *yyo, YYFPRINTF (yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - YYLOCATION_PRINT (yyo, yylocationp); + YYLOCATION_PRINT (yyo, yylocationp<%= output.user_args %>); YYFPRINTF (yyo, ": "); - yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, p); + yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp<%= output.user_args %>); YYFPRINTF (yyo, ")"); } @@ -840,7 +840,7 @@ yy_symbol_print (FILE *yyo, `------------------------------------------------------------------*/ static void -yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop<%= output.user_formals %>) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -851,10 +851,10 @@ yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) YYFPRINTF (stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ +# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>) \ do { \ if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ + yy_stack_print ((Bottom), (Top)<%= output.user_args %>); \ } while (0) @@ -878,25 +878,27 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, yy_symbol_print (stderr, YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), &yyvsp[(yyi + 1) - (yynrhs)], - &(yylsp[(yyi + 1) - (yynrhs)]), p); + &(yylsp[(yyi + 1) - (yynrhs)])<%= output.user_args %>); YYFPRINTF (stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ +# define YY_REDUCE_PRINT(Rule<%= output.user_args %>) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, p); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule<%= output.user_args %>); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ +#ifndef yydebug int yydebug; +#endif #else /* !YYDEBUG */ # define YYDPRINTF(Args) ((void) 0) -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>) +# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>) +# define YY_REDUCE_PRINT(Rule<%= output.user_args %>) #endif /* !YYDEBUG */ @@ -1110,7 +1112,7 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx, required number of bytes is too large to store. */ static int yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, - const yypcontext_t *yyctx) + const yypcontext_t *yyctx<%= output.user_formals %>) { enum { YYARGS_MAX = 5 }; /* Internationalized format string. */ @@ -1200,7 +1202,7 @@ yydestruct (const char *yymsg, <%= output.parse_param_use("yyvaluep", "yylocationp") %> if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp<%= output.user_args %>); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_USE (yykind); @@ -1227,11 +1229,11 @@ int yychar; /* The semantic value of the lookahead symbol. */ /* Default value used for initialization, for pacifying older GCCs or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) +YY_INITIAL_VALUE (static const YYSTYPE yyval_default;) YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Location data for the lookahead symbol. */ -static YYLTYPE yyloc_default +static const YYLTYPE yyloc_default # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL = { 1, 1, 1, 1 } # endif @@ -1322,7 +1324,7 @@ YYLTYPE yylloc = yyloc_default; YY_IGNORE_USELESS_CAST_BEGIN *yyssp = YY_CAST (yy_state_t, yystate); YY_IGNORE_USELESS_CAST_END - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE @@ -1440,7 +1442,7 @@ YYLTYPE yylloc = yyloc_default; else { yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>); } /* If the proper action on seeing token YYTOKEN is to reduce or to @@ -1463,7 +1465,7 @@ YYLTYPE yylloc = yyloc_default; yyerrstatus--; /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc<%= output.user_args %>); yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; @@ -1505,7 +1507,7 @@ YYLTYPE yylloc = yyloc_default; /* Default location. */ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); yyerror_range[1] = yyloc; - YY_REDUCE_PRINT (yyn); + YY_REDUCE_PRINT (yyn<%= output.user_args %>); switch (yyn) { <%= output.user_actions -%> @@ -1523,7 +1525,7 @@ YYLTYPE yylloc = yyloc_default; case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc<%= output.user_args %>); YYPOPSTACK (yylen); yylen = 0; @@ -1561,7 +1563,7 @@ YYLTYPE yylloc = yyloc_default; = {yyssp, yytoken, &yylloc}; char const *yymsgp = YY_("syntax error"); int yysyntax_error_status; - yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>); if (yysyntax_error_status == 0) yymsgp = yymsg; else if (yysyntax_error_status == -1) @@ -1573,7 +1575,7 @@ YYLTYPE yylloc = yyloc_default; if (yymsg) { yysyntax_error_status - = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>); yymsgp = yymsg; } else @@ -1628,7 +1630,7 @@ YYLTYPE yylloc = yyloc_default; this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>); yystate = *yyssp; goto yyerrlab1; @@ -1663,7 +1665,7 @@ YYLTYPE yylloc = yyloc_default; YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp<%= output.user_args %>); YYPOPSTACK (1); yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>); } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN @@ -1675,7 +1677,7 @@ YYLTYPE yylloc = yyloc_default; YYLLOC_DEFAULT (*yylsp, yyerror_range, 2); /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>); yystate = yyn; goto yynewstate; @@ -1721,7 +1723,7 @@ YYLTYPE yylloc = yyloc_default; /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>); while (yyssp != yyss) { yydestruct ("Cleanup: popping", From b5c19cbbd87b2649a07c46c5c08ec54497a51f5b Mon Sep 17 00:00:00 2001 From: alitaso345 Date: Sun, 11 Jun 2023 12:29:15 +0900 Subject: [PATCH 2/2] Remove integration spec that compares output of bison and lrama --- spec/integration/ruby_spec.rb | 56 ----------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 spec/integration/ruby_spec.rb diff --git a/spec/integration/ruby_spec.rb b/spec/integration/ruby_spec.rb deleted file mode 100644 index 3ca6af28..00000000 --- a/spec/integration/ruby_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -require "tempfile" -require "open3" - -RSpec.describe "integration" do - def generate_and_compare(version) - grammar_file_path = fixture_path("integration/#{version}/parse.tmp.y") - warning = Lrama::Warning.new - y = File.read(grammar_file_path) - out = Tempfile.new - header_out = Tempfile.new - grammar = Lrama::Parser.new(y).parse - states = Lrama::States.new(grammar, warning) - states.compute - context = Lrama::Context.new(states) - Lrama::Output.new( - out: out, - output_file_path: "y.tab.c", - template_name: "bison/yacc.c", - grammar_file_path: "parse.tmp.y", - header_out: header_out, - header_file_path: "y.tab.h", - context: context, - grammar: grammar, - ).render - out.close - header_out.close - - {"y.tab.c"=>out.path, "y.tab.h"=>header_out.path}.each do |expected, actual| - content = File.read(fixture_path("integration/#{version}/#{expected}")) - content.sub!(/\A.*\KGNU Bison \d+(?:\.\d)*/) {"Lrama #{Lrama::VERSION}"} - Tempfile.create(expected) do |tmp| - tmp.write(content) - out, err, status = Open3.capture3("git diff --exit-code -U0 --ignore-all-space --no-index #{actual} #{tmp.path}") - expect(status.success?).to be_truthy, out - end - end - end - - describe "Ruby 3.2" do - it do - generate_and_compare("ruby_3_2_0") - end - end - - describe "Ruby 3.1" do - it do - generate_and_compare("ruby_3_1_0") - end - end - - describe "Ruby 3.0" do - it do - generate_and_compare("ruby_3_0_5") - end - end -end