summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-02-01 08:38:53 +0100
committerAkim Demaille <akim.demaille@gmail.com>2020-02-02 11:28:45 +0100
commit0774b2c6e391d5428c2aae0c735933432ce74a3b (patch)
treeccfe260d681280158acbbe5c5fe8cf7327545892
parent493359b75815df852195b1517f868743ba7998f7 (diff)
downloadbison-0774b2c6e391d5428c2aae0c735933432ce74a3b.tar.gz
skeletons: add support for %code epilogue
When building the test cases, emitting code in the epilogue is very constraining. Let's make it simpler thanks to %code epilogue. However, I don't want to document this: it is bad style to use it (we should avoid having too many ways to write the same thing, TI!MTOWTDI), just put your code in the true epilogue section. * data/skeletons/glr.c, data/skeletons/lalr1.d, data/skeletons/lalr1.java, * data/skeletons/yacc.c: Implement support for %code epilogue. Remove useless comments. * tests/calc.at, tests/java.at: Simplify.
-rw-r--r--data/skeletons/glr.c3
-rw-r--r--data/skeletons/lalr1.d5
-rw-r--r--data/skeletons/lalr1.java6
-rw-r--r--data/skeletons/yacc.c3
-rw-r--r--tests/calc.at1
-rw-r--r--tests/java.at14
6 files changed, 13 insertions, 19 deletions
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index a3b0e69e..8cf56c31 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -2720,5 +2720,6 @@ m4_if(b4_prefix, [yy], [],
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])])[
-]b4_epilogue[]dnl
+]b4_percent_code_get([[epilogue]])[]dnl
+b4_epilogue[]dnl
b4_output_end
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index bbf87c63..6bae65f4 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -902,9 +902,8 @@ m4_popdef([b4_at_dollar])])dnl
stream.writeln ();
}]])[
}
-
- /* User implementation code. */
]b4_percent_code_get[
}
-]b4_epilogue[]dnl
+]b4_percent_code_get([[epilogue]])[]dnl
+b4_epilogue[]dnl
b4_output_end
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 678510a1..58490697 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -1036,10 +1036,8 @@ b4_dollar_popdef[]dnl
private static final int yyfinal_ = ]b4_final_state_number[;
private static final int yyntokens_ = ]b4_tokens_number[;
-/* User implementation code. */
-]b4_percent_code_get[]dnl
-
+]b4_percent_code_get[
}
-
+]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
b4_output_end
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index ccdf485c..c3c50da6 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -2065,5 +2065,6 @@ yypushreturn:]])[
YYSTACK_FREE (yymsg);]])[
return yyresult;
}
-]b4_epilogue[]dnl
+]b4_percent_code_get([[epilogue]])[]dnl
+b4_epilogue[]dnl
b4_output_end
diff --git a/tests/calc.at b/tests/calc.at
index 9be19e2c..bcaffb79 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -25,6 +25,7 @@
m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)])
+# Whether token translation is supported.
m4_pushdef([AT_TOKEN_TRANSLATE_IF],
[AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])])
diff --git a/tests/java.at b/tests/java.at
index 28a3377b..0383ddd4 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -117,13 +117,8 @@ exp:
| '-' error { $$ = new Integer (0); return YYERROR; }
;
-]AT_LEXPARAM_IF([[
-%code lexer {
-]],
-[[
-%%
-class CalcLexer implements Calc.Lexer {
-]])[
+]AT_LEXPARAM_IF([[%code lexer {]],
+ [[%code epilogue { class CalcLexer implements Calc.Lexer {]])[
StreamTokenizer st;
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
@@ -176,10 +171,9 @@ class CalcLexer implements Calc.Lexer {
else
return st.ttype;
}
-]AT_LEXPARAM_IF([[
+]AT_LEXPARAM_IF([], [[}]])[
};
-%%]], [[
-}]])[
+%%
]AT_JAVA_POSITION_DEFINE[
]])
])# _AT_DATA_JAVA_CALC_Y