Search in sources :

Example 1 with SourcePosition

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());
        }
    }
}
Also used : SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) Node(de.be4.classicalb.core.parser.node.Node)

Example 2 with SourcePosition

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);
}
Also used : SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) Token(de.be4.classicalb.core.parser.node.Token)

Example 3 with SourcePosition

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) Start(de.be4.classicalb.core.parser.node.Start) SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) BParser(de.be4.classicalb.core.parser.BParser) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 4 with SourcePosition

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);
}
Also used : SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) Test(org.junit.Test)

Example 5 with SourcePosition

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());
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) AAddExpression(de.be4.classicalb.core.parser.node.AAddExpression) Start(de.be4.classicalb.core.parser.node.Start) SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) BParser(de.be4.classicalb.core.parser.BParser) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Aggregations

SourcePosition (de.hhu.stups.sablecc.patch.SourcePosition)7 Test (org.junit.Test)3 BParser (de.be4.classicalb.core.parser.BParser)2 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)2 Node (de.be4.classicalb.core.parser.node.Node)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)2 Start (de.be4.classicalb.core.parser.node.Start)2 Token (de.be4.classicalb.core.parser.node.Token)2 AAddExpression (de.be4.classicalb.core.parser.node.AAddExpression)1