From 94701b4e5e18b742191c1dd59c384cb011d3ea6e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 26 Dec 2020 11:24:57 +0100 Subject: [PATCH] style: rename semanticVal as value * data/skeletons/README-D.txt: Remove, now useless and obsolete. * data/skeletons/glr2.cc, examples/d/calc/calc.y, * tests/calc.at, tests/d.at, tests/scanner.at (semanticVal): Replace with... (value): this. --- TODO | 2 +- data/local.mk | 1 - data/skeletons/README-D.txt | 60 ------------------------------------- data/skeletons/glr2.cc | 28 ++++++++--------- examples/d/calc/calc.y | 6 ++-- tests/calc.at | 6 ++-- tests/d.at | 2 -- tests/scanner.at | 6 ++-- 8 files changed, 24 insertions(+), 87 deletions(-) delete mode 100644 data/skeletons/README-D.txt diff --git a/TODO b/TODO index 90ecea33..db73ace8 100644 --- a/TODO +++ b/TODO @@ -786,7 +786,7 @@ Equip the parser with a means to create the (visual) parse tree. # LocalWords: nterm bitsetv ielr ritem nstates nrules nritems yysymbol EQ # LocalWords: SymbolKind YYEMPTY YYUNDEF YYTNAME NUM yyntokens yytname sed # LocalWords: nonterminals yykind yycode YYNAMES yynames init getName conv -# LocalWords: TokenKind semanticVal ival yychar yylval yylexer Tolmer hoc +# LocalWords: TokenKind ival yychar yylval yylexer Tolmer hoc # LocalWords: Sobisch YYPTRDIFF ptrdiff Autotest YYPRINT toknum yytoknum # LocalWords: sym Wother stderr FP fixits xgettext fdiagnostics Graphviz # LocalWords: graphviz VCG bitset xml bw maint yytoken YYABORT deps diff --git a/data/local.mk b/data/local.mk index 1ad9d235..3ead3af9 100644 --- a/data/local.mk +++ b/data/local.mk @@ -41,7 +41,6 @@ dist_skeletons_DATA = \ # Experimental support for the D language. dist_skeletons_DATA += \ - data/skeletons/README-D.txt \ data/skeletons/d-skel.m4 \ data/skeletons/d.m4 \ data/skeletons/lalr1.d diff --git a/data/skeletons/README-D.txt b/data/skeletons/README-D.txt deleted file mode 100644 index e6068b4e..00000000 --- a/data/skeletons/README-D.txt +++ /dev/null @@ -1,60 +0,0 @@ -Some usage notes for the D Parser: - -- it is a port of the Java parser, so interface is very similar. - -- the lexer class needs to implement the interface 'Lexer' (similar to - java). It typically (depending on options) looks like this: - -public interface Lexer -{ - /** - * Method to retrieve the beginning position of the last scanned token. - * @return the position at which the last scanned token starts. */ - @property YYPosition startPos (); - - /** - * Method to retrieve the ending position of the last scanned token. - * @return the first position beyond the last scanned token. */ - @property YYPosition endPos (); - - /** - * Method to retrieve the semantic value of the last scanned token. - * @return the semantic value of the last scanned token. */ - @property YYSemanticType semanticVal (); - - /** - * Entry point for the scanner. Returns the token identifier corresponding - * to the next token and prepares to return the semantic value - * and beginning/ending positions of the token. - * @return the token identifier corresponding to the next token. */ - TokenKind yylex (); - - /** - * Entry point for error reporting. Emits an error - * referring to the given location in a user-defined way. - * - * @param loc The location of the element to which the - * error message is related - * @param s The string for the error message. */ - void yyerror (YYLocation loc, string s); -} - -- semantic types are handled by D unions (same as for C/C++ parsers) - -- the following (non-standard) %defines are supported: - - %define package "" - %define api.parser.class "my_class_name>" - %define position_type "my_position_type" - %define location_type "my_location_type" - -- the following declarations basically work like in C/C++: - - %locations - %error-verbose - %parse-param - %initial-action - %code - %union - -- %destructor is not yet supported diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 04d76dcc..00adae89 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -344,7 +344,7 @@ m4_define([b4_rhs_data], # -------------------------------------------------- # Expansion of $$ or $$, for symbol SYMBOL-NUM. m4_define([b4_rhs_value], -[b4_symbol_value([b4_rhs_data([$1], [$2]).semanticVal()], [$3], [$4])]) +[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])]) @@ -767,7 +767,7 @@ public: { setPred (other.pred ()); if (other.yyresolved) - new (&yysval) value_type (other.semanticVal ()); + new (&yysval) value_type (other.value ()); else setFirstVal (other.firstVal ());]b4_parse_assert_if([[ check_();]])[ @@ -792,7 +792,7 @@ public: yyposn = other.yyposn; setPred (other.pred ()); if (other.yyresolved) - semanticVal () = other.semanticVal (); + value () = other.value (); else setFirstVal (other.firstVal ());]b4_locations_if([[ yyloc = other.yyloc;]])[ @@ -818,13 +818,13 @@ public: const semantic_option* firstVal () const; void setFirstVal (const semantic_option* option); - value_type& semanticVal () + value_type& value () {]b4_parse_assert_if([[ check_ ();]])[ return yysval; } - const value_type& semanticVal () const + const value_type& value () const {]b4_parse_assert_if([[ check_ ();]])[ return yysval; @@ -1119,12 +1119,12 @@ public: else if (yys0->yyresolved) { yys1->yyresolved = true; - yys1->semanticVal() = yys0->semanticVal(); + yys1->value () = yys0->value (); } else if (yys1->yyresolved) { yys0->yyresolved = true; - yys0->semanticVal() = yys1->semanticVal(); + yys0->value () = yys1->value (); } else { @@ -1407,7 +1407,7 @@ void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class check_ ();]])[ if (yyresolved) yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState), - &semanticVal()]b4_locations_if([, &yyloc])[); + &value ()]b4_locations_if([, &yyloc])[); else { YY_SYMBOL_PRINT (yymsg << (firstVal() ? " unresolved" : " incomplete"), @@ -1700,10 +1700,10 @@ public: #endif yys.yyresolved = s->yyresolved; if (s->yyresolved) - new (&yys.semanticVal ()) value_type (s->semanticVal ()); + new (&yys.value ()) value_type (s->value ()); else - /* The effect of using semanticVal or yyloc (in an immediate rule) is - * undefined. */ + /* The effect of using yysval or yyloc (in an immediate + * rule) is undefined. */ yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[ yys.yyloc = s->yyloc;]])[ yys.setPred(s->pred()); @@ -1740,7 +1740,7 @@ public: std::cerr << " $" << yyi + 1 << " = "; yyparser.yy_symbol_print_ (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState), - &yyvsp[yyi - yynrhs + 1].getState().semanticVal()]b4_locations_if([[, + &yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[, &]b4_rhs_location(yynrhs, yyi + 1)])[); if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved) std::cerr << " (unresolved)"; @@ -2296,7 +2296,7 @@ public: if (yyrhslen == 0) *yyvalp = yyval_default; else - *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().semanticVal();]b4_locations_if([[ + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]b4_locations_if([[ /* Default location. */ YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); yyerror_range[1].getState().yyloc = *yylocp; @@ -2657,7 +2657,7 @@ private: { yys.yyresolved = true; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - new (&yys.semanticVal ()) value_type (yysval); + new (&yys.value ()) value_type (yysval); YY_IGNORE_MAYBE_UNINITIALIZED_END } else diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y index 2c79c158..572b10b6 100644 --- a/examples/d/calc/calc.y +++ b/examples/d/calc/calc.y @@ -106,7 +106,7 @@ if (isInputRange!R && is(ElementType!R : dchar)) stderr.writeln(loc.toString(), ": ", s); } - Value semanticVal_; + Value value_; Symbol yylex() { @@ -129,7 +129,7 @@ if (isInputRange!R && is(ElementType!R : dchar)) int lenChars = 0; auto copy = input; import std.conv : parse; - semanticVal_.ival = input.parse!int; + value_.ival = input.parse!int; while (!input.empty && copy.front != input.front) { lenChars++; @@ -137,7 +137,7 @@ if (isInputRange!R && is(ElementType!R : dchar)) } location.begin = location.end; location.end.column += lenChars; - return Symbol(TokenKind.NUM, semanticVal_.ival, location); + return Symbol(TokenKind.NUM, value_.ival, location); } // Individual characters diff --git a/tests/calc.at b/tests/calc.at index 85f95fca..b1428316 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -563,7 +563,7 @@ class CalcLexer(R) : Lexer ]AT_YYERROR_DEFINE[ - Value semanticVal_;]AT_LOCATION_IF([[ + Value value_;]AT_LOCATION_IF([[ Location location; ]])[ int parseInt () @@ -600,8 +600,8 @@ class CalcLexer(R) : Lexer // Numbers. if (input.front.isNumber) { - semanticVal_.ival = parseInt; - return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, semanticVal_.ival]AT_LOCATION_IF([[, location]])[); + value_.ival = parseInt; + return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, value_.ival]AT_LOCATION_IF([[, location]])[); } // Individual characters diff --git a/tests/d.at b/tests/d.at index f268b820..869824fe 100644 --- a/tests/d.at +++ b/tests/d.at @@ -78,8 +78,6 @@ class CalcLexer(R) : Lexer void yyerror(string s) {} - Value semanticVal_; - Symbol yylex() { $2 diff --git a/tests/scanner.at b/tests/scanner.at index 46a20116..023e2791 100644 --- a/tests/scanner.at +++ b/tests/scanner.at @@ -115,7 +115,7 @@ class YYLexer(R) : Lexer ]AT_YYERROR_DEFINE[ - Value semanticVal_; + Value value_; Symbol yylex () { @@ -131,8 +131,8 @@ class YYLexer(R) : Lexer switch (c) { case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - semanticVal_.val = c - '0'; - return Symbol(TokenKind.NUM, semanticVal_.val); + value_.val = c - '0'; + return Symbol(TokenKind.NUM, value_.val); case '+': return Symbol(TokenKind.PLUS); case '-': return Symbol(TokenKind.MINUS); case '*': return Symbol(TokenKind.STAR);