Search in sources :

Example 21 with IParseResult

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());
    }
}
Also used : StateSpecification(org.yakindu.sct.model.stext.stext.StateSpecification) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 22 with IParseResult

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());
    }
}
Also used : TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) IParseResult(org.eclipse.xtext.parser.IParseResult) TransitionReaction(org.yakindu.sct.model.stext.stext.TransitionReaction)

Example 23 with IParseResult

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;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) StextResource(org.yakindu.sct.model.stext.resource.StextResource) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) StringReader(java.io.StringReader) ListBasedDiagnosticConsumer(org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer) Statechart(org.yakindu.sct.model.sgraph.Statechart) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 24 with IParseResult

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();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) StringReader(java.io.StringReader) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 25 with IParseResult

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();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) StringReader(java.io.StringReader) IParseResult(org.eclipse.xtext.parser.IParseResult)

Aggregations

IParseResult (org.eclipse.xtext.parser.IParseResult)60 EObject (org.eclipse.emf.ecore.EObject)22 StringReader (java.io.StringReader)16 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)14 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)10 INode (org.eclipse.xtext.nodemodel.INode)10 XtextResource (org.eclipse.xtext.resource.XtextResource)10 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)9 ParserRule (org.eclipse.xtext.ParserRule)8 Test (org.junit.Test)7 ITextRegion (org.eclipse.xtext.util.ITextRegion)6 Resource (org.eclipse.emf.ecore.resource.Resource)4 TextRegion (org.eclipse.xtext.util.TextRegion)4 URI (org.eclipse.emf.common.util.URI)3 WrappedException (org.eclipse.emf.common.util.WrappedException)3 ParseResult (org.eclipse.xtext.parser.ParseResult)3 Scope (org.yakindu.sct.model.sgraph.Scope)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2