java: avoid trailing white spaces

* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
This commit is contained in:
Akim Demaille
2020-02-01 10:41:44 +01:00
parent c16fcaf2fb
commit ba69beafac
2 changed files with 57 additions and 54 deletions

View File

@@ -147,7 +147,8 @@ b4_symbol_foreach([b4_token_enum])])])
# b4-case(ID, CODE)
# -----------------
# We need to fool Java's stupid unreachable code detection.
m4_define([b4_case], [ case $1:
m4_define([b4_case],
[ case $1:
if (yyn == $1)
$2;
break;
@@ -155,7 +156,8 @@ m4_define([b4_case], [ case $1:
# b4_predicate_case(LABEL, CONDITIONS)
# ------------------------------------
m4_define([b4_predicate_case], [ case $1:
m4_define([b4_predicate_case],
[ case $1:
if (! ($2)) YYERROR;
break;
])

View File

@@ -65,8 +65,8 @@ m4_define([b4_define_state],[[
int label = YYNEWSTATE;
/* Error handling. */
int yynerrs_ = 0;
]b4_locations_if([[/* The location where the error started. */
int yynerrs_ = 0;]b4_locations_if([[
/* The location where the error started. */
]b4_location_type[ yyerrloc = null;
/* Location. */
@@ -224,7 +224,8 @@ m4_define([b4_define_state],[[
]b4_percent_code_get([[lexer]])[
}
]])[/**
]])[
/**
* The object doing lexical analysis for us.
*/
private Lexer yylexer;
@@ -320,8 +321,8 @@ m4_define([b4_define_state],[[
}]])[
private final class YYStack {
private int[] stateStack = new int[16];
]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
private int[] stateStack = new int[16];]b4_locations_if([[
private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
private ]b4_yystype[[] valueStack = new ]b4_yystype[[16];
public int size = 16;
@@ -334,8 +335,7 @@ m4_define([b4_define_state],[[
{
int[] newStateStack = new int[size * 2];
System.arraycopy (stateStack, 0, newStateStack, 0, height);
stateStack = newStateStack;
]b4_locations_if([[
stateStack = newStateStack;]b4_locations_if([[
]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
System.arraycopy (locStack, 0, newLocStack, 0, height);
locStack = newLocStack;]])
@@ -347,8 +347,8 @@ m4_define([b4_define_state],[[
size *= 2;
}
stateStack[height] = state;
]b4_locations_if([[locStack[height] = loc;]])[
stateStack[height] = state;]b4_locations_if([[
locStack[height] = loc;]])[
valueStack[height] = value;
}
@@ -359,8 +359,8 @@ m4_define([b4_define_state],[[
public final void pop (int num) {
// Avoid memory leaks... garbage collection is a white lie!
if (0 < num) {
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);]b4_locations_if([[
java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
}
height -= num;
}
@@ -368,8 +368,9 @@ m4_define([b4_define_state],[[
public final int stateAt (int i) {
return stateStack[height - i];
}
]b4_locations_if([[
]b4_locations_if([[public final ]b4_location_type[ locationAt (int i) {
public final ]b4_location_type[ locationAt (int i) {
return locStack[height - i];
}
@@ -460,8 +461,8 @@ m4_define([b4_define_state],[[
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. */
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);
]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[]b4_parse_trace_if([[
]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt (yylen - 1) : yystack.valueAt (0);]b4_locations_if([[
]b4_location_type[ yyloc = yylloc (yystack, yylen);]])[]b4_parse_trace_if([[
yyReducePrint (yyn, yystack);]])[
@@ -547,16 +548,15 @@ m4_define([b4_define_state],[[
* Push Parse input from external lexer
*
* @@param yylextoken current token
* @@param yylexval current lval
]b4_locations_if([ * @@param yylexloc current position])[
* @@param yylexval current lval]b4_locations_if([[
* @@param yylexloc current position]])[
*
* @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
*/
public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))
b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
{
]b4_locations_if([/* @@$. */
b4_location_type yyloc;])[
public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
{]b4_locations_if([[
/* @@$. */
]b4_location_type[ yyloc;]])[
]b4_push_if([],[[
]b4_define_state[]b4_parse_trace_if([[
yycdebug ("Starting parse\n");]])[
@@ -706,7 +706,8 @@ b4_dollar_popdef[]dnl
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
}
]b4_locations_if([yyerrloc = yylloc;])[
]b4_locations_if([[
yyerrloc = yylloc;]])[
if (yyerrstatus_ == 3)
{
/* If just tried and failed to reuse lookahead token after an
@@ -730,8 +731,8 @@ b4_dollar_popdef[]dnl
/*-------------------------------------------------.
| errorlab -- error raised explicitly by YYERROR. |
`-------------------------------------------------*/
case YYERROR:
]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
case YYERROR:]b4_locations_if([[
yyerrloc = yystack.locationAt (yylen - 1);]])[
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
yystack.pop (yylen);
@@ -765,7 +766,8 @@ b4_dollar_popdef[]dnl
if (yystack.height == 0)
]b4_push_if([{label = YYABORT; break;}],[return false;])[
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
]b4_locations_if([[
yyerrloc = yystack.locationAt (0);]])[
yystack.pop ();
yystate = yystack.stateAt (0);]b4_parse_trace_if([[
if (0 < yydebug)
@@ -776,12 +778,12 @@ b4_dollar_popdef[]dnl
/* Leave the switch. */
break;
]b4_locations_if([
]b4_locations_if([[
/* Muck with the stack to setup for yylloc. */
yystack.push (0, null, yylloc);
yystack.push (0, null, yyerrloc);
yyloc = yylloc (yystack, 2);
yystack.pop (2);])[
yystack.pop (2);]])[
/* Shift the error token. */]b4_parse_trace_if([[
yySymbolPrint ("Shifting", yystos_[yyn],
@@ -823,10 +825,10 @@ b4_dollar_popdef[]dnl
this.label = YYNEWSTATE;
/* Error handling. */
this.yynerrs_ = 0;
]b4_locations_if([/* The location where the error started. */
this.yynerrs_ = 0;]b4_locations_if([[
/* The location where the error started. */
this.yyerrloc = null;
this.yylloc = new b4_location_type (null, null);])[
this.yylloc = new ]b4_location_type[ (null, null);]])[
/* Semantic value of the lookahead. */
this.yylval = null;
@@ -846,8 +848,7 @@ b4_dollar_popdef[]dnl
*
* @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
*/
public int push_parse (int yylextoken, b4_yystype yylexval, b4_position_type yylexpos)
b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])
public int push_parse (int yylextoken, b4_yystype yylexval, b4_position_type yylexpos)b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])
{
return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
}
@@ -872,9 +873,9 @@ b4_dollar_popdef[]dnl
]b4_yystype[ lval = yylexer.getLVal();
]b4_locations_if([dnl
b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
yylexer.getEndPos ());])[
]b4_locations_if([status = push_parse(token,lval,yyloc);],[
status = push_parse(token,lval);])[
yylexer.getEndPos ());])[]b4_locations_if([[
status = push_parse(token,lval,yyloc);]], [[
status = push_parse(token,lval);]])[
} while (status == YYPUSH_MORE);
return (status == YYACCEPT);
}