use of de.hhu.stups.sablecc.patch.SourcePosition in project probparsers by bendisposto.
the class MissingPositionsAdder method defaultIn.
public void defaultIn(Node node) {
SourcePosition startPos = node.getStartPos();
if (startPos == null) {
Node parent = node.parent();
if (parent != null && parent.getStartPos() != null) {
node.setStartPos(parent.getStartPos());
node.setEndPos(parent.getEndPos());
}
}
}
use of de.hhu.stups.sablecc.patch.SourcePosition in project probparsers by bendisposto.
the class PrologExceptionPrinter method printBLexerException.
private static void printBLexerException(final IPrologTermOutput pto, final BLexerException e, final String filename, final boolean useIndentation, final boolean lineOneOff) {
final Token token = e.getLastToken();
final SourcePosition pos = token == null ? null : new SourcePosition(token.getLine(), token.getPos());
printExceptionWithSourcePosition(pto, e, filename, pos, useIndentation, lineOneOff);
}
use of de.hhu.stups.sablecc.patch.SourcePosition in project probparsers by bendisposto.
the class PositionAspectTest method testSimpleNode.
@Test
public void testSimpleNode() throws Exception {
final String testMachine = "#EXPRESSION x";
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
final SourcePosition startPos = expression.getStartPos();
final SourcePosition endPos = expression.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(14, endPos.getPos());
}
use of de.hhu.stups.sablecc.patch.SourcePosition in project probparsers by bendisposto.
the class SourcePositionCompareTest method test.
@Test
public void test() {
SourcePosition p1 = new SourcePosition(1, 5);
SourcePosition p2 = new SourcePosition(2, 10);
SourcePosition p3 = new SourcePosition(3, 1);
SourcePosition p4 = new SourcePosition(3, 11);
assertTrue(p1.compareTo(p1) == 0);
assertTrue(p1.compareTo(p2) < 0);
assertTrue(p2.compareTo(p1) > 0);
assertTrue(p1.compareTo(p3) < 0);
assertTrue(p1.compareTo(p4) < 0);
assertTrue(p2.compareTo(p3) < 0);
assertTrue(p2.compareTo(p4) < 0);
assertTrue(p3.compareTo(p4) < 0);
}
use of de.hhu.stups.sablecc.patch.SourcePosition in project probparsers by bendisposto.
the class PositionAspectTest method testComposedNode.
@Test
public void testComposedNode() throws Exception {
final String testMachine = "#EXPRESSION x+1";
final BParser parser = new BParser("testcase");
final Start startNode = parser.parse(testMachine, true);
// test top node
final PExpression expression = ((AExpressionParseUnit) startNode.getPParseUnit()).getExpression();
SourcePosition startPos = expression.getStartPos();
SourcePosition endPos = expression.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
// test left child: 13-14
final PExpression leftExpr = ((AAddExpression) expression).getLeft();
startPos = leftExpr.getStartPos();
endPos = leftExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(13, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(14, endPos.getPos());
// test right child: 15-16
final PExpression rightExpr = ((AAddExpression) expression).getRight();
startPos = rightExpr.getStartPos();
endPos = rightExpr.getEndPos();
assertNotNull(startNode);
assertNotNull(endPos);
assertEquals(1, startPos.getLine());
assertEquals(15, startPos.getPos());
assertEquals(1, endPos.getLine());
assertEquals(16, endPos.getPos());
}
Aggregations