[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] java: fix support for api.prefix
From: |
Akim Demaille |
Subject: |
[PATCH 2/3] java: fix support for api.prefix |
Date: |
Thu, 20 Jun 2019 07:01:10 +0200 |
* data/skeletons/java.m4: here.
* tests/java.at: Check it.
---
NEWS | 3 +++
data/skeletons/java.m4 | 15 +++++++++++++--
doc/bison.texi | 2 +-
tests/java.at | 5 ++++-
tests/local.at | 6 +++---
5 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/NEWS b/NEWS
index a7a37f1c..f039b51b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ In Java, %define api.prefix was ignored. It now behaves as expected.
* Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
diff --git a/data/skeletons/java.m4 b/data/skeletons/java.m4
index a62a52e1..edf23a92 100644
--- a/data/skeletons/java.m4
+++ b/data/skeletons/java.m4
@@ -184,8 +184,19 @@ b4_percent_define_check_kind([[throws]],
[code], [deprecated])
m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
b4_percent_define_default([[api.value.type]], [[Object]])
-# %name-prefix
-m4_define_default([b4_prefix], [[YY]])
+# b4_api_prefix, b4_api_PREFIX
+# ----------------------------
+# Corresponds to %define api.prefix
+b4_percent_define_default([[api.prefix]], [[YY]])
+m4_define([b4_api_prefix],
+[b4_percent_define_get([[api.prefix]])])
+m4_define([b4_api_PREFIX],
+[m4_toupper(b4_api_prefix)])
+
+# b4_prefix
+# ---------
+# If the %name-prefix is not given, it is api.prefix.
+m4_define_default([b4_prefix], [b4_api_prefix])
b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser])
m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])])
diff --git a/doc/bison.texi b/doc/bison.texi
index 927b9374..fc1dacf4 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -6068,7 +6068,7 @@ Introduced in Bison 3.3 to replace
@code{parser_class_name}.
@item Accepted Values: String
-@item Default Value: @code{yy}
+@item Default Value: @code{YY} for Java, @code{yy} otherwise.
@item History: introduced in Bison 2.6
@end itemize
diff --git a/tests/java.at b/tests/java.at
index 0c66c817..2fbfe6dc 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -60,7 +60,7 @@ AT_BISON_OPTION_PUSHDEFS([%language "Java" $4])
AT_DATA_GRAMMAR([Calc.y],
[[/* Infix notation calculator--calc */
%language "Java"
-%name-prefix "Calc"
+%define api.prefix {Calc}
%define api.parser.class {Calc}
%define public
@@ -444,6 +444,9 @@ AT_CHECK_JAVA_GREP([[class YYParser]])
AT_CHECK_JAVA_MINIMAL([[%name-prefix "Prefix"]])
AT_CHECK_JAVA_GREP([[class PrefixParser]])
+AT_CHECK_JAVA_MINIMAL([[%define api.prefix {Prefix}]])
+AT_CHECK_JAVA_GREP([[class PrefixParser]])
+
AT_CHECK_JAVA_MINIMAL([[%define api.token.prefix {TOK_}]])
AT_CHECK_JAVA_GREP([[.*TOK_END.*]])
diff --git a/tests/local.at b/tests/local.at
index 63310901..2b331cc9 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -200,7 +200,7 @@ m4_pushdef([AT_NAME_PREFIX],
[m4_bregexp([$3],
[\(%define api\.prefix\|%name-prefix\) [\{\"]\([^\"\}]*\)[\"\}]],
[\2])],
- [yy])])
+ [AT_JAVA_IF([YY], [yy])])])
# AT_NAMESPACE: also consider api.prefix. FIXME: Stop that confusion.
m4_pushdef([AT_NAMESPACE],
[m4_bmatch([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) .*],
@@ -218,7 +218,7 @@ m4_pushdef([AT_VARIANT_IF],
m4_pushdef([AT_API_prefix],
[m4_bmatch([$3], [%define api\.prefix {.*}],
[m4_bregexp([$3], [%define api\.prefix {\([^\}]*\)}], [\1])],
- [yy])])
+ [AT_JAVA_IF([YY], [yy])])])
m4_pushdef([AT_API_PREFIX],
[m4_toupper(AT_API_prefix)])
# yyerror receives the location if %location, and if the parser is pure. For
@@ -782,7 +782,7 @@ m4_define([AT_MAIN_DEFINE(java)],
{
public static void main (String args[]) throws IOException
{
- YYParser p = new YYParser ();
+ ]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser ();
System.exit (p.parse () ? 0 : 1);
}
}]])
--
2.21.0