use of de.be4.classicalb.core.preparser.node.Token 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());
}
use of de.be4.classicalb.core.preparser.node.Token in project probparsers by bendisposto.
the class PrologExceptionPrinter method printBLexerException.
private static void printBLexerException(final IPrologTermOutput pto, final BLexerException e, final String filename, final boolean useIndentation, final boolean lineOneOff) {
final Token token = e.getLastToken();
final SourcePosition pos = token == null ? null : new SourcePosition(token.getLine(), token.getPos());
printExceptionWithSourcePosition(pto, e, filename, pos, useIndentation, lineOneOff);
}
use of de.be4.classicalb.core.preparser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkForInvalidDefinition.
@Test
public void checkForInvalidDefinition() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEING x :=1 END \nEND";
try {
getTreeAsString(s);
fail("Invalid substitution was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
// there is no token available, hence the position is in the text
assertTrue(e.getMessage().contains("[3,15]"));
assertTrue(e.getMessage().contains("expecting end of definition"));
}
}
use of de.be4.classicalb.core.preparser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkForInvalidSubstitution.
@Test
public void checkForInvalidSubstitution() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEGIN\n x=1 END \nEND";
try {
getTreeAsString(s);
fail("Invalid substitution was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
// there is no token available, hence the position is in the text
assertTrue(e.getMessage().contains("[4,3]"));
}
}
use of de.be4.classicalb.core.preparser.node.Token in project probparsers by bendisposto.
the class DefinitionsErrorsTest method checkAtSymbolInDefinitions.
@Test
public void checkAtSymbolInDefinitions() throws Exception {
String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEGIN\n @ END \nEND";
try {
getTreeAsString(s);
fail("Invalid substitution was not detected.");
} catch (BCompoundException e) {
System.out.println(e.getMessage());
// there is no token available, hence the position is in the text
assertTrue(e.getMessage().contains("[4,2]"));
}
}
Aggregations