Search in sources :

Example 31 with BParser

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

the class SatProblem method getTreeAsStringOrg.

private String getTreeAsStringOrg(final String testMachine) throws BCompoundException {
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, false);
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    final String string = ast2String.toString();
    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 32 with BParser

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

the class PredVarsTest method getTreeAsStringOrg.

private String getTreeAsStringOrg(final String testMachine) throws BCompoundException {
    final BParser parser = new BParser("testcase");
    final Start startNode = parser.parse(testMachine, false);
    final Ast2String ast2String = new Ast2String();
    startNode.apply(ast2String);
    final String string = ast2String.toString();
    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 33 with BParser

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

the class ClassicalBParser method parsePredicate.

@Override
public void parsePredicate(final IPrologTermOutput pto, final String predicate, final boolean wrap) throws ProBParseException {
    try {
        Start ast = new BParser().parsePredicate(predicate);
        printAst(pto, ast, wrap, WRAPPER_PRED);
    } catch (BCompoundException e) {
        throw new ProBParseException(e.getFirstException().getLocalizedMessage());
    }
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ProBParseException(de.prob.parserbase.ProBParseException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 34 with BParser

use of de.be4.classicalb.core.parser.BParser in project prob2 by bendisposto.

the class TLAFactory method parseAllMachines.

/**
 * Given an {@link Start} ast, {@link File} f, and {@link BParser} bparser,
 * all machines are loaded.
 *
 * @param ast
 *            {@link Start} representing the abstract syntax tree for the
 *            machine
 * @param f
 *            {@link File} containing machine
 * @param bparser
 *            {@link BParser} for parsing
 * @return {@link RecursiveMachineLoader} rml with all loaded machines
 * @throws BCompoundException if the machines could not be loaded
 */
public RecursiveMachineLoader parseAllMachines(final Start ast, final File f, final BParser bparser) throws BCompoundException {
    final RecursiveMachineLoader rml = new RecursiveMachineLoader(f.getParent(), bparser.getContentProvider());
    rml.loadAllMachines(f, ast, bparser.getDefinitions());
    logger.trace("Done parsing '{}'", f.getAbsolutePath());
    return rml;
}
Also used : RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)

Example 35 with BParser

use of de.be4.classicalb.core.parser.BParser in project prob2 by bendisposto.

the class TLAFactory method parseFile.

/**
 * Parse a file into an AST {@link Start}.
 *
 * @param model
 *            {@link File} containing B machine
 * @param bparser
 *            {@link BParser} for parsing
 * @return {@link Start} AST after parsing model with {@link BParser}
 *         bparser
 * @throws IOException if an I/O error occurred
 * @throws BCompoundException if the file could not be parsed
 */
public Start parseFile(final File model, final BParser bparser) throws IOException, BCompoundException {
    logger.trace("Parsing main file '{}'", model.getAbsolutePath());
    Start ast = null;
    ast = bparser.parseFile(model, false);
    return ast;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)63 BParser (de.be4.classicalb.core.parser.BParser)53 Test (org.junit.Test)39 File (java.io.File)23 Ast2String (util.Ast2String)21 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)18 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)7 PrintStream (java.io.PrintStream)7 AbstractParseMachineTest (util.AbstractParseMachineTest)7 IOException (java.io.IOException)6 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)5 ClassicalBModel (de.prob.model.classicalb.ClassicalBModel)4 OutputStream (java.io.OutputStream)4 BLexer (de.be4.classicalb.core.parser.BLexer)3 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 EOF (de.be4.classicalb.core.parser.node.EOF)3 Token (de.be4.classicalb.core.parser.node.Token)3 ProBError (de.prob.exception.ProBError)3