Search in sources :

Example 6 with ASTPrinter

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

the class BParser method fullParsing.

public int fullParsing(final File bfile, final ParsingBehaviour parsingBehaviour, final PrintStream out, final PrintStream err) {
    try {
        // Properties hashes = new Properties();
        // if (parsingBehaviour.getOutputFile() != null) {
        // if (hashesStillValid(parsingBehaviour.getOutputFile())){
        // return 0;
        // }
        // }
        final long start = System.currentTimeMillis();
        final Start tree = parseFile(bfile, parsingBehaviour.isVerbose());
        final long end = System.currentTimeMillis();
        if (parsingBehaviour.isPrintTime()) {
            out.println("Time for parsing: " + (end - start) + "ms");
        }
        if (parsingBehaviour.isPrintAST()) {
            ASTPrinter sw = new ASTPrinter(out);
            tree.apply(sw);
        }
        if (parsingBehaviour.isDisplayGraphically()) {
            tree.apply(new ASTDisplay());
        }
        final long start2 = System.currentTimeMillis();
        if (parsingBehaviour.isPrologOutput()) {
            printASTasProlog(out, this, bfile, tree, parsingBehaviour, contentProvider);
        }
        final long end2 = System.currentTimeMillis();
        if (parsingBehaviour.isPrintTime()) {
            out.println("Time for Prolog output: " + (end2 - start2) + "ms");
        }
        if (parsingBehaviour.isFastPrologOutput()) {
            try {
                String fp = getASTasFastProlog(this, bfile, tree, parsingBehaviour, contentProvider);
                out.println(fp);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } catch (final IOException e) {
        if (parsingBehaviour.isPrologOutput()) {
            PrologExceptionPrinter.printException(err, e, bfile.getAbsolutePath());
        } else {
            err.println();
            err.println("Error reading input file: " + e.getLocalizedMessage());
        }
        return -2;
    } catch (final BCompoundException e) {
        if (parsingBehaviour.isPrologOutput()) {
            PrologExceptionPrinter.printException(err, e, parsingBehaviour.isUseIndention(), false);
        // PrologExceptionPrinter.printException(err, e);
        } else {
            err.println();
            err.println("Error parsing input file: " + e.getLocalizedMessage());
        }
        return -3;
    }
    return 0;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) ASTDisplay(de.be4.classicalb.core.parser.visualisation.ASTDisplay) IOException(java.io.IOException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) ParserException(de.be4.classicalb.core.parser.parser.ParserException)

Example 7 with ASTPrinter

use of de.be4.classicalb.core.parser.visualisation.ASTPrinter 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 8 with ASTPrinter

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

Example 9 with ASTPrinter

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

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

Example 10 with ASTPrinter

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

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

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)14 BParser (de.be4.classicalb.core.parser.BParser)8 Ast2String (util.Ast2String)7 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)6 Test (org.junit.Test)5 BLexer (de.be4.classicalb.core.parser.BLexer)3 EOF (de.be4.classicalb.core.parser.node.EOF)3 Token (de.be4.classicalb.core.parser.node.Token)3 File (java.io.File)3 IOException (java.io.IOException)3 PushbackReader (java.io.PushbackReader)3 StringReader (java.io.StringReader)3 ASTPrinter (de.be4.eventbalg.core.parser.analysis.ASTPrinter)2 Start (de.be4.eventbalg.core.parser.node.Start)2 Helpers.getTreeAsString (util.Helpers.getTreeAsString)2 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 ParserException (de.be4.classicalb.core.parser.parser.ParserException)1 ASTDisplay (de.be4.classicalb.core.parser.visualisation.ASTDisplay)1 ASTDisplay (de.be4.eventb.core.parser.analysis.ASTDisplay)1 ASTPrinter (de.be4.eventb.core.parser.analysis.ASTPrinter)1