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;
}
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);
}
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;
}
}
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 {
}
}
}
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());
}
Aggregations