Search in sources :

Example 56 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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 57 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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)

Example 58 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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 59 with BCompoundException

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

the class ProBError method convertParserExceptionToErrorItems.

private static List<ErrorItem> convertParserExceptionToErrorItems(BCompoundException e) {
    List<ErrorItem> errorItems = new ArrayList<>();
    for (BException bException : e.getBExceptions()) {
        List<ErrorItem.Location> errorItemlocations = new ArrayList<>();
        if (bException.getFilename() != null && bException.getCause() != null) {
            List<BException.Location> parserlocations = bException.getLocations();
            for (BException.Location location : parserlocations) {
                ErrorItem.Location loc = new ErrorItem.Location(bException.getFilename(), location.getStartLine(), location.getStartColumn(), location.getEndLine(), location.getEndColumn());
                errorItemlocations.add(loc);
            }
        }
        ErrorItem item = new ErrorItem(bException.getMessage(), ErrorItem.Type.ERROR, errorItemlocations);
        errorItems.add(item);
    }
    return errorItems;
}
Also used : ArrayList(java.util.ArrayList) ErrorItem(de.prob.animator.domainobjects.ErrorItem) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 60 with BCompoundException

use of de.be4.classicalb.core.parser.exceptions.BCompoundException 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)

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