d: create alias Value for YYSemanticType

* data/skeletons/d.m4: Here.
* data/skeletons/lalr1.d, examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust.
* tests/calc.at, tests/d.at, tests/scanner.at: Test it.
This commit is contained in:
Adela Vais
2020-12-18 19:46:02 +02:00
committed by Akim Demaille
parent 8e44b24ba8
commit b00fa62e95
7 changed files with 21 additions and 20 deletions

View File

@@ -454,7 +454,8 @@ m4_define([b4_var_decl],
# Depending on %define token_lex, may be output in the header or source file. # Depending on %define token_lex, may be output in the header or source file.
m4_define([b4_public_types_declare], m4_define([b4_public_types_declare],
[[ [[
alias Symbol = ]b4_parser_class[.Symbol;]b4_locations_if([[ alias Symbol = ]b4_parser_class[.Symbol;
alias Value = ]b4_yystype[;]b4_locations_if([[
alias Location = ]b4_location_type[;]])[ alias Location = ]b4_location_type[;]])[
]]) ]])
@@ -471,7 +472,7 @@ m4_define([b4_symbol_type_define],
struct Symbol struct Symbol
{ {
private SymbolKind kind; private SymbolKind kind;
private ]b4_yystype[ value_;]b4_locations_if([[ private Value value_;]b4_locations_if([[
private Location location_;]])[ private Location location_;]])[
this(TokenKind token]b4_locations_if([[, Location loc]])[) this(TokenKind token]b4_locations_if([[, Location loc]])[)
{ {
@@ -488,7 +489,7 @@ m4_define([b4_symbol_type_define],
} }
} }
SymbolKind token() { return kind; } SymbolKind token() { return kind; }
]b4_yystype[ value() { return value_; }]b4_locations_if([[ Value value() { return value_; }]b4_locations_if([[
Location location() { return location_; }]])[ Location location() { return location_; }]])[
} }
]]) ]])

View File

@@ -68,7 +68,7 @@ public interface Lexer
/** /**
* Method to retrieve the semantic value of the last scanned token. * Method to retrieve the semantic value of the last scanned token.
* @@return the semantic value of the last scanned token. */ * @@return the semantic value of the last scanned token. */
]b4_yystype[ semanticVal (); Value semanticVal ();
/** /**
* Entry point for the scanner. Returns the token identifier corresponding * Entry point for the scanner. Returns the token identifier corresponding
@@ -351,7 +351,7 @@ b4_user_union_members
private int yyaction (int yyn, ref YYStack yystack, int yylen) private int yyaction (int yyn, ref YYStack yystack, int yylen)
{ {
]b4_yystype[ yyval;]b4_locations_if([[ Value yyval;]b4_locations_if([[
]b4_location_type[ yyloc = yylloc_from_stack (yystack, yylen);]])[ ]b4_location_type[ yyloc = yylloc_from_stack (yystack, yylen);]])[
/* If YYLEN is nonzero, implement the default value of the action: /* If YYLEN is nonzero, implement the default value of the action:
@@ -393,7 +393,7 @@ b4_user_union_members
`--------------------------------*/ `--------------------------------*/
private final void yy_symbol_print (string s, SymbolKind yykind, private final void yy_symbol_print (string s, SymbolKind yykind,
ref ]b4_yystype[ yyvaluep]dnl ref Value yyvaluep]dnl
b4_locations_if([, ref ]b4_location_type[ yylocationp])[) b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
{ {
if (0 < yydebug) if (0 < yydebug)
@@ -442,7 +442,7 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
]b4_location_type[ yyloc;]])[ ]b4_location_type[ yyloc;]])[
/// Semantic value of the lookahead. /// Semantic value of the lookahead.
]b4_yystype[ yylval; Value yylval;
bool yyresult;]b4_lac_if([[ bool yyresult;]b4_lac_if([[
// Discard the LAC context in case there still is one left from a // Discard the LAC context in case there still is one left from a
@@ -1088,7 +1088,7 @@ m4_popdef([b4_at_dollar])])dnl
private final struct YYStackElement { private final struct YYStackElement {
int state; int state;
]b4_yystype[ value;]b4_locations_if( Value value;]b4_locations_if(
b4_location_type[[] location;])[ b4_location_type[[] location;])[
} }
@@ -1100,7 +1100,7 @@ m4_popdef([b4_at_dollar])])dnl
return stack.length; return stack.length;
} }
public final void push (int state, ]b4_yystype[ value]dnl public final void push (int state, Value value]dnl
b4_locations_if([, ref ]b4_location_type[ loc])[) b4_locations_if([, ref ]b4_location_type[ loc])[)
{ {
stack ~= YYStackElement(state, value]b4_locations_if([, loc])[); stack ~= YYStackElement(state, value]b4_locations_if([, loc])[);
@@ -1127,7 +1127,7 @@ m4_popdef([b4_at_dollar])])dnl
return stack[$-i-1].location; return stack[$-i-1].location;
}]])[ }]])[
public final ref ]b4_yystype[ valueAt (int i) public final ref Value valueAt (int i)
{ {
return stack[$-i-1].value; return stack[$-i-1].value;
} }

View File

@@ -106,9 +106,9 @@ if (isInputRange!R && is(ElementType!R : dchar))
stderr.writeln(loc.toString(), ": ", s); stderr.writeln(loc.toString(), ": ", s);
} }
YYSemanticType semanticVal_; Value semanticVal_;
public final YYSemanticType semanticVal() public final Value semanticVal()
{ {
return semanticVal_; return semanticVal_;
} }

View File

@@ -102,9 +102,9 @@ if (isInputRange!R && is(ElementType!R : dchar))
stderr.writeln(s); stderr.writeln(s);
} }
YYSemanticType semanticVal_; Value semanticVal_;
public final YYSemanticType semanticVal() public final Value semanticVal()
{ {
return semanticVal_; return semanticVal_;
} }

View File

@@ -559,7 +559,7 @@ class CalcLexer(R) : Lexer
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
YYSemanticType semanticVal_;]AT_LOCATION_IF([[ Value semanticVal_;]AT_LOCATION_IF([[
Location location; Location location;
public final @property YYPosition startPos() public final @property YYPosition startPos()
@@ -572,7 +572,7 @@ class CalcLexer(R) : Lexer
return location.end; return location.end;
} }
]])[ ]])[
public final @property YYSemanticType semanticVal() public final @property Value semanticVal()
{ {
return semanticVal_; return semanticVal_;
} }

View File

@@ -78,8 +78,8 @@ class CalcLexer(R) : Lexer
void yyerror(string s) {} void yyerror(string s) {}
YYSemanticType semanticVal_; Value semanticVal_;
YYSemanticType semanticVal() @property { return semanticVal_; } Value semanticVal() @property { return semanticVal_; }
Symbol yylex() Symbol yylex()
{ {

View File

@@ -115,8 +115,8 @@ class YYLexer(R) : Lexer
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
YYSemanticType semanticVal_; Value semanticVal_;
public final @property YYSemanticType semanticVal () public final @property Value semanticVal ()
{ {
return semanticVal_; return semanticVal_;
} }