Search in sources :

Example 16 with Parser

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

the class PushbackBufferOverflows method withoutPredVars.

@Test
public void withoutPredVars() throws Exception {
    String source = "#PREDICATE procs : STRING +-> {\"waiting\",\"ready\"} & current : STRING & idle : {TRUE,FALSE} & idle = FALSE & procs /= { } & { \"waiting\" } /= { } & { \"waiting\" } /\\ ran(procs) = { } & { \"ready\" } = ran(procs)";
    BParser parser = new BParser();
    Start result = parser.parse(source, false);
    assertNotNull(result);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 17 with Parser

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

the class PushbackBufferOverflows method withPredVars.

@Test
public void withPredVars() throws Exception {
    String source = "#PREDICATE procs : STRING +-> {\"waiting\",\"ready\"} & current : STRING & idle : {TRUE,FALSE} & idle = FALSE & procs /= { } & { \"waiting\" } /= { } & { \"waiting\" } /\\ ran(procs) = { } & { \"ready\" } = ran(procs)";
    BParser parser = new BParser();
    Start result = parser.eparse(source, new MockedDefinitions());
    assertNotNull(result);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) MockedDefinitions(de.be4.classicalb.core.parser.MockedDefinitions) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 18 with Parser

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

the class Helpers method parseFile2.

public static String parseFile2(String filename) throws IOException {
    final File machineFile = new File(filename);
    final BParser parser = new BParser(machineFile.getAbsolutePath());
    Start tree;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    try {
        tree = parser.parseFile(machineFile, false);
        PrintStream printStream = new PrintStream(output);
        BParser.printASTasProlog(printStream, parser, machineFile, tree, new ParsingBehaviour(), parser.getContentProvider());
        output.close();
        return output.toString();
    } catch (BCompoundException e) {
        e.printStackTrace();
        PrologExceptionPrinter.printException(output, e);
        return output.toString();
    }
}
Also used : PrintStream(java.io.PrintStream) Start(de.be4.classicalb.core.parser.node.Start) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 19 with Parser

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

the class Helpers method getMachineAsPrologTerm.

public static String getMachineAsPrologTerm(String input) {
    final BParser parser = new BParser("Test");
    Start start;
    try {
        start = parser.parse(input, true);
    } catch (BCompoundException e) {
        throw new RuntimeException(e);
    }
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    final IPrologTermOutput pout = new PrologTermOutput(output, false);
    printAsProlog(start, pout);
    return output.toString();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput)

Example 20 with Parser

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

the class CliBParser method parseTemporalFormula.

private static void parseTemporalFormula(BufferedReader in, final TemporalLogicParser<?> parser) throws IOException {
    String theFormula;
    PrologTermStringOutput strOutput = new PrologTermStringOutput();
    theFormula = in.readLine();
    try {
        final PrologTerm term = parser.generatePrologTerm(theFormula, null);
        strOutput.openTerm("ltl").printTerm(term).closeTerm();
    } catch (LtlParseException e) {
        strOutput.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
    }
    strOutput.fullstop();
    // A Friendly Reminder: strOutput includes a newline!
    print(strOutput.toString());
}
Also used : PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) PrologTerm(de.prob.prolog.term.PrologTerm) LtlParseException(de.be4.ltl.core.parser.LtlParseException)

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