Search in sources :

Example 16 with ParsingBehaviour

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

the class FilePragmaTest method testFilePragma.

@Test
public void testFilePragma() throws IOException, BCompoundException {
    String PATH = "src/test/resources/pragmas/filePragma/";
    String file = PATH + "Main1.mch";
    File f = new File(file);
    BParser bparser = new BParser();
    Start ast = bparser.parseFile(f, false);
    assertNotNull(ast);
    RecursiveMachineLoader rml = new RecursiveMachineLoader(PATH, bparser.getContentProvider(), new ParsingBehaviour());
    rml.loadAllMachines(f, ast, bparser.getDefinitions());
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) Ast2String(util.Ast2String) File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) Test(org.junit.Test)

Example 17 with ParsingBehaviour

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

the class RulesProjectExceptionTest method testRulesMachineInOrdinaryMachineFileException.

@Test
public void testRulesMachineInOrdinaryMachineFileException() throws Exception {
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

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

        @Override
        public String toString() {
            return this.string.toString();
        }
    };
    PrintStream pStream = new PrintStream(output);
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setPrologOutput(true);
    BParser bParser = new BParser("RulesMachineInOrdinaryMachineFile.mch");
    bParser.fullParsing(new File("src/test/resources/rules/project/RulesMachineInOrdinaryMachineFile.mch"), parsingBehaviour, pStream, pStream);
    System.out.println(output.toString());
    assertTrue(output.toString().contains("parse_exception"));
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) BParser(de.be4.classicalb.core.parser.BParser) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) File(java.io.File) Test(org.junit.Test)

Example 18 with ParsingBehaviour

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

the class RulesUtil method getRulesProjectAsPrologTerm.

public static String getRulesProjectAsPrologTerm(final String content) {
    RulesProject rulesProject = new RulesProject();
    ParsingBehaviour pb = new ParsingBehaviour();
    pb.setAddLineNumbers(false);
    rulesProject.setParsingBehaviour(pb);
    rulesProject.parseRulesMachines(content, new String[] {});
    rulesProject.checkAndTranslateProject();
    List<IModel> bModels = rulesProject.getBModels();
    List<BException> bExceptionList = rulesProject.getBExceptionList();
    if (bExceptionList.isEmpty()) {
        IModel model = bModels.get(bModels.size() - 2);
        PrettyPrinter pp = new PrettyPrinter();
        model.getStart().apply(pp);
        System.out.println(pp.getPrettyPrint());
    }
    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();
        }
    };
    rulesProject.printPrologOutput(new PrintStream(output), new PrintStream(output));
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) OutputStream(java.io.OutputStream) BException(de.be4.classicalb.core.parser.exceptions.BException) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

Example 19 with ParsingBehaviour

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

the class RulesMachineFilesTest method testImplicitDependenciesDueToFunctionCall.

@Test
public void testImplicitDependenciesDueToFunctionCall() throws Exception {
    File file = new File(dir + "ImplicitDependencyDueFunctionCall.rmch");
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    parsingBehaviour.setPrologOutput(true);
    RulesProject.parseProject(file, parsingBehaviour, System.out, System.err);
}
Also used : File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) Test(org.junit.Test)

Example 20 with ParsingBehaviour

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

the class RulesMachineFilesTest method testProject2.

@Test
public void testProject2() throws Exception {
    File file = new File(dir + "project/references/test1/Rule1.rmch");
    ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    parsingBehaviour.setPrologOutput(true);
    RulesProject.parseProject(file, parsingBehaviour, System.out, System.err);
}
Also used : File(java.io.File) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) Test(org.junit.Test)

Aggregations

ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)19 File (java.io.File)16 PrintStream (java.io.PrintStream)12 BParser (de.be4.classicalb.core.parser.BParser)9 OutputStream (java.io.OutputStream)7 Start (de.be4.classicalb.core.parser.node.Start)6 Test (org.junit.Test)6 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)5 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)4 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 ProBError (de.prob.exception.ProBError)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 BException (de.be4.classicalb.core.parser.exceptions.BException)2 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)2 LtlParseException (de.be4.ltl.core.parser.LtlParseException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Ast2String (util.Ast2String)2 MockedDefinitions (de.be4.classicalb.core.parser.MockedDefinitions)1 ParserException (de.be4.classicalb.core.parser.parser.ParserException)1