use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class SetType method createASTNode.
public PExpression createASTNode(Typechecker typechecker) {
APowSubsetExpression node = new APowSubsetExpression(subtype.createASTNode(typechecker));
typechecker.setType(node, this);
return node;
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class StringType method createASTNode.
public PExpression createASTNode(Typechecker typechecker) {
AStringSetExpression node = new AStringSetExpression();
typechecker.setType(node, new SetType(this));
return node;
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class StructType method createASTNode.
public PExpression createASTNode(Typechecker typechecker) {
ArrayList<PRecEntry> list = new ArrayList<PRecEntry>();
Set<Entry<String, BType>> entrySet = this.types.entrySet();
for (Entry<String, BType> entry : entrySet) {
String name = entry.getKey();
BType type = entry.getValue();
TIdentifierLiteral literal = new TIdentifierLiteral(name);
ArrayList<TIdentifierLiteral> idList = new ArrayList<TIdentifierLiteral>();
idList.add(literal);
AIdentifierExpression id = new AIdentifierExpression(idList);
ARecEntry recEntry = new ARecEntry(id, type.createASTNode(typechecker));
list.add(recEntry);
}
AStructExpression node = new AStructExpression(list);
typechecker.setType(node, new SetType(this));
return node;
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class RulesMachineChecker method caseARuleFailSubSubstitution.
@Override
public void caseARuleFailSubSubstitution(ARuleFailSubSubstitution node) {
if (!isInRule()) {
errorList.add(new CheckException("RULE_FAIL used outside of a RULE operation", node));
return;
}
checkErrorType(node.getErrorType());
if (!node.getIdentifiers().isEmpty() && node.getWhen() == null) {
this.errorList.add(new CheckException("The WHEN predicate must be provided if RULE_FAIL has at least one parameter.", node));
return;
}
this.identifierScope.createNewScope(new LinkedList<PExpression>(node.getIdentifiers()));
if (node.getWhen() != null) {
node.getWhen().apply(this);
}
node.getMessage().apply(this);
this.identifierScope.removeScope();
}
use of de.be4.classicalb.core.parser.node.PExpression 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);
}
Aggregations