Skip to content

Commit 5c554ea

Browse files
adelavaisakimd
authored andcommitted
d: demonstrate the token constructors
* examples/d/calc/calc.y: Use the token constructors in the 'calc' example.
1 parent 7eee2cc commit 5c554ea

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

examples/d/calc/calc.y

+10-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
%define parse.error detailed
2424
%define parse.trace
2525
%define api.push-pull push
26+
%define api.token.constructor
2627

2728
%locations
2829

@@ -122,7 +123,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
122123
location.step();
123124

124125
if (input.empty)
125-
return Symbol(TokenKind.YYEOF, location);
126+
return Symbol.YYEOF(location);
126127

127128
// Numbers.
128129
if (input.front.isNumber)
@@ -149,7 +150,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
149150
copy.popFront;
150151
}
151152
}
152-
return Symbol(TokenKind.NUM, ival, location);
153+
return Symbol.NUM(ival, location);
153154
}
154155

155156
// Individual characters
@@ -158,17 +159,17 @@ if (isInputRange!R && is(ElementType!R : dchar))
158159
location.end.column++;
159160
switch (ch)
160161
{
161-
case '+': return Symbol(TokenKind.PLUS, location);
162-
case '-': return Symbol(TokenKind.MINUS, location);
163-
case '*': return Symbol(TokenKind.STAR, location);
164-
case '/': return Symbol(TokenKind.SLASH, location);
165-
case '(': return Symbol(TokenKind.LPAR, location);
166-
case ')': return Symbol(TokenKind.RPAR, location);
162+
case '+': return Symbol.PLUS(location);
163+
case '-': return Symbol.MINUS(location);
164+
case '*': return Symbol.STAR(location);
165+
case '/': return Symbol.SLASH(location);
166+
case '(': return Symbol.LPAR(location);
167+
case ')': return Symbol.RPAR(location);
167168
case '\n':
168169
{
169170
location.end.line++;
170171
location.end.column = 1;
171-
return Symbol(TokenKind.EOL, location);
172+
return Symbol.EOL(location);
172173
}
173174
default: assert(0);
174175
}

0 commit comments

Comments
 (0)