Search in sources :

Example 6 with Parser

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

the class ASTPrologTest method checkProlog.

private void checkProlog(final int counter, final String bspec, final String expected) throws BCompoundException {
    final BParser parser = new BParser("testcase");
    if (remove_restrictions) {
        parser.getOptions().setRestrictProverExpressions(false);
    }
    final Start startNode = parser.parse(bspec, false, new NoContentProvider());
    checkAST(counter, expected, startNode);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start)

Example 7 with Parser

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

the class ParseableButProblematicOnWindows method testParsable.

@Test
public void testParsable() throws Exception {
    final BParser parser = new BParser(machine.getName());
    Start start = parser.parseFile(machine, false);
    start.apply(new PositionTester());
    assertNotNull(start);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) AbstractParseMachineTest(util.AbstractParseMachineTest) Test(org.junit.Test)

Example 8 with Parser

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

the class ParseableButProblematicOnWindowsWindowsLF method testParsable.

@Test
public void testParsable() throws Exception {
    final BParser parser = new BParser(machine.getName());
    Start start = parser.parseFile(machine, false);
    start.apply(new PositionTester());
    assertNotNull(start);
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) AbstractParseMachineTest(util.AbstractParseMachineTest) Test(org.junit.Test)

Example 9 with Parser

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

the class PreParser method parse.

public void parse() throws PreParseException, IOException, BException, BCompoundException {
    final PreLexer preLexer = new PreLexer(pushbackReader);
    final Parser preParser = new Parser(preLexer);
    Start rootNode = null;
    try {
        rootNode = preParser.parse();
    } catch (final ParserException e) {
        if (e.getToken() instanceof de.be4.classicalb.core.preparser.node.TDefinitions) {
            final Token errorToken = e.getToken();
            final String message = "[" + errorToken.getLine() + "," + errorToken.getPos() + "] " + "Clause 'DEFINITIONS' is used more than once";
            throw new PreParseException(e.getToken(), message);
        } else {
            throw new PreParseException(e.getToken(), e.getLocalizedMessage());
        }
    } catch (final LexerException e) {
        throw new PreParseException(e.getLocalizedMessage());
    }
    final DefinitionPreCollector collector = new DefinitionPreCollector();
    rootNode.apply(collector);
    evaluateDefinitionFiles(collector.getFileDefinitions());
    List<Token> sortedDefinitionList = sortDefinitionsByTopologicalOrderAndCheckForCycles(collector.getDefinitions());
    evaluateTypes(sortedDefinitionList, collector.getDefinitions());
}
Also used : ParserException(de.be4.classicalb.core.preparser.parser.ParserException) Start(de.be4.classicalb.core.preparser.node.Start) Token(de.be4.classicalb.core.preparser.node.Token) DefinitionPreCollector(de.be4.classicalb.core.parser.analysis.checking.DefinitionPreCollector) Parser(de.be4.classicalb.core.preparser.parser.Parser) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) LexerException(de.be4.classicalb.core.preparser.lexer.LexerException)

Example 10 with Parser

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

the class RecursiveMachineLoader method printAsProlog.

public void printAsProlog(final IPrologTermOutput pout) {
    final ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(getNodeIdMapping());
    pprinter.printSourcePositions(parsingBehaviour.isAddLineNumbers());
    final ASTProlog prolog = new ASTProlog(pout, pprinter);
    // parser version
    pout.openTerm("parser_version");
    pout.printAtom(BParser.getBuildRevision());
    pout.closeTerm();
    pout.fullstop();
    // machine
    pout.openTerm("classical_b");
    pout.printAtom(main);
    pout.openList();
    List<File> allFiles = new ArrayList<>();
    allFiles.addAll(machineFilesLoaded);
    allFiles.addAll(definitionFilesLoaded);
    for (final File file : allFiles) {
        try {
            pout.printAtom(file.getCanonicalPath());
        } catch (IOException e) {
            pout.printAtom(file.getPath());
        }
    }
    pout.closeList();
    pout.closeTerm();
    pout.fullstop();
    for (final Map.Entry<String, Start> entry : getParsedMachines().entrySet()) {
        pout.openTerm("machine");
        entry.getValue().apply(prolog);
        pout.closeTerm();
        pout.fullstop();
    }
    pout.flush();
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)51 BParser (de.be4.classicalb.core.parser.BParser)41 Test (org.junit.Test)31 Ast2String (util.Ast2String)20 File (java.io.File)15 IOException (java.io.IOException)13 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)10 StringReader (java.io.StringReader)9 PushbackReader (java.io.PushbackReader)8 AbstractParseMachineTest (util.AbstractParseMachineTest)7 PrintStream (java.io.PrintStream)6 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)5 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)4 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)4 Reader (java.io.Reader)4 ArrayList (java.util.ArrayList)4 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3 Start (de.be4.eventbalg.core.parser.node.Start)3 LtlParseException (de.be4.ltl.core.parser.LtlParseException)3