mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
d: reduce verbosity for returning the location from yylex()
* examples/d/calc/calc.y (start, end): Replace by this... (location): new member variable in the Lexer class. Use it. * tests/calc.at: Use the defined location variable.
This commit is contained in:
committed by
Akim Demaille
parent
ee4ec08513
commit
cc04459cfe
@@ -95,8 +95,7 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
|
||||
this(R r) { input = r; }
|
||||
|
||||
YYPosition start;
|
||||
YYPosition end;
|
||||
YYLocation location;
|
||||
|
||||
// Should be a local in main, shared with %parse-param.
|
||||
int exit_status = 0;
|
||||
@@ -121,13 +120,13 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
// Skip initial spaces
|
||||
while (!input.empty && input.front != '\n' && isWhite(input.front))
|
||||
{
|
||||
start = end;
|
||||
end.column++;
|
||||
location.begin = location.end;
|
||||
location.end.column++;
|
||||
input.popFront;
|
||||
}
|
||||
|
||||
if (input.empty)
|
||||
return Symbol(TokenKind.YYEOF, YYLocation(startPos, endPos));
|
||||
return Symbol(TokenKind.YYEOF, location);
|
||||
|
||||
// Numbers.
|
||||
if (input.front.isNumber)
|
||||
@@ -141,29 +140,29 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
lenChars++;
|
||||
copy.popFront;
|
||||
}
|
||||
start = end;
|
||||
end.column += lenChars;
|
||||
return Symbol(TokenKind.NUM, semanticVal_.ival, YYLocation(startPos, endPos));
|
||||
location.begin = location.end;
|
||||
location.end.column += lenChars;
|
||||
return Symbol(TokenKind.NUM, semanticVal_.ival, location);
|
||||
}
|
||||
|
||||
// Individual characters
|
||||
auto ch = input.front;
|
||||
input.popFront;
|
||||
start = end;
|
||||
end.column++;
|
||||
location.begin = location.end;
|
||||
location.end.column++;
|
||||
switch (ch)
|
||||
{
|
||||
case '+': return Symbol(TokenKind.PLUS, YYLocation(startPos, endPos));
|
||||
case '-': return Symbol(TokenKind.MINUS, YYLocation(startPos, endPos));
|
||||
case '*': return Symbol(TokenKind.STAR, YYLocation(startPos, endPos));
|
||||
case '/': return Symbol(TokenKind.SLASH, YYLocation(startPos, endPos));
|
||||
case '(': return Symbol(TokenKind.LPAR, YYLocation(startPos, endPos));
|
||||
case ')': return Symbol(TokenKind.RPAR, YYLocation(startPos, endPos));
|
||||
case '+': return Symbol(TokenKind.PLUS, location);
|
||||
case '-': return Symbol(TokenKind.MINUS, location);
|
||||
case '*': return Symbol(TokenKind.STAR, location);
|
||||
case '/': return Symbol(TokenKind.SLASH, location);
|
||||
case '(': return Symbol(TokenKind.LPAR, location);
|
||||
case ')': return Symbol(TokenKind.RPAR, location);
|
||||
case '\n':
|
||||
{
|
||||
end.line++;
|
||||
end.column = 1;
|
||||
return Symbol(TokenKind.EOL, YYLocation(startPos, endPos));
|
||||
location.end.line++;
|
||||
location.end.column = 1;
|
||||
return Symbol(TokenKind.EOL, location);
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
@@ -171,12 +170,12 @@ if (isInputRange!R && is(ElementType!R : dchar))
|
||||
|
||||
YYPosition startPos() const
|
||||
{
|
||||
return start;
|
||||
return location.begin;
|
||||
}
|
||||
|
||||
YYPosition endPos() const
|
||||
{
|
||||
return end;
|
||||
return location.end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user