Search in sources :

Example 96 with BCompoundException

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

the class StringLiteralNotClosedTest method testStringLiteralNotClosedShortString.

@Test
public void testStringLiteralNotClosedShortString() {
    final String testMachine = "MACHINE Test CONSTANTS the_string PROPERTIES the_string = \"not closed END";
    try {
        getTreeAsString(testMachine);
        fail("Exception did not occur");
    } catch (BCompoundException e) {
        assertEquals("[1,59] Unknown token: \"not closed END", e.getMessage());
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 97 with BCompoundException

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

the class StringLiteralNotClosedTest 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) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 98 with BCompoundException

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

the class SatProblem method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
    final BParser parser = new BParser("testcase");
    Start ast = parser.eparse(testMachine, new Definitions());
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    final String string = ast2String.toString();
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Definitions(de.be4.classicalb.core.parser.Definitions) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 99 with BCompoundException

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

the class Test1002 method file2.

@Test
public void file2() throws BCompoundException {
    String source = " clients : STRING +-> STRING & balances : STRING +-> NATURAL & owners : STRING <-> STRING & u : STRING & n : STRING & m : NATURAL & m > balances(n) & m < 100000";
    Start result = BParser.parse(BParser.FORMULA_PREFIX + "" + source);
    assertNotNull(result);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Test(org.junit.Test)

Example 100 with BCompoundException

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

the class Test1002 method file3.

@Test
public void file3() throws BCompoundException {
    String source = "srv : {\"HS\",\"SC\",\"COM\",\"VOM\",\"SDA\",\"RDA\",\"TD\",\"RA\",\"GMR\",\"LDM\",\"EP\",\"MSP\"} & om : {\"SAFETY\",\"NOM\",\"DIAG\"} & acquiring : {TRUE,FALSE} & prepData : {TRUE,FALSE} & prepDataType : {\"SD\",\"HD\",\"MD\"} & page : NATURAL & ia : NATURAL & fa : NATURAL & lpck : seq(STRING) & lpckDT : {\"CR\",\"CD\",\"OM\",\"ND\",\"ASD\",\"AMD\",\"MSE\",\"ICS\",\"LS\"} & csrs : {\"SD\",\"HD\",\"MD\"} --> NATURAL & totCSR : {\"SD\",\"HD\",\"MD\"} --> NATURAL & csc : NATURAL & mem : 1 .. 1024 --> STRING & modMem : POW(NATURAL) & sdwp : NATURAL & sparam : {\"HGT\",\"ILP\",\"AICST\"} --> NATURAL & time : NATURAL & processingCmd : {TRUE,FALSE} & iain : NATURAL & data : seq(STRING) & c : NATURAL & processingCmd = TRUE & srv = \"LDM\" & om = \"NOM\" & csc > 0 & c = csc - 1 & sparam(\"ILP\") <= iain & iain + card(data) : 0 .. 32 & {x | x-iain:dom(data)} /\\ modMem = { } & {x | x-iain:dom(data)} /= { } & modMem = { }";
    Start result = BParser.parse(BParser.FORMULA_PREFIX + "" + source);
    assertNotNull(result);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Test(org.junit.Test)

Aggregations

BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)73 Test (org.junit.Test)64 Ast2String (util.Ast2String)62 Start (de.be4.classicalb.core.parser.node.Start)52 BParser (de.be4.classicalb.core.parser.BParser)29 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)19 File (java.io.File)15 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)7 BException (de.be4.classicalb.core.parser.exceptions.BException)7 Helpers.getTreeAsString (util.Helpers.getTreeAsString)7 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)5 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)5 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 Node (de.be4.classicalb.core.parser.node.Node)5 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)4 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)4