Search in sources :

Example 26 with Parser

use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.

the class FilePragmaTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    // System.out.println("Parsing \"" + testMachine + "\"");
    final BParser parser = new BParser("testcase");
    parser.getOptions().setGrammar(RulesGrammar.getInstance());
    final Start startNode = parser.parse(testMachine, false);
    // startNode.apply(new ASTPrinter());
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    final String string = ast2String.toString();
    // System.out.println(string);
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 27 with Parser

use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.

the class ParseTestUtil method parse.

private static String parse(final String input) throws BCompoundException {
    final BParser parser = new BParser();
    final Start ast = parser.parse(input, false);
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    return ast2String.toString();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String)

Example 28 with Parser

use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.

the class PositionAspectTest method testHasGetMethods.

@Test
public void testHasGetMethods() throws Exception {
    final String testMachine = "#EXPRESSION 1+2";
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, true);
    startNode.getStartPos();
    startNode.getEndPos();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 29 with Parser

use of de.be4.eventb.core.parser.parser.Parser 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 30 with Parser

use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.

the class DefinitionFilesTest method testCircleReference.

/*
	 * test circles references between def files
	 */
@Test
public void testCircleReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile3\"\nEND";
    final BParser parser = new BParser("testcase");
    try {
        parser.parse(testMachine, false, this);
        fail("Expected PreParseException missing");
    } catch (final BCompoundException e) {
        assertTrue(e.getCause() instanceof PreParseException);
    }
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)51 BParser (de.be4.classicalb.core.parser.BParser)41 Test (org.junit.Test)31 Ast2String (util.Ast2String)20 File (java.io.File)15 IOException (java.io.IOException)13 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)10 StringReader (java.io.StringReader)9 PushbackReader (java.io.PushbackReader)8 AbstractParseMachineTest (util.AbstractParseMachineTest)7 PrintStream (java.io.PrintStream)6 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)4 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)4 Reader (java.io.Reader)4 ArrayList (java.util.ArrayList)4 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3 Start (de.be4.eventbalg.core.parser.node.Start)3 LtlParseException (de.be4.ltl.core.parser.LtlParseException)3