Search in sources :

Example 36 with ParserRule

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

the class NoJdtTestLanguageSemanticSequencer 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 == NoJdtPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case NoJdtPackage.GREETING:
                sequence_Greeting(context, (Greeting) semanticObject);
                return;
            case NoJdtPackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Greeting(org.eclipse.xtext.testlanguages.noJdt.noJdt.Greeting) Action(org.eclipse.xtext.Action) Model(org.eclipse.xtext.testlanguages.noJdt.noJdt.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 37 with ParserRule

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

the class FollowElementComputer method computeFollowElements.

public void computeFollowElements(Collection<FollowElement> followElements, final IFollowElementAcceptor followElementAcceptor) {
    FollowElementCalculator calculator = feCalculatorProvider.get();
    calculator.acceptor = element -> {
        ParserRule rule = GrammarUtil.containingParserRule(element);
        if (rule == null || !GrammarUtil.isDatatypeRule(rule))
            followElementAcceptor.accept(element);
    };
    for (FollowElement element : followElements) {
        computeFollowElements(calculator, element);
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule)

Example 38 with ParserRule

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

the class RequiredRuleNameComputer method adjustRuleName.

protected String adjustRuleName(String ruleName, Param param) {
    AbstractElement elementToParse = param.elementToParse;
    Set<Parameter> context = getAssignedParameters(elementToParse, param.paramStack);
    if (!context.isEmpty()) {
        ParserRule containingRule = GrammarUtil.containingParserRule(elementToParse);
        String antlrRuleName = ruleNames.getAntlrRuleName(containingRule);
        int len = antlrRuleName.length();
        if (antlrRuleName.startsWith("rule")) {
            // rule__XYZ instead of ruleXYZ
            len += 2;
        }
        int config = getParameterConfig(context);
        String result = ruleNames.getAntlrRuleName(containingRule, config) + ruleName.substring(len);
        return result;
    }
    return ruleName;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) AbstractElement(org.eclipse.xtext.AbstractElement) Parameter(org.eclipse.xtext.Parameter)

Example 39 with ParserRule

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

the class RequiredRuleNameComputer method getRequiredRuleNames.

/**
 * @since 2.14
 */
protected String[][] getRequiredRuleNames(Param param, AbstractElement elementToParse) {
    if (elementToParse instanceof RuleCall) {
        RuleCall call = (RuleCall) elementToParse;
        if (call.getRule() instanceof ParserRule) {
            String antlrRuleName = ruleNames.getAntlrRuleName(call.getRule());
            if (!call.getArguments().isEmpty()) {
                Set<Parameter> context = param.getAssignedParametes();
                Set<Parameter> arguments = getAssignedArguments(call, context);
                int config = getParameterConfig(arguments);
                antlrRuleName = ruleNames.getAntlrRuleName(call.getRule(), config);
            }
            return new String[][] { { antlrRuleName } };
        }
    }
    return EMPTY_ARRAY;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Parameter(org.eclipse.xtext.Parameter) RuleCall(org.eclipse.xtext.RuleCall)

Example 40 with ParserRule

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

the class PartialContentAssistTestLanguageSemanticSequencer 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 == PartialContentAssistTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case PartialContentAssistTestLanguagePackage.PROPERTY:
                sequence_Property(context, (Property) semanticObject);
                return;
            case PartialContentAssistTestLanguagePackage.TYPE_DECLARATION:
                sequence_TypeDeclaration(context, (TypeDeclaration) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Parameter(org.eclipse.xtext.Parameter) Property(org.eclipse.xtext.ide.tests.testlanguage.partialContentAssistTestLanguage.Property) TypeDeclaration(org.eclipse.xtext.ide.tests.testlanguage.partialContentAssistTestLanguage.TypeDeclaration) 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