Search in sources :

Example 31 with Parser

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

the class DefinitionFilesTest method testNonCircleReference.

/*
	 * test circles references between def files
	 */
@Test
public void testNonCircleReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile5\";\n\"DefFile6\"\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, false, this);
}
Also used : BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 32 with Parser

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

the class DefinitionFilesTest method testRecursiveReference.

// TODO test two files
/*
	 * test recursive references from def file to def file
	 */
@Test
public void testRecursiveReference() throws Exception {
    final String testMachine = "MACHINE Test\nDEFINITIONS \"DefFile1\"; def1 == xx; def02 == aa\nEND";
    final BParser parser = new BParser("testcase");
    parser.parse(testMachine, false, this);
    final IDefinitions definitions = parser.getDefinitions();
    final AExpressionDefinitionDefinition def1 = (AExpressionDefinitionDefinition) definitions.getDefinition("def1");
    assertEquals("def1", def1.getName().getText());
    assertEquals(0, def1.getParameters().size());
    assertTrue(def1.getRhs() instanceof AIdentifierExpression);
    String ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def1.getRhs()).getIdentifier());
    assertEquals("xx", ident);
    final AExpressionDefinitionDefinition def2 = (AExpressionDefinitionDefinition) definitions.getDefinition("def2");
    assertEquals("def2", def2.getName().getText());
    assertEquals(0, def2.getParameters().size());
    assertTrue(def2.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def2.getRhs()).getIdentifier());
    assertEquals("yy", ident);
    final AExpressionDefinitionDefinition def3 = (AExpressionDefinitionDefinition) definitions.getDefinition("def3");
    assertEquals("def3", def3.getName().getText());
    assertEquals(0, def3.getParameters().size());
    assertTrue(def3.getRhs() instanceof AIdentifierExpression);
    ident = Utils.getTIdentifierListAsString(((AIdentifierExpression) def3.getRhs()).getIdentifier());
    // definition in outer def file should overwrite the one in referenced
    // def file
    assertEquals("bb", ident);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) IDefinitions(de.be4.classicalb.core.parser.IDefinitions) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 33 with Parser

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

the class DefinitionsOrderTest method testReordered.

@Test
public void testReordered() throws IOException, BCompoundException {
    machine = new File(PATH + "DefinitionsOccurReordered.mch");
    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) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) Test(org.junit.Test)

Example 34 with Parser

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

the class CtlParser method parseFormula.

protected Start parseFormula(final String formula) throws LtlParseException, IOException {
    StringReader reader = new StringReader(formula);
    PushbackReader r = new PushbackReader(reader);
    Lexer l = new CtlLexer(r);
    Parser p = new Parser(l);
    Start ast = null;
    try {
        ast = p.parse();
    } catch (ParserException e) {
        final UniversalToken token = UniversalToken.createToken(e.getToken());
        throw new LtlParseException(token, e.getLocalizedMessage());
    } catch (LexerException e) {
        throw new LtlParseException(null, e.getLocalizedMessage());
    }
    return ast;
}
Also used : ParserException(de.be4.ltl.core.ctlparser.parser.ParserException) CtlLexer(de.be4.ltl.core.parser.internal.CtlLexer) Lexer(de.be4.ltl.core.ctlparser.lexer.Lexer) UniversalToken(de.be4.ltl.core.parser.internal.UniversalToken) Start(de.be4.ltl.core.ctlparser.node.Start) StringReader(java.io.StringReader) CtlLexer(de.be4.ltl.core.parser.internal.CtlLexer) LexerException(de.be4.ltl.core.ctlparser.lexer.LexerException) PushbackReader(java.io.PushbackReader) Parser(de.be4.ltl.core.ctlparser.parser.Parser)

Example 35 with Parser

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

the class ErrorMessagesTest 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)

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