Search in sources :

Example 41 with Parser

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

the class ModelGenerator method addComponent.

private ModelModifier addComponent(ModelModifier modelM, String name, String componentDesc, Map<String, String> components) throws BException {
    EventBParser parser = new EventBParser();
    Start ast = parser.parse(componentDesc, false);
    ReferenceExtractor e = new ReferenceExtractor();
    ast.apply(e);
    if (e.isContext()) {
        for (String s : e.getExtends()) {
            String fileN = s + ".ctx";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for context " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        modelM = addComponent(modelM, ast);
    } else if (e.isMachine()) {
        for (String s : e.getSees()) {
            String fileN = s + ".ctx";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for context " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        for (String s : e.getRefines()) {
            String fileN = s + ".emch";
            if (modelM.getModel().getComponent(fileN) == null) {
                if (components.get(fileN) == null) {
                    throw new IllegalArgumentException("no component description for machine " + s);
                }
                modelM = addComponent(modelM, s, components.get(fileN), components);
            }
        }
        modelM = addComponent(modelM, ast);
    }
    return modelM;
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) EventBParser(de.be4.eventbalg.core.parser.EventBParser)

Example 42 with Parser

use of de.be4.classicalb.core.parser.parser.Parser 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 43 with Parser

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

the class Helpers method fullParsing.

public static String fullParsing(String filename, ParsingBehaviour parsingBehaviour) {
    final File machineFile = new File(filename);
    final BParser parser = new BParser(machineFile.getAbsolutePath());
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintStream printStream = new PrintStream(output);
    parser.fullParsing(machineFile, parsingBehaviour, printStream, printStream);
    printStream.flush();
    printStream.close();
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File)

Example 44 with Parser

use of de.be4.classicalb.core.parser.parser.Parser 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 45 with Parser

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

the class Helpers method parseFile.

public static void parseFile(final String filename) throws IOException, BCompoundException {
    final int dot = filename.lastIndexOf('.');
    if (dot >= 0) {
        final File machineFile = new File(filename);
        final String probfilename = filename.substring(0, dot) + ".prob";
        BParser parser = new BParser(filename);
        Start tree = parser.parseFile(machineFile, false);
        final ParsingBehaviour behaviour = new ParsingBehaviour();
        behaviour.setVerbose(true);
        PrintStream output = new PrintStream(probfilename);
        BParser.printASTasProlog(output, parser, machineFile, tree, behaviour, parser.getContentProvider());
        output.close();
    } else
        throw new IllegalArgumentException("Filename '" + filename + "' has no extension");
}
Also used : PrintStream(java.io.PrintStream) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

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