Search in sources :

Example 81 with Start

use of de.be4.classicalb.core.parser.node.Start 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 82 with Start

use of de.be4.classicalb.core.parser.node.Start 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 83 with Start

use of de.be4.classicalb.core.parser.node.Start 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 84 with Start

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

the class Helpers method printAsProlog.

public static void printAsProlog(final Start start, final IPrologTermOutput pout) {
    final NodeIdAssignment nodeIds = new NodeIdAssignment();
    nodeIds.assignIdentifiers(1, start);
    final ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(nodeIds);
    final ASTProlog prolog = new ASTProlog(pout, pprinter);
    pout.openTerm("machine");
    start.apply(prolog);
    pout.closeTerm();
    pout.fullstop();
    pout.flush();
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)

Example 85 with Start

use of de.be4.classicalb.core.parser.node.Start 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)104 Test (org.junit.Test)84 BParser (de.be4.classicalb.core.parser.BParser)43 Ast2String (util.Ast2String)32 File (java.io.File)20 Start (de.be4.eventbalg.core.parser.node.Start)19 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)18 Start (de.be4.eventb.core.parser.node.Start)18 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)14 AMachineParseUnit (de.be4.eventbalg.core.parser.node.AMachineParseUnit)14 IOException (java.io.IOException)12 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 PushbackReader (java.io.PushbackReader)11 StringReader (java.io.StringReader)11 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)8 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)7 AbstractParseMachineTest (util.AbstractParseMachineTest)7 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)6 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)6 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)6