Search in sources :

Example 36 with BParser

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

the class ClassicalBFactory 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 ProBError
 *             if the file could not be parsed
 */
public Start parseFile(final File model, final BParser bparser) throws IOException {
    try {
        logger.trace("Parsing main file '{}'", model.getAbsolutePath());
        Start ast = null;
        ast = bparser.parseFile(model, false);
        return ast;
    } catch (BCompoundException e) {
        throw new ProBError(e);
    }
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ProBError(de.prob.exception.ProBError) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 37 with BParser

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

the class SubstitutionTest 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(string);
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 38 with BParser

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

the class AtelierBCompatibilityTest method testSysExtension.

@Test
public void testSysExtension() throws IOException, BCompoundException {
    String PATH = "src/test/resources/atelierb/sys_extension/";
    String file = PATH + "main.sys";
    File f = new File(file);
    BParser bparser = new BParser();
    Start ast = bparser.parseFile(f, false);
    assertNotNull(ast);
    RecursiveMachineLoader rml = new RecursiveMachineLoader(PATH, bparser.getContentProvider());
    rml.loadAllMachines(f, ast, bparser.getDefinitions());
}
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 39 with BParser

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

the class Helpers method fullParsing.

public static String fullParsing(String filename, ParsingBehaviour parsingBehaviour) {
    final File machineFile = new File(filename);
    final BParser parser = new BParser(machineFile.getAbsolutePath());
    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();
        }
    };
    PrintStream printStream = new PrintStream(output);
    parser.fullParsing(machineFile, parsingBehaviour, printStream, printStream);
    printStream.flush();
    printStream.close();
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File)

Example 40 with BParser

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

the class Helpers method getTreeAsString.

public static String getTreeAsString(final String testMachine) throws BCompoundException {
    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(string);
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser)

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