use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class StextResource method parseState.
protected void parseState(State state) {
IParseResult parseResult = parse(state, StateSpecification.class.getSimpleName());
StateSpecification rootASTElement = (StateSpecification) parseResult.getRootASTElement();
state.getScopes().clear();
if (rootASTElement.getScope() != null) {
state.getScopes().add(rootASTElement.getScope());
}
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class StextResource method parseTransition.
protected void parseTransition(Transition transition) {
IParseResult parseResult = parse(transition, TransitionSpecification.class.getSimpleName());
TransitionSpecification rootASTElement = (TransitionSpecification) parseResult.getRootASTElement();
transition.getProperties().clear();
if (rootASTElement.getReaction() != null) {
TransitionReaction reaction = rootASTElement.getReaction();
transition.setEffect(reaction.getEffect());
transition.setTrigger(reaction.getTrigger());
transition.getProperties().addAll(reaction.getProperties());
}
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class STextExpressionParser method parseExpression.
public EObject parseExpression(String expression, String ruleName, String specification) {
StextResource resource = getResource();
resource.setURI(URI.createURI(getUri(), true));
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName(ruleName);
IParseResult result = parser.parse(parserRule, new StringReader(expression));
EObject rootASTElement = result.getRootASTElement();
resource.getContents().add(rootASTElement);
ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
Statechart sc = SGraphFactory.eINSTANCE.createStatechart();
sc.setDomainID(domainId);
sc.setName("sc");
if (specification != null) {
sc.setSpecification(specification);
}
resource.getContents().add(sc);
resource.getLinkingDiagnostics().clear();
linker.linkModel(sc, diagnosticsConsumer);
linker.linkModel(rootASTElement, diagnosticsConsumer);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics();
if (diagnostics.size() > 0) {
throw new LinkingException(diagnostics.toString());
}
if (result.hasSyntaxErrors()) {
StringBuilder errorMessages = new StringBuilder();
Iterable<INode> syntaxErrors = result.getSyntaxErrors();
for (INode iNode : syntaxErrors) {
errorMessages.append(iNode.getSyntaxErrorMessage());
errorMessages.append("\n");
}
throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages);
}
if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
}
return rootASTElement;
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class STextExpressionParser method createInterfaceScope.
public Scope createInterfaceScope(String contextScope) {
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName(InterfaceScope.class.getSimpleName());
IParseResult result = parser.parse(parserRule, new StringReader(contextScope));
return (Scope) result.getRootASTElement();
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class STextExpressionParser method createInternalScope.
public Scope createInternalScope(String contextScope) {
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName(InternalScope.class.getSimpleName());
IParseResult result = parser.parse(parserRule, new StringReader(contextScope));
return (Scope) result.getRootASTElement();
}
Aggregations