Search in sources :

Example 11 with Parser

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

the class StructuralTest method testConstantsClause.

@Test
public void testConstantsClause() throws Exception {
    final String testMachine = "MACHINE SimplyStructure\nCONSTANTS dd, e, Ff\nPROPERTIES dd : BOOL\nEND";
    // System.out.println("Parsing: \"" + testMachine + "\":");
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, false);
    assertNotNull(startNode);
// TODO more tests
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Test(org.junit.Test)

Example 12 with Parser

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

the class StructuralTest method testClausesStructure.

@Test
public void testClausesStructure() throws Exception {
    final String testMachine = "MACHINE SimplyStructure\n" + "VARIABLES aa, b, Cc\n" + "INVARIANT aa : NAT\n" + "INITIALISATION aa:=1\n" + "CONSTANTS dd, e, Ff\n" + "PROPERTIES dd : NAT\n" + "SETS GGG; Hhh; JJ = {dada, dudu, TUTUT}; iII; kkk = {LLL}\nEND";
    // System.out.println("Parsing: \"" + testMachine + "\":");
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, true);
    assertNotNull(startNode);
// TODO more tests
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Test(org.junit.Test)

Example 13 with Parser

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

the class UnparsableMachineTest method testParsable.

@Test(expected = BCompoundException.class)
public void testParsable() throws Exception {
    final BParser parser = new BParser(machine.getName());
    Start start = parser.parseFile(machine, false);
    assertNotNull(start);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) AbstractParseMachineTest(util.AbstractParseMachineTest) Test(org.junit.Test)

Example 14 with Parser

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

the class Ticket295 method ticker295.

// #x. /* comment */ (x>1000 & x<2**10)
@Test
public void ticker295() throws Exception {
    // String input = "#FORMULA #x. /* comment */ (x>1000 & x<2**10)";
    String input1 = "#FORMULA #x. /*buh */ (  x>1000 & x<2**10)";
    String input2 = "#FORMULA #x.(/*buh */ x>1000 & x<2**10)";
    DefinitionTypes defTypes1 = new DefinitionTypes();
    final BLexer lexer1 = new BLexer(new PushbackReader(new StringReader(input1), 99), defTypes1, input1.length());
    DefinitionTypes defTypes2 = new DefinitionTypes();
    final BLexer lexer2 = new BLexer(new PushbackReader(new StringReader(input2), 99), defTypes2, input2.length());
    Parser parser1 = new Parser(lexer1);
    Parser parser2 = new Parser(lexer2);
    final Start rootNode1 = parser1.parse();
    final Start rootNode2 = parser2.parse();
    final String result1 = getTreeAsString(rootNode1);
    final String result2 = getTreeAsString(rootNode2);
    assertNotNull(rootNode1);
    assertNotNull(rootNode2);
    assertEquals(result1, result2);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) StringReader(java.io.StringReader) Ast2String(util.Ast2String) PushbackReader(java.io.PushbackReader) Parser(de.be4.classicalb.core.parser.parser.Parser) Test(org.junit.Test)

Example 15 with Parser

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

the class DefinitionsErrorsTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException {
    // System.out.println("Parsing: \"" + testMachine + "\":");
    final BParser parser = new BParser("testcase");
    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();
    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)

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