Search in sources :

Example 66 with BParser

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

the class PredVarsTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
    final BParser parser = new BParser("testcase");
    Start ast = parser.eparse(testMachine, new Definitions());
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    final String string = ast2String.toString();
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Definitions(de.be4.classicalb.core.parser.Definitions) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 67 with BParser

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

the class ParserBugTest method test.

@Test
public void test() throws Exception {
    BParser parser = new BParser();
    Start ast = parser.parse(s, true);
    ast.apply(new ASTPrinter());
    assertTrue(true);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) BParser(de.be4.classicalb.core.parser.BParser) Test(org.junit.Test)

Example 68 with BParser

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

the class RulesParseUnit method parse.

public void parse() {
    if (this.bCompoundException != null) {
        return;
    }
    try {
        bParser = null;
        if (machineFile != null) {
            bParser = new BParser(machineFile.getPath());
            bParser.setDirectory(machineFile.getParentFile());
        } else {
            bParser = new BParser();
        }
        ParseOptions parseOptions = new ParseOptions();
        parseOptions.setGrammar(RulesGrammar.getInstance());
        bParser.setParseOptions(parseOptions);
        start = bParser.parse(content, debugOuput, new CachingDefinitionFileProvider());
        refFinder = new RulesReferencesFinder(machineFile, start);
        refFinder.findReferencedMachines();
        this.machineReferences = refFinder.getReferences();
        this.machineName = refFinder.getName();
        this.rulesMachineChecker = new RulesMachineChecker(machineFile, bParser.getFileName(), machineReferences, start);
        rulesMachineChecker.runChecks();
        this.operationList.addAll(rulesMachineChecker.getOperations());
    } catch (BCompoundException e) {
        // store parser exceptions
        this.bCompoundException = e;
    }
}
Also used : CachingDefinitionFileProvider(de.be4.classicalb.core.parser.CachingDefinitionFileProvider) ParseOptions(de.be4.classicalb.core.parser.ParseOptions) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 69 with BParser

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

the class PreParser method evaluateDefinitionFiles.

private void evaluateDefinitionFiles(final List<Token> list) throws PreParseException, BException, BCompoundException {
    IDefinitionFileProvider cache = null;
    if (contentProvider instanceof IDefinitionFileProvider) {
        cache = (IDefinitionFileProvider) contentProvider;
    }
    for (final Token fileNameToken : list) {
        final List<String> newDoneList = new ArrayList<String>(doneDefFiles);
        try {
            final String fileName = fileNameToken.getText();
            if (doneDefFiles.contains(fileName)) {
                StringBuilder sb = new StringBuilder();
                for (String string : doneDefFiles) {
                    sb.append(string).append(" -> ");
                }
                sb.append(fileName);
                throw new PreParseException(fileNameToken, "Cyclic references in definition files: " + sb.toString());
            }
            IDefinitions definitions;
            if (cache != null && cache.getDefinitions(fileName) != null) {
                definitions = cache.getDefinitions(fileName);
            } else {
                final String content = contentProvider.getFileContent(directory, fileName);
                newDoneList.add(fileName);
                final File file = contentProvider.getFile(directory, fileName);
                String filePath = fileName;
                if (file != null) {
                    filePath = file.getCanonicalPath();
                }
                final BParser parser = new BParser(filePath, parseOptions);
                parser.setDirectory(directory);
                parser.setDoneDefFiles(newDoneList);
                parser.setDefinitions(new Definitions(file));
                parser.parse(content, debugOutput, contentProvider);
                definitions = parser.getDefinitions();
                if (cache != null) {
                    cache.storeDefinition(fileName, definitions);
                }
            }
            defFileDefinitions.addDefinitions(definitions);
            definitionTypes.addAll(definitions.getTypes());
        } catch (final IOException e) {
            throw new PreParseException(fileNameToken, "Definition file cannot be read: " + e.getLocalizedMessage());
        } finally {
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Token(de.be4.classicalb.core.preparser.node.Token) IOException(java.io.IOException) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) File(java.io.File)

Example 70 with BParser

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

the class RecursiveMachineLoader method loadMachine.

private void loadMachine(final List<String> ancestors, final File machineFile) throws BCompoundException, IOException {
    if (machineFilesLoaded.contains(machineFile)) {
        return;
    }
    final BParser parser = new BParser(machineFile.getAbsolutePath());
    Start tree;
    tree = parser.parseFile(machineFile, parsingBehaviour.isVerbose(), contentProvider);
    recursivlyLoadMachine(machineFile, tree, ancestors, false, machineFile.getParentFile(), parser.getDefinitions());
}
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