]> git.saurik.com Git - bison.git/blob - data/java.m4
tests: minor improvements
[bison.git] / data / java.m4
1 -*- Autoconf -*-
2
3 # Java language support for Bison
4
5 # Copyright (C) 2007-2012 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 m4_include(b4_pkgdatadir/[c-like.m4])
21
22 # b4_comment(TEXT)
23 # ----------------
24 m4_define([b4_comment], [/* m4_bpatsubst([$1], [
25 ], [
26 ]) */])
27
28
29 # b4_list2(LIST1, LIST2)
30 # --------------------------
31 # Join two lists with a comma if necessary.
32 m4_define([b4_list2],
33 [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
34
35
36 # b4_percent_define_get3(DEF, PRE, POST, NOT)
37 # -------------------------------------------
38 # Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
39 # otherwise NOT.
40 m4_define([b4_percent_define_get3],
41 [m4_ifval(m4_quote(b4_percent_define_get([$1])),
42 [$2[]b4_percent_define_get([$1])[]$3], [$4])])
43
44
45
46 # b4_flag_value(BOOLEAN-FLAG)
47 # ---------------------------
48 m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
49
50
51 # b4_public_if(TRUE, FALSE)
52 # -------------------------
53 b4_percent_define_default([[public]], [[false]])
54 m4_define([b4_public_if],
55 [b4_percent_define_flag_if([public], [$1], [$2])])
56
57
58 # b4_abstract_if(TRUE, FALSE)
59 # ---------------------------
60 b4_percent_define_default([[abstract]], [[false]])
61 m4_define([b4_abstract_if],
62 [b4_percent_define_flag_if([abstract], [$1], [$2])])
63
64
65 # b4_final_if(TRUE, FALSE)
66 # ---------------------------
67 b4_percent_define_default([[final]], [[false]])
68 m4_define([b4_final_if],
69 [b4_percent_define_flag_if([final], [$1], [$2])])
70
71
72 # b4_strictfp_if(TRUE, FALSE)
73 # ---------------------------
74 b4_percent_define_default([[strictfp]], [[false]])
75 m4_define([b4_strictfp_if],
76 [b4_percent_define_flag_if([strictfp], [$1], [$2])])
77
78
79 # b4_lexer_if(TRUE, FALSE)
80 # ------------------------
81 m4_define([b4_lexer_if],
82 [b4_percent_code_ifdef([[lexer]], [$1], [$2])])
83
84
85 # b4_identification
86 # -----------------
87 m4_define([b4_identification],
88 [ /** Version number for the Bison executable that generated this parser. */
89 public static final String bisonVersion = "b4_version";
90
91 /** Name of the skeleton that generated this parser. */
92 public static final String bisonSkeleton = b4_skeleton;
93 ])
94
95
96 ## ------------ ##
97 ## Data types. ##
98 ## ------------ ##
99
100 # b4_int_type(MIN, MAX)
101 # ---------------------
102 # Return the smallest int type able to handle numbers ranging from
103 # MIN to MAX (included).
104 m4_define([b4_int_type],
105 [m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
106 b4_ints_in($@, [-32768], [32767]), [1], [short],
107 [int])])
108
109 # b4_int_type_for(NAME)
110 # ---------------------
111 # Return the smallest int type able to handle numbers ranging from
112 # `NAME_min' to `NAME_max' (included).
113 m4_define([b4_int_type_for],
114 [b4_int_type($1_min, $1_max)])
115
116 # b4_null
117 # -------
118 m4_define([b4_null], [null])
119
120
121 ## ------------------------- ##
122 ## Assigning token numbers. ##
123 ## ------------------------- ##
124
125 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
126 # ---------------------------------------
127 # Output the definition of this token as an enum.
128 m4_define([b4_token_enum],
129 [ /** Token number, to be returned by the scanner. */
130 public static final int $1 = $2;
131 ])
132
133
134 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
135 # -----------------------------------------------------
136 # Output the definition of the tokens (if there are) as enums.
137 m4_define([b4_token_enums],
138 [m4_if([$#$1], [1], [],
139 [/* Tokens. */
140 m4_map([b4_token_enum], [$@])])
141 ])
142
143 # b4-case(ID, CODE)
144 # -----------------
145 # We need to fool Java's stupid unreachable code detection.
146 m4_define([b4_case], [ case $1:
147 if (yyn == $1)
148 $2;
149 break;
150 ])
151
152
153 ## ---------------- ##
154 ## Default values. ##
155 ## ---------------- ##
156
157 m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
158 b4_percent_define_default([[stype]], [[Object]])])
159
160 # %name-prefix
161 m4_define_default([b4_prefix], [[YY]])
162
163 b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
164 m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
165
166 b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
167 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
168
169 b4_percent_define_default([[throws]], [])])
170 m4_define([b4_throws], [b4_percent_define_get([[throws]])])
171
172 b4_percent_define_default([[location_type]], [Location])])
173 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])
174
175 b4_percent_define_default([[position_type]], [Position])])
176 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])
177
178
179 ## ----------------- ##
180 ## Semantic Values. ##
181 ## ----------------- ##
182
183
184 # b4_lhs_value([TYPE])
185 # --------------------
186 # Expansion of $<TYPE>$.
187 m4_define([b4_lhs_value], [yyval])
188
189
190 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
191 # --------------------------------------
192 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
193 # symbols on RHS.
194 #
195 # In this simple implementation, %token and %type have class names
196 # between the angle brackets.
197 m4_define([b4_rhs_value],
198 [(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
199
200 # b4_lhs_location()
201 # -----------------
202 # Expansion of @$.
203 m4_define([b4_lhs_location],
204 [(yyloc)])
205
206
207 # b4_rhs_location(RULE-LENGTH, NUM)
208 # ---------------------------------
209 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
210 # on RHS.
211 m4_define([b4_rhs_location],
212 [yystack.locationAt ($1-($2))])
213
214
215 # b4_lex_param
216 # b4_parse_param
217 # --------------
218 # If defined, b4_lex_param arrives double quoted, but below we prefer
219 # it to be single quoted. Same for b4_parse_param.
220
221 # TODO: should be in bison.m4
222 m4_define_default([b4_lex_param], [[]]))
223 m4_define([b4_lex_param], b4_lex_param))
224 m4_define([b4_parse_param], b4_parse_param))
225
226 # b4_lex_param_decl
227 # -------------------
228 # Extra formal arguments of the constructor.
229 m4_define([b4_lex_param_decl],
230 [m4_ifset([b4_lex_param],
231 [b4_remove_comma([$1],
232 b4_param_decls(b4_lex_param))],
233 [$1])])
234
235 m4_define([b4_param_decls],
236 [m4_map([b4_param_decl], [$@])])
237 m4_define([b4_param_decl], [, $1])
238
239 m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
240
241
242
243 # b4_parse_param_decl
244 # -------------------
245 # Extra formal arguments of the constructor.
246 m4_define([b4_parse_param_decl],
247 [m4_ifset([b4_parse_param],
248 [b4_remove_comma([$1],
249 b4_param_decls(b4_parse_param))],
250 [$1])])
251
252
253
254 # b4_lex_param_call
255 # -------------------
256 # Delegating the lexer parameters to the lexer constructor.
257 m4_define([b4_lex_param_call],
258 [m4_ifset([b4_lex_param],
259 [b4_remove_comma([$1],
260 b4_param_calls(b4_lex_param))],
261 [$1])])
262 m4_define([b4_param_calls],
263 [m4_map([b4_param_call], [$@])])
264 m4_define([b4_param_call], [, $2])
265
266
267
268 # b4_parse_param_cons
269 # -------------------
270 # Extra initialisations of the constructor.
271 m4_define([b4_parse_param_cons],
272 [m4_ifset([b4_parse_param],
273 [b4_constructor_calls(b4_parse_param)])])
274
275 m4_define([b4_constructor_calls],
276 [m4_map([b4_constructor_call], [$@])])
277 m4_define([b4_constructor_call],
278 [this.$2 = $2;
279 ])
280
281
282
283 # b4_parse_param_vars
284 # -------------------
285 # Extra instance variables.
286 m4_define([b4_parse_param_vars],
287 [m4_ifset([b4_parse_param],
288 [
289 /* User arguments. */
290 b4_var_decls(b4_parse_param)])])
291
292 m4_define([b4_var_decls],
293 [m4_map_sep([b4_var_decl], [
294 ], [$@])])
295 m4_define([b4_var_decl],
296 [ protected final $1;])
297
298
299
300 # b4_maybe_throws(THROWS)
301 # -----------------------
302 # Expand to either an empty string or "throws THROWS".
303 m4_define([b4_maybe_throws],
304 [m4_ifval($1, [throws $1])])