use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.
the class RulesMachineChecker method caseADefinitionExpression.
@Override
public void caseADefinitionExpression(ADefinitionExpression node) {
node.getDefLiteral().apply(this);
final String defName = node.getDefLiteral().getText();
if ("READ_XML_FROM_STRING".equals(defName)) {
if (node.getParameters().size() != 1) {
errorList.add(new CheckException("The external function 'READ_XML_FROM_STRING' requires exactly one argrument.", node));
return;
}
PExpression pExpression = node.getParameters().get(0);
if (pExpression instanceof AStringExpression) {
AStringExpression aStringExpr = (AStringExpression) pExpression;
TStringLiteral content = aStringExpr.getContent();
String text = content.getText();
int xmlStartIndex = text.indexOf("<?");
if (xmlStartIndex == -1) {
return;
}
String testString = text.substring(0, xmlStartIndex);
int numberOfNewLines = testString.length() - testString.replace("\n", "").length();
try {
InputSource inputSource = new InputSource(new StringReader(text.trim()));
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
Locale newLocale = new Locale("en", "GB");
// Surprisingly, we need both of the following two lines in
// order to obtain all error messages in English.
java.util.Locale.setDefault(newLocale);
saxParser.setProperty("http://apache.org/xml/properties/locale", newLocale);
saxParser.parse(inputSource, new DefaultHandler());
} catch (SAXParseException e) {
final int line = content.getLine() + numberOfNewLines + e.getLineNumber() - 1;
final int column = (numberOfNewLines == 0 && e.getLineNumber() == 1) ? content.getPos() + e.getColumnNumber() : e.getColumnNumber();
TStringLiteral dummy = new TStringLiteral("", line, column);
String message = e.getMessage();
errorList.add(new CheckException(message, dummy, e));
} catch (SAXException e) {
String message = e.getMessage();
errorList.add(new CheckException(message, aStringExpr, e));
} catch (ParserConfigurationException | IOException e) {
/*
* We do nothing. The error is not handled by the parser but
* will be handled by the ProB prolog kernel.
*/
}
}
}
super.caseADefinitionExpression(node);
}
use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.
the class ASTPrologTest method checkProlog.
private void checkProlog(final int counter, final String bspec, final String expected) throws BCompoundException {
final BParser parser = new BParser("testcase");
if (remove_restrictions) {
parser.getOptions().setRestrictProverExpressions(false);
}
final Start startNode = parser.parse(bspec, false, new NoContentProvider());
checkAST(counter, expected, startNode);
}
use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.
the class ParseableButProblematicOnWindows method testParsable.
@Test
public void testParsable() throws Exception {
final BParser parser = new BParser(machine.getName());
Start start = parser.parseFile(machine, false);
start.apply(new PositionTester());
assertNotNull(start);
}
use of de.be4.eventb.core.parser.parser.Parser in project probparsers by bendisposto.
the class ParseableButProblematicOnWindowsWindowsLF method testParsable.
@Test
public void testParsable() throws Exception {
final BParser parser = new BParser(machine.getName());
Start start = parser.parseFile(machine, false);
start.apply(new PositionTester());
assertNotNull(start);
}
use of de.be4.eventb.core.parser.parser.Parser 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());
}
Aggregations