mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
java: tests: check location tracking in the calculator
Unfortunately in the Java skeleton the user cannot override the way locations are displayed, and locations don't know the structure of the positions. So they cannot implement the tricks used in the C/C++ skeletons to display "1.1" instead of "1.1-1.2". * tests/local.at (Java): Add support for column tracking in the locations, as we did in examples/java/calc. * tests/calc.at: Use AT_CALC_YYLEX.
This commit is contained in:
@@ -832,39 +832,78 @@ m4_define([AT_YYERROR_DECLARE_EXTERN(java)], [])
|
||||
# -----------------------
|
||||
m4_define([AT_JAVA_POSITION_DEFINE],
|
||||
[[class Position {
|
||||
public int line;
|
||||
public int token;
|
||||
public int line = 1;
|
||||
public int column = 1;
|
||||
|
||||
public Position ()
|
||||
{
|
||||
line = 0;
|
||||
token = 0;
|
||||
line = 1;
|
||||
column = 1;
|
||||
}
|
||||
|
||||
public Position (int l, int t)
|
||||
{
|
||||
line = l;
|
||||
token = t;
|
||||
column = t;
|
||||
}
|
||||
|
||||
public void set (Position p)
|
||||
{
|
||||
line = p.line;
|
||||
column = p.column;
|
||||
}
|
||||
|
||||
public boolean equals (Position l)
|
||||
{
|
||||
return l.line == line && l.token == token;
|
||||
return l.line == line && l.column == column;
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return Integer.toString (line) + "." + Integer.toString (token);
|
||||
return Integer.toString (line) + "." + Integer.toString (column);
|
||||
}
|
||||
|
||||
public int lineno ()
|
||||
public int line ()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
public int token ()
|
||||
public int column ()
|
||||
{
|
||||
return token;
|
||||
return column;
|
||||
}
|
||||
}
|
||||
|
||||
class PositionReader extends BufferedReader {
|
||||
|
||||
private Position position = new Position ();
|
||||
private Position previousPosition = new Position ();
|
||||
|
||||
public PositionReader (Reader reader) {
|
||||
super (reader);
|
||||
}
|
||||
|
||||
public int read () throws IOException {
|
||||
int res = super.read ();
|
||||
previousPosition.set (position);
|
||||
if (res > -1) {
|
||||
char c = (char)res;
|
||||
if (c == '\r' || c == '\n') {
|
||||
position.line += 1;
|
||||
position.column = 1;
|
||||
} else {
|
||||
position.column += 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Position getPosition () {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Position getPreviousPosition () {
|
||||
return previousPosition;
|
||||
}
|
||||
}]])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user