Search in sources :

Example 41 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class PartialSerializationTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == EcorePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case EcorePackage.ECLASS:
                sequence_EClassDecl(context, (EClass) semanticObject);
                return;
        }
    else if (epackage == PartialSerializationTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case PartialSerializationTestLanguagePackage.ECLASS_REF:
                sequence_EClassRef(context, (EClassRef) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_CHILD:
                sequence_MandatoryChild(context, (MandatoryChild) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_CHILD_LIST:
                sequence_MandatoryChildList(context, (MandatoryChildList) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANDATORY_VALUE:
                sequence_MandatoryValue(context, (MandatoryValue) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANY_MANDATORY_VALUES:
                sequence_ManyMandatoryValues(context, (ManyMandatoryValues) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MANY_VALUES:
                sequence_ManyOptionalValues(context, (ManyValues) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD:
                sequence_OptionalChild(context, (OptionalChild) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_CHILD_LIST:
                sequence_OptionalChildList(context, (OptionalChildList) semanticObject);
                return;
            case PartialSerializationTestLanguagePackage.OPTIONAL_VALUE:
                sequence_OptionalValue(context, (OptionalValue) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) EClass(org.eclipse.emf.ecore.EClass) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 42 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class IndentationAwareCompletionPrefixProvider method getLastCompleteNodeByOffset.

protected INode getLastCompleteNodeByOffset(INode node, int offset) {
    BidiTreeIterator<INode> iterator = node.getRootNode().getAsTreeIterable().iterator();
    INode result = node;
    ITextRegion candidateTextRegion = node.getTextRegion();
    while (iterator.hasNext()) {
        INode candidate = iterator.next();
        ITextRegion textRegion = candidate.getTextRegion();
        if (textRegion.getOffset() >= offset && !(textRegion.getOffset() == offset && textRegion.getLength() == 0)) {
            if (!candidateTextRegion.equals(textRegion) && candidate instanceof ILeafNode && textRegion.getLength() + textRegion.getOffset() >= offset) {
                break;
            }
        }
        if ((candidate instanceof ILeafNode) && (candidate.getGrammarElement() == null || candidate.getGrammarElement() instanceof AbstractElement || candidate.getGrammarElement() instanceof ParserRule)) {
            if (textRegion.getLength() == 0) {
                if (candidateTextRegion.getOffset() + candidateTextRegion.getLength() < offset || candidateTextRegion.getLength() == 0 && candidateTextRegion.getOffset() <= offset) {
                    result = candidate;
                    candidateTextRegion = candidate.getTextRegion();
                }
            } else {
                result = candidate;
                candidateTextRegion = candidate.getTextRegion();
            }
        }
    }
    return result;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) AbstractElement(org.eclipse.xtext.AbstractElement) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Example 43 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class BaseContentAssistParser method getFollowElements.

protected Collection<FE> getFollowElements(InternalParser parser, AbstractElement entryPoint) {
    String ruleName = getRuleName(entryPoint);
    if (ruleName == null) {
        if (entryPoint instanceof RuleCall) {
            RuleCall call = (RuleCall) entryPoint;
            AbstractRule rule = call.getRule();
            if (rule instanceof ParserRule) {
                ruleName = getRuleNames().getAntlrRuleName(rule);
            }
        }
    }
    if (ruleName == null) {
        throw new IllegalStateException("entryPoint: " + entryPoint);
    }
    return getFollowElements(parser, ruleName);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 44 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class Bug385636SemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == Bug385636Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Bug385636Package.DEFINE_VARIABLE:
                sequence_DefineVariable(context, (DefineVariable) semanticObject);
                return;
            case Bug385636Package.DEFINE_VARIABLES:
                sequence_DefineVariables(context, (DefineVariables) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_EQUAL:
                sequence_Statement(context, (Expression_Equal) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_LARGER_EQUAL:
                sequence_Statement(context, (Expression_Larger_Equal) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_NOT_EQUAL:
                sequence_Statement(context, (Expression_Not_Equal) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_NOT_GREATER:
                sequence_Statement(context, (Expression_Not_Greater) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_NOT_LESS:
                sequence_Statement(context, (Expression_Not_Less) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_SMALLER:
                sequence_Statement(context, (Expression_Smaller) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_SMALLER_EQUAL:
                sequence_Statement(context, (Expression_Smaller_Equal) semanticObject);
                return;
            case Bug385636Package.EXPRESSION_VARIABLE_NAME:
                sequence_Expression_VariableName(context, (Expression_VariableName) semanticObject);
                return;
            case Bug385636Package.NVARIABLE_ACCESS:
                sequence_NVariableAccess(context, (NVariableAccess) semanticObject);
                return;
            case Bug385636Package.PROGRAM:
                sequence_Program(context, (Program) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : Expression_Smaller(org.eclipse.xtext.resource.bug385636.Expression_Smaller) ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Expression_VariableName(org.eclipse.xtext.resource.bug385636.Expression_VariableName) Program(org.eclipse.xtext.resource.bug385636.Program) Expression_Larger_Equal(org.eclipse.xtext.resource.bug385636.Expression_Larger_Equal) DefineVariable(org.eclipse.xtext.resource.bug385636.DefineVariable) Expression_Not_Equal(org.eclipse.xtext.resource.bug385636.Expression_Not_Equal) Expression_Not_Greater(org.eclipse.xtext.resource.bug385636.Expression_Not_Greater) EPackage(org.eclipse.emf.ecore.EPackage) Expression_Smaller_Equal(org.eclipse.xtext.resource.bug385636.Expression_Smaller_Equal) Expression_Not_Less(org.eclipse.xtext.resource.bug385636.Expression_Not_Less) Expression_Equal(org.eclipse.xtext.resource.bug385636.Expression_Equal) Parameter(org.eclipse.xtext.Parameter) DefineVariables(org.eclipse.xtext.resource.bug385636.DefineVariables) NVariableAccess(org.eclipse.xtext.resource.bug385636.NVariableAccess)

Example 45 with ParserRule

use of org.eclipse.xtext.ParserRule in project xtext-core by eclipse.

the class LiveContainerTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == LiveContainerTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case LiveContainerTestLanguagePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Model(org.eclipse.xtext.resource.liveContainerTestLanguage.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

ParserRule (org.eclipse.xtext.ParserRule)380 Test (org.junit.Test)172 Grammar (org.eclipse.xtext.Grammar)151 Action (org.eclipse.xtext.Action)144 Parameter (org.eclipse.xtext.Parameter)137 EPackage (org.eclipse.emf.ecore.EPackage)126 AbstractRule (org.eclipse.xtext.AbstractRule)94 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)74 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)41 EObject (org.eclipse.emf.ecore.EObject)27 EnumRule (org.eclipse.xtext.EnumRule)21 TerminalRule (org.eclipse.xtext.TerminalRule)21 AbstractElement (org.eclipse.xtext.AbstractElement)18 Assignment (org.eclipse.xtext.Assignment)15 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)12 EClass (org.eclipse.emf.ecore.EClass)11 Group (org.eclipse.xtext.Group)11 NamedArgument (org.eclipse.xtext.NamedArgument)11 TypeRef (org.eclipse.xtext.TypeRef)11