]b4_position_type[ class, denote a point in the input.
+ * Locations represent a part of the input through the beginning
+ * and ending positions.
+ */
+ public static class ]b4_location_type[ {
+ /**
+ * The first, inclusive, position in the range.
+ */
+ public ]b4_position_type[ begin;
+
+ /**
+ * The first position beyond the range.
+ */
+ public ]b4_position_type[ end;
+
+ /**
+ * Create a ]b4_location_type[ denoting an empty range located at
+ * a given point.
+ * @@param loc The position at which the range is anchored.
+ */
+ public ]b4_location_type[ (]b4_position_type[ loc) {
+ this.begin = this.end = loc;
+ }
+
+ /**
+ * Create a ]b4_location_type[ from the endpoints of the range.
+ * @@param begin The first position included in the range.
+ * @@param end The first position beyond the range.
+ */
+ public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) {
+ this.begin = begin;
+ this.end = end;
+ }
+
+ /**
+ * Print a representation of the location. For this to be correct,
+ * ]b4_position_type[ should override the equals
+ * method.
+ */
+ public String toString() {
+ if (begin.equals (end)) {
+ return begin.toString();
+ } else {
+ return begin.toString() + "-" + end.toString();
+ }
+ }
+ }
+
+ private ]b4_location_type[ yylloc(YYStack rhs, int n)
+ {
+ if (n > 0) {
+ return new ]b4_location_type[(rhs.locationAt(n-1).begin, rhs.locationAt(0).end);
+ } else {
+ return new ]b4_location_type[(rhs.locationAt(0).end);
+ }
+ }]])[
+
+]b4_declare_symbol_enum[
+
+ /**
+ * Communication interface between the scanner and the Bison-generated
+ * parser ]b4_parser_class[.
+ */
+ public interface Lexer {
+ ]b4_token_enums[
+ /** Deprecated, use ]b4_symbol(eof, id)[ instead. */
+ public static final int EOF = ]b4_symbol(eof, id)[;
+ ]b4_pull_if([b4_locations_if([[
+ /**
+ * Method to retrieve the beginning position of the last scanned token.
+ * @@return the position at which the last scanned token starts.
+ */
+ ]b4_position_type[ getStartPos();
+
+ /**
+ * Method to retrieve the ending position of the last scanned token.
+ * @@return the first position beyond the last scanned token.
+ */
+ ]b4_position_type[ getEndPos();]])[
+
+ /**
+ * Method to retrieve the semantic value of the last scanned token.
+ * @@return the semantic value of the last scanned token.
+ */
+ ]b4_yystype[ getLVal();
+
+ /**
+ * Entry point for the scanner. Returns the token identifier corresponding
+ * to the next token and prepares to return the semantic value
+ * ]b4_locations_if([and beginning/ending positions ])[of the token.
+ * @@return the token identifier corresponding to the next token.
+ */
+ int yylex()]b4_maybe_throws([b4_lex_throws])[;
+ ]])[
+ /**
+ * Emit an error]b4_locations_if([ referring to the given location])[in a user-defined way.
+ *
+ *]b4_locations_if([[ @@param loc The location of the element to which the
+ * error message is related.]])[
+ * @@param msg The string for the error message.
+ */
+ void yyerror(]b4_locations_if([b4_location_type[ loc, ]])[String msg);
+
+ ]b4_parse_error_bmatch(
+ [custom], [[
+ /**
+ * Build and emit a "syntax error" message in a user-defined way.
+ *
+ * @@param ctx The context of the error.
+ */
+ void reportSyntaxError(Context ctx);
+ ]])[
+}
+
+ ]b4_lexer_if([[
+ private class YYLexer implements Lexer {
+ ]b4_percent_code_get([[lexer]])[
+}
+
+ ]])[
+ /**
+ * The object doing lexical analysis for us.
+ */
+ private Lexer yylexer;
+
+ ]b4_parse_param_vars[
+
+]b4_lexer_if([[
+ /**
+ * Instantiates the Bison-generated parser.
+ */
+ public ]b4_parser_class[(]b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[
+ {
+ ]b4_percent_code_get([[init]])[]b4_lac_if([[
+ this.yylacStack = new ArrayListnull location.]])[
+ * @@param msg The error message.
+ */
+ public final void yyerror(String msg) {
+ yylexer.yyerror(]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
+ }
+ ]b4_locations_if([[
+ /**
+ * Print an error message via the lexer.
+ * @@param loc The location associated with the message.
+ * @@param msg The error message.
+ */
+ public final void yyerror(]b4_location_type[ loc, String msg) {
+ yylexer.yyerror(loc, msg);
+}
+
+ /**
+ * Print an error message via the lexer.
+ * @@param pos The position associated with the message.
+ * @@param msg The error message.
+ */
+ public final void yyerror(]b4_position_type[ pos, String msg) {
+ yylexer.yyerror(new ]b4_location_type[ (pos), msg);
+}]])[
+ ]b4_parse_trace_if([[
+ protected final void yycdebugNnl(String s) {
+ if (0 < yydebug) {
+ yyDebugStream.print(s);
+ }
+ }
+
+ protected final void yycdebug(String s) {
+ if (0 < yydebug) {
+ yyDebugStream.println(s);
+ }
+ }]])[
+
+ private final class YYStack {
+ 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;
+ public int height = -1;
+
+ public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
+ height++;
+ if (size == height) {
+ int[] newStateStack = new int[size * 2];
+ // TODO Replace with copyInto
+ System.arraycopy(stateStack, 0, newStateStack, 0, height);
+ stateStack = newStateStack;]b4_locations_if([[
+ ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
+ // TODO Replace with copyInto
+ System.arraycopy(locStack, 0, newLocStack, 0, height);
+ locStack = newLocStack;]])
+
+ b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
+ // TODO Replace with copyInto
+ System.arraycopy(valueStack, 0, newValueStack, 0, height);
+ valueStack = newValueStack;
+
+ size *= 2;
+ }
+
+ stateStack[height] = state;]b4_locations_if([[
+ locStack[height] = loc;]])[
+ valueStack[height] = value;
+ }
+
+ public final void pop() {
+ pop(1);
+ }
+
+ public final void pop(int num) {
+ // TODO Replace with valueStack.fill
+ // Avoid memory leaks... garbage collection is a white lie!
+ if (num > 0) {
+ 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;
+ }
+
+ public final int stateAt(int i) {
+ return stateStack[height - i];
+ }
+ ]b4_locations_if([[
+
+ public final ]b4_location_type[ locationAt(int i) {
+ return locStack[height - i];
+ }
+ ]])[
+ public final ]b4_yystype[ valueAt(int i) {
+ return valueStack[height - i];
+ }
+
+ // TODO Replace with a PrintStream interface
+ // Print the state stack on the debug stream.
+ public void print(java.io.PrintStream out) {
+ out.print ("Stack now");
+
+ for (int i = 0; i <= height; i++) {
+ out.print(' ');
+ out.print(stateStack[i]);
+ }
+ out.println();
+ }
+ }
+
+ /**
+ * Returned by a Bison action in order to stop the parsing process and
+ * return success (true).
+ */
+ public static final int YYACCEPT = 0;
+
+ /**
+ * Returned by a Bison action in order to stop the parsing process and
+ * return failure (false).
+ */
+ public static final int YYABORT = 1;
+
+ ]b4_push_if([
+ /**
+ * Returned by a Bison action in order to request a new token.
+ */
+ public static final int YYPUSH_MORE = 4;])[
+
+ /**
+ * Returned by a Bison action in order to start error recovery without
+ * printing an error message.
+ */
+ public static final int YYERROR = 2;
+
+ /**
+ * Internal return codes that are not supported for user semantic
+ * actions.
+ */
+ private static final int YYERRLAB = 3;
+ private static final int YYNEWSTATE = 4;
+ private static final int YYDEFAULT = 5;
+ private static final int YYREDUCE = 6;
+ private static final int YYERRLAB1 = 7;
+ private static final int YYRETURN = 8;
+ ]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[
+
+ private int yyerrstatus_ = 0;
+
+ ]b4_push_if([b4_define_state])[
+ /**
+ * Whether error recovery is being done. In this state, the parser
+ * reads token until it reaches a known state, and then restarts normal
+ * operation.
+ */
+ public final boolean recovering ()
+ {
+ return yyerrstatus_ == 0;
+ }
+
+ /** Compute post-reduction state.
+ * @@param yystate the current state
+ * @@param yysym the nonterminal to push on the stack
+ */
+ private int yyLRGotoState(int yystate, int yysym) {
+ int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate;
+ if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate) {
+ return yytable_[yyr];
+ } else {
+ return yydefgoto_[yysym - YYNTOKENS_];
+ }
+}
+
+ private int yyaction(int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[
+ {
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'. Otherwise, use the top of the stack.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. */
+ ]b4_yystype[ yyval;
+ if (0 < yylen) {
+ yyval = yystack.valueAt(yylen - 1);
+ } else {
+ yyval = yystack.valueAt(0);
+ }]b4_locations_if([[
+ ]b4_location_type[ yyloc = yylloc(yystack, yylen);]])[]b4_parse_trace_if([[
+
+ yyReducePrint(yyn, yystack);]])[
+
+ // TODO CHECK if it can be removed right away if only default condition is present
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default: break;
+ }]b4_parse_trace_if([[
+
+ yySymbolPrint("-> $$ =", SymbolKind.get(yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
+
+ yystack.pop(yylen);
+ yylen = 0;
+ /* Shift the result of the reduction. */
+ int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]);
+ yystack.push(yystate, yyval]b4_locations_if([, yyloc])[);
+ return YYNEWSTATE;
+ }
+
+ ]b4_parse_trace_if([[
+ /*--------------------------------.
+ | Print this symbol on YYOUTPUT. |
+ `--------------------------------*/
+
+ private void yySymbolPrint(String s, SymbolKind yykind,
+]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[) {
+ // TODO Replace with builder
+ if (yydebug > 0) {
+ yycdebug(s
+ + (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ")
+ + yykind.getSymbolName() + " ("]b4_locations_if([
+ + yylocation + ": "])[
+ + (yyvalue == null ? "(null)" : yyvalue.toString()) + ")");
+ }
+}]])[
+
+ ]b4_push_if([],[[
+ /**
+ * Parse input from the scanner that was specified at object construction
+ * time. Return whether the end of the input was reached successfully.
+ *
+ * @@return true if the parsing succeeds. Note that this does not
+ * imply that there were no syntax errors.
+ */
+ public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
+]b4_push_if([
+ /**
+ * Push Parse input from external lexer
+ *
+ * @@param yylextoken current token
+ * @@param yylexval current lval]b4_locations_if([[
+ * @@param yylexloc current position]])[
+ *
+ * @@return YYACCEPT, YYABORT, YYPUSH_MORE
+ */
+ 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_lac_if([[
+ // Discard the LAC context in case there still is one left from a
+ // previous invocation.
+ yylacDiscard("init");]])[
+ ]b4_parse_trace_if([[
+ yycdebug ("Starting parse");]])[
+ yyerrstatus_ = 0;
+ yynerrs = 0;
+
+ /* Initialize the stack. */
+ yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
+ ]m4_ifdef([b4_initial_action], [
+ b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
+ b4_user_initial_action
+ b4_dollar_popdef[]dnl
+ ])[
+ ]])[
+ ]b4_push_if([[
+ if (!this.push_parse_initialized)
+ {
+ push_parse_initialize ();
+ ]m4_ifdef([b4_initial_action], [
+ b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
+ b4_user_initial_action
+ b4_dollar_popdef[]dnl
+ ])[]b4_parse_trace_if([[
+ yycdebug ("Starting parse");]])[
+ yyerrstatus_ = 0;
+ } else {
+ label = YYGETTOKEN;
+ }
+
+ boolean push_token_consumed = true;
+ ]])[
+ for (;;)
+ labelSwitch: switch (label)
+ {
+ /* New state. Unlike in the C/C++ skeletons, the state is already
+ pushed when we come here. */
+ case YYNEWSTATE:]b4_parse_trace_if([[
+ yycdebug ("Entering state " + yystate);
+ if (0 < yydebug) {
+ yystack.print(yyDebugStream);
+ }]])[
+
+ /* Accept? */
+ if (yystate == YYFINAL_) {
+ ]b4_push_if([label = YYACCEPT; break labelSwitch;],
+ [return true;])[
+ }
+
+ /* Take a decision. First try without lookahead. */
+ yyn = yypact_[yystate];
+ if (yyPactValueIsDefault (yyn))
+ {
+ label = YYDEFAULT;
+ break labelSwitch;
+ }
+ ]b4_push_if([ /* Fall Through */
+
+ case YYGETTOKEN:])[
+ /* Read a lookahead token. */
+ if (yychar == YYEMPTY_)
+ {
+ ]b4_push_if([[
+ if (!push_token_consumed) {
+ return YYPUSH_MORE;
+ }]b4_parse_trace_if([[
+ yycdebug ("Reading a token");]])[
+ yychar = yylextoken;
+ yylval = yylexval;]b4_locations_if([
+ yylloc = yylexloc;])[
+ push_token_consumed = false;]], [b4_parse_trace_if([[
+ yycdebug ("Reading a token");]])[
+ yychar = yylexer.yylex ();
+ yylval = yylexer.getLVal();]b4_locations_if([[
+ yylloc = new ]b4_location_type[(yylexer.getStartPos(),
+ yylexer.getEndPos());]])[
+ ]])[
+ }
+
+ /* Convert token to internal form. */
+ yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
+ yySymbolPrint("Next token is", yytoken,
+ yylval]b4_locations_if([, yylloc])[);]])[
+
+ if (yytoken == ]b4_symbol(error, kind)[)
+ {
+ // The scanner already issued an error message, process directly
+ // to error recovery. But do not keep the error token as
+ // lookahead, it is too special and may lead us to an endless
+ // loop in error recovery. */
+ yychar = Lexer.]b4_symbol(undef, id)[;
+ yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
+ yyerrloc = yylloc;]])[
+ label = YYERRLAB1;
+ }
+ else
+ {
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken.getCode();
+ if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) {]b4_lac_if([[
+ if (!yylacEstablish(yystack, yytoken)) {
+ label = YYERRLAB;
+ } else]])[
+ label = YYDEFAULT;
+ } else if (yytable_[yyn] <= 0) { /* <= 0 means reduce or error. */
+ yyn = yytable_[yyn];
+
+ if (yyTableValueIsError(yyn)) {
+ label = YYERRLAB;
+ }]b4_lac_if([[ else if (!yylacEstablish(yystack, yytoken)) {
+ label = YYERRLAB;
+ }]])[ else {
+ yyn = -yyn;
+ label = YYREDUCE;
+ }
+ } else {
+ /* Shift the lookahead token. */]b4_parse_trace_if([[
+ yySymbolPrint("Shifting", yytoken,
+ yylval]b4_locations_if([, yylloc])[);
+ ]])[
+ /* Discard the token being shifted. */
+ yychar = YYEMPTY_;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus_ > 0) {
+ --yyerrstatus_;
+ }
+
+ yystate = yyn;
+ yystack.push(yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[
+ yylacDiscard("shift");]])[
+ label = YYNEWSTATE;
+ }
+ }
+ break labelSwitch;
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ case YYDEFAULT:
+ yyn = yydefact_[yystate];
+ if (yyn == 0) {
+ label = YYERRLAB;
+ } else {
+ label = YYREDUCE;
+ }
+ break labelSwitch;
+
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ case YYREDUCE:
+ yylen = yyr2_[yyn];
+ label = yyaction(yyn, yystack, yylen);
+ yystate = yystack.stateAt(0);
+ break labelSwitch;
+
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
+ case YYERRLAB:
+ /* If not already recovering from an error, report this error. */
+ if (yyerrstatus_ == 0)
+ {
+ ++yynerrs;
+ if (yychar == YYEMPTY_) {
+ yytoken = null;
+ }
+ yyreportSyntaxError(new Context(this, yystack, yytoken]b4_locations_if([[, yylloc]])[));
+ }
+ ]b4_locations_if([[
+ yyerrloc = yylloc;]])[
+ if (yyerrstatus_ == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= Lexer.]b4_symbol(eof, id)[) {
+ /* Return failure if at end of input. */
+ if (yychar == Lexer.]b4_symbol(eof, id)[) {
+ ]b4_push_if([label = YYABORT; break labelSwitch;], [return false;])[
+ }
+ } else {
+ yychar = YYEMPTY_;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ label = YYERRLAB1;
+ break labelSwitch;
+
+ /*-------------------------------------------------.
+ | errorlab -- error raised explicitly by YYERROR. |
+ `-------------------------------------------------*/
+ 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);
+ yylen = 0;
+ yystate = yystack.stateAt(0);
+ label = YYERRLAB1;
+ break labelSwitch;
+
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
+ case YYERRLAB1:
+ yyerrstatus_ = 3; /* Each real token shifted decrements this. */
+
+ // Pop stack until we find a state that shifts the error token.
+ for (;;)
+ {
+ yyn = yypact_[yystate];
+ if (!yyPactValueIsDefault (yyn))
+ {
+ yyn += ]b4_symbol(error, kind)[.getCode();
+ if (yyn >= 0 &&
+ yyn <= YYLAST_ &&
+ yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode()
+ ) {
+ yyn = yytable_[yyn];
+ if (0 < yyn) {
+ break;
+ }
+ }
+ }
+
+ /* Pop the current state because it cannot handle the
+ * error token. */
+ if (yystack.height == 0) {
+ ]b4_push_if([label = YYABORT; break labelSwitch;],[return false;])[
+ }
+
+ ]b4_locations_if([[
+ yyerrloc = yystack.locationAt (0);]])[
+ yystack.pop ();
+ yystate = yystack.stateAt(0);]b4_parse_trace_if([[
+ if (0 < yydebug) {
+ yystack.print(yyDebugStream);]])[
+ }
+ }
+
+ if (label == YYABORT) {
+ /* Leave the switch. */
+ break labelSwitch;
+ }
+
+ ]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);]])[
+
+ /* Shift the error token. */]b4_lac_if([[
+ yylacDiscard("error recovery");]])[]b4_parse_trace_if([[
+ yySymbolPrint("Shifting", SymbolKind.get(yystos_[yyn]),
+ yylval]b4_locations_if([, yyloc])[);]])[
+
+ yystate = yyn;
+ yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
+ label = YYNEWSTATE;
+ break labelSwitch;
+
+ /* Accept. */
+ case YYACCEPT:
+ ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;],
+ [return true;])[
+
+ /* Abort. */
+ case YYABORT:
+ ]b4_push_if([this.push_parse_initialized = false; return YYABORT;],
+ [return false;])[
+ }
+ }
+]b4_push_if([[
+ boolean push_parse_initialized = false;
+
+ /**
+ * (Re-)Initialize the state of the push parser.
+ */
+ public void push_parse_initialize ()
+ {
+ /* Lookahead and lookahead in internal form. */
+ this.yychar = YYEMPTY_;
+ this.yytoken = null;
+
+ /* State. */
+ this.yyn = 0;
+ this.yylen = 0;
+ this.yystate = 0;
+ this.yystack = new YYStack();]b4_lac_if([[
+ this.yylacStack = new ArrayListyypact_ value indicates a defaulted state.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yyPactValueIsDefault(int yyvalue) {
+ return yyvalue == yypact_ninf_;
+ }
+
+ /**
+ * Whether the given yytable_
+ * value indicates a syntax error.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yyTableValueIsError(int yyvalue) {
+ return yyvalue == yytable_ninf_;
+ }
+
+ private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
+ private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
+
+ ]b4_parser_tables_define[
+
+]b4_parse_trace_if([[
+]b4_integral_parser_table_define([rline], [b4_rline],
+ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
+
+
+ // Report on the debug stream that the rule yyrule is going to be reduced.
+ private void yyReducePrint (int yyrule, YYStack yystack)
+ {
+ if (yydebug == 0) {
+ return;
+ }
+ int yylno = yyrline_[yyrule];
+ int yynrhs = yyr2_[yyrule];
+ /* Print the symbols being reduced, and their result. */
+ yycdebug ("Reducing stack by rule " + (yyrule - 1)
+ + " (line " + yylno + "):");
+
+ /* The symbols being reduced. */
+ // TODO: Use Stringbuilder
+ for (int yyi = 0; yyi < yynrhs; yyi++) {
+ yySymbolPrint(" $" + (yyi + 1) + " =",
+ SymbolKind.get(yystos_[yystack.stateAt(yynrhs - (yyi + 1))]),
+ ]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
+ b4_rhs_location(yynrhs, yyi + 1)])[);
+ }
+ }]])[
+
+ /* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, with out-of-bounds checking. */
+ private static final SymbolKind yytranslate_(int t)
+ ]b4_api_token_raw_if(dnl
+ [[ {
+ return SymbolKind.get(t);
+ }
+]],
+ [[ {
+ // Last valid token kind.
+ int code_max = ]b4_code_max[;
+ if (t <= 0) {
+ return ]b4_symbol(eof, kind)[;
+ }
+ else if (t <= code_max) {
+ return SymbolKind.get(yytranslate_table_[t]);
+ }
+ else {
+ return ]b4_symbol(undef, kind)[;
+ }
+ }
+ ]b4_integral_parser_table_define([translate_table], [b4_translate])[
+]])[
+
+ private static final int YYLAST_ = ]b4_last[;
+ private static final int YYEMPTY_ = -2;
+ private static final int YYFINAL_ = ]b4_final_state_number[;
+ private static final int YYNTOKENS_ = ]b4_tokens_number[;
+
+ ]b4_percent_code_get[
+}
+]b4_percent_code_get([[epilogue]])[]dnl
+b4_epilogue[]dnl
+b4_output_end
diff --git a/antibytes-grammar-tools/flex/FlexKotlinCompatibleSkeleton.skel b/antibytes-grammar-tools/flex/FlexKotlinCompatibleSkeleton.skel
new file mode 100644
index 00000000..7ee5ef4e
--- /dev/null
+++ b/antibytes-grammar-tools/flex/FlexKotlinCompatibleSkeleton.skel
@@ -0,0 +1,360 @@
+
+ /** This character denotes the end of file. */
+ public static final int YYEOF = -1;
+
+ /** Initial size of the lookahead buffer. */
+--- private static final int ZZ_BUFFERSIZE = ...;
+
+ // Lexical states.
+--- lexical states, charmap
+
+ /** Error code for "Unknown internal scanner error". */
+ private static final int ZZ_UNKNOWN_ERROR = 0;
+ /** Error code for "could not match input". */
+ private static final int ZZ_NO_MATCH = 1;
+ /** Error code for "pushback value was too large". */
+ private static final int ZZ_PUSHBACK_2BIG = 2;
+
+ /**
+ * Error messages for {@link #ZZ_UNKNOWN_ERROR}, {@link #ZZ_NO_MATCH}, and
+ * {@link #ZZ_PUSHBACK_2BIG} respectively.
+ */
+ private static final String ZZ_ERROR_MSG[] = {
+ "Unknown internal scanner error",
+ "Error: could not match input",
+ "Error: pushback value was too large"
+ };
+
+--- isFinal list
+ /** Input device. */
+ private java.io.Reader zzReader;
+
+ /** Current state of the DFA. */
+ private int zzState;
+
+ /** Current lexical state. */
+ private int zzLexicalState = YYINITIAL;
+
+ /**
+ * This buffer contains the current text to be matched and is the source of the {@link #yytext()}
+ * string.
+ */
+ private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
+
+ /** Text position at the last accepting state. */
+ private int zzMarkedPos;
+
+ /** Current text position in the buffer. */
+ private int zzCurrentPos;
+
+ /** Marks the beginning of the {@link #yytext()} string in the buffer. */
+ private int zzStartRead;
+
+ /** Marks the last character in the buffer, that has been read from input. */
+ private int zzEndRead;
+
+ /**
+ * Whether the scanner is at the end of file.
+ * @see #yyatEOF
+ */
+ private boolean zzAtEOF;
+
+ /**
+ * The number of occupied positions in {@link #zzBuffer} beyond {@link #zzEndRead}.
+ *
+ * When a lead/high surrogate has been read from the input stream into the final + * {@link #zzBuffer} position, this will have a value of 1; otherwise, it will have a value of 0. + */ + private int zzFinalHighSurrogate = 0; + +--- user class code + +--- constructor declaration + + /** + * Refills the input buffer. + * + * @return {@code false} iff there was new input. + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + + /* first: make room (if you can) */ + if (zzStartRead > 0) { + zzEndRead += zzFinalHighSurrogate; + zzFinalHighSurrogate = 0; + System.arraycopy(zzBuffer, zzStartRead, + zzBuffer, 0, + zzEndRead - zzStartRead); + + /* translate stored positions */ + zzEndRead -= zzStartRead; + zzCurrentPos -= zzStartRead; + zzMarkedPos -= zzStartRead; + zzStartRead = 0; + } + + /* is the buffer big enough? */ + if (zzCurrentPos >= zzBuffer.length - zzFinalHighSurrogate) { + /* if not: blow it up */ + char newBuffer[] = new char[zzBuffer.length * 2]; + System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); + zzBuffer = newBuffer; + zzEndRead += zzFinalHighSurrogate; + zzFinalHighSurrogate = 0; + } + + /* fill the buffer with new input */ + int requested = zzBuffer.length - zzEndRead; + int numRead = zzReader.read(zzBuffer, zzEndRead, requested); + + /* not supposed to occur according to specification of java.io.Reader */ + if (numRead == 0) { + throw new java.io.IOException( + "Reader returned 0 characters. See JFlex examples/zero-reader for a workaround."); + } + if (numRead > 0) { + zzEndRead += numRead; + if (Character.isHighSurrogate(zzBuffer[zzEndRead - 1])) { + if (numRead == requested) { // We requested too few chars to encode a full Unicode character + --zzEndRead; + zzFinalHighSurrogate = 1; + } else { // There is room in the buffer for at least one more char + int c = zzReader.read(); // Expecting to read a paired low surrogate char + if (c == -1) { + return true; + } else { + zzBuffer[zzEndRead++] = (char)c; + } + } + } + /* potentially more input available */ + return false; + } + + /* numRead < 0 ==> end of stream */ + return true; + } + + + /** + * Closes the input reader. + * + * @throws java.io.IOException if the reader could not be closed. + */ + public final void yyclose() throws java.io.IOException { + zzAtEOF = true; // indicate end of file + zzEndRead = zzStartRead; // invalidate buffer + + if (zzReader != null) { + zzReader.close(); + } + } + + + /** + * Resets the scanner to read from a new input stream. + * + *
Does not close the old reader. + * + *
All internal variables are reset, the old input stream cannot be reused (internal + * buffer is discarded and lost). Lexical state is set to {@code ZZ_INITIAL}. + * + *
Internal scan buffer is resized down to its initial length, if it has grown. + * + * @param reader The new input stream. + */ + public final void yyreset(java.io.Reader reader) { + zzReader = reader; + zzEOFDone = false; + yyResetPosition(); + zzLexicalState = YYINITIAL; + if (zzBuffer.length > ZZ_BUFFERSIZE) { + zzBuffer = new char[ZZ_BUFFERSIZE]; + } + } + + /** + * Resets the input position. + */ + private final void yyResetPosition() { + zzAtBOL = true; + zzAtEOF = false; + zzCurrentPos = 0; + zzMarkedPos = 0; + zzStartRead = 0; + zzEndRead = 0; + zzFinalHighSurrogate = 0; + yyline = 0; + yycolumn = 0; + yychar = 0L; + } + + + /** + * Returns whether the scanner has reached the end of the reader it reads from. + * + * @return whether the scanner has reached EOF. + */ + public final boolean yyatEOF() { + return zzAtEOF; + } + + + /** + * Returns the current lexical state. + * + * @return the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + + /** + * Enters a new lexical state. + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + + /** + * Returns the text matched by the current regular expression. + * + * @return the matched text. + */ + public final String yytext() { + return new String(zzBuffer, zzStartRead, zzMarkedPos-zzStartRead); + } + + + /** + * Returns the character at the given position from the matched text. + * + *
It is equivalent to {@code yytext().charAt(pos)}, but faster. + * + * @param position the position of the character to fetch. A value from 0 to {@code yylength()-1}. + * + * @return the character at {@code position}. + */ + public final char yycharat(int position) { + return zzBuffer[zzStartRead + position]; + } + + + /** + * How many characters were matched. + * + * @return the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos-zzStartRead; + } + + + /** + * Reports an error that occurred while scanning. + * + *
In a well-formed scanner (no or only correct usage of {@code yypushback(int)} and a + * match-all fallback rule) this method will only be called with things that + * "Can't Possibly Happen". + * + *
If this method is called, something is seriously wrong (e.g. a JFlex bug producing a faulty + * scanner etc.). + * + *
Usual syntax/scanner level error handling should be done in error fallback rules. + * + * @param errorCode the code of the error message to display. + */ +--- zzScanError declaration + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + +--- throws clause + } + + + /** + * Pushes the specified amount of characters back into the input stream. + * + *
They will be read again by then next call of the scanning method. + * + * @param number the number of characters to be read again. This number must not be greater than + * {@link #yylength()}. + */ +--- yypushback decl (contains zzScanError exception) + if ( number > yylength() ) + zzScanError(ZZ_PUSHBACK_2BIG); + + zzMarkedPos -= number; + } + + +--- zzDoEOF + + + /** + * Resumes scanning until the next regular expression is matched, the end of input is encountered + * or an I/O-Error occurs. + * + * @return the next token. + * @exception java.io.IOException if any I/O-Error occurs. + */ +--- yylex declaration + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + char[] zzBufferL = zzBuffer; + +--- local declarations + + while (true) { + zzMarkedPosL = zzMarkedPos; + +--- start admin (line, char, col count) + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + +--- start admin (lexstate etc) + zzForAction: + while (true) { + +--- next input, line, col, char count, next transition, isFinal action + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; +--- line count update + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; +--- char count update + + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; +--- eofvalue + } + else { +--- actions + default: +--- no match + } + } + } + } + +--- main + +} diff --git a/buildSrc/src/main/kotlin/tech/antibytes/gradle/plugin/script/quality-spotless.gradle.kts b/buildSrc/src/main/kotlin/tech/antibytes/gradle/plugin/script/quality-spotless.gradle.kts index ca4dd42d..fac9e637 100644 --- a/buildSrc/src/main/kotlin/tech/antibytes/gradle/plugin/script/quality-spotless.gradle.kts +++ b/buildSrc/src/main/kotlin/tech/antibytes/gradle/plugin/script/quality-spotless.gradle.kts @@ -41,7 +41,11 @@ val ktlintVersion = "0.42.1" spotless { kotlin { target("**/*.kt") - targetExclude("buildSrc/build/", "**/buildSrc/build/") + targetExclude( + "buildSrc/build/", + "**/buildSrc/build/", + "antibytes-grammar-tools/bison/skeleton/" + ) ktlint(ktlintVersion).userData( mapOf( "disabled_rules" to "no-wildcard-imports", @@ -60,7 +64,14 @@ spotless { endWithNewline() } format("misc") { - target("**/*.adoc", "**/*.md", "**/.gitignore", ".java-version") + target( + "**/*.adoc", + "**/*.md", + "**/.gitignore", + ".java-version", + "**/*.m4", + "**/*.skel", + ) trimTrailingWhitespace() indentWithSpaces()