Search in sources :

Example 31 with RuleCall

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

the class GrammarPDAProviderTest method toPda.

private String toPda(final CharSequence rulesText) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals");
        _builder.newLine();
        _builder.newLine();
        _builder.append("generate GrammarPDAProviderTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarPDAProviderTestLanguage\"");
        _builder.newLine();
        _builder.newLine();
        _builder.append(rulesText);
        _builder.newLineIfNotEmpty();
        final Grammar grammar = this.parser.parse(_builder);
        this.validator.assertNoErrors(grammar);
        final SerializationContextMap<Pda<ISerState, RuleCall>> pdas = this.pdaProvider.getGrammarPDAs(grammar);
        final Consumer<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>> _function = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
            this.assertNoLeakedGrammarElements(grammar, it.getValue());
        };
        pdas.values().forEach(_function);
        final Function1<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>> _function_1 = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
            return it.getContexts();
        };
        final Function1<ISerializationContext, String> _function_2 = (ISerializationContext it) -> {
            StringConcatenation _builder_1 = new StringConcatenation();
            _builder_1.append(it);
            _builder_1.append(":");
            _builder_1.newLineIfNotEmpty();
            _builder_1.append("\t");
            String _listString = this.toListString(pdas.get(it));
            _builder_1.append(_listString, "\t");
            _builder_1.newLineIfNotEmpty();
            return _builder_1.toString();
        };
        return IterableExtensions.join(ListExtensions.<ISerializationContext, String>map(IterableExtensions.<ISerializationContext>sort(Iterables.<ISerializationContext>concat(ListExtensions.<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>>map(pdas.values(), _function_1))), _function_2));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Grammar(org.eclipse.xtext.Grammar) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) ISerState(org.eclipse.xtext.serializer.analysis.ISerState) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List)

Example 32 with RuleCall

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

the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_02.

@Test
public void testCheckRuleCallInUnorderedGroup_02() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
    RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
    TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
    typeRef.setClassifier(EcorePackage.Literals.EBIG_DECIMAL);
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setType(typeRef);
    ruleCall.setRule(parserRule);
    unorderedGroup.getElements().add(ruleCall);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkRuleCallInUnorderedGroup(ruleCall);
    messageAcceptor.validate();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) TypeRef(org.eclipse.xtext.TypeRef) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 33 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_08_335692.

@Test
public void testRuleCallAllowed_08_335692() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model : value=ID FRAGMENT;\n" + "SubModel : FRAGMENT;\n" + "terminal fragment FRAGMENT: ';';";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    ParserRule datatypeRule = (ParserRule) grammar.getRules().get(1);
    RuleCall ruleCall = (RuleCall) datatypeRule.getAlternatives();
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Grammar(org.eclipse.xtext.Grammar) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 34 with RuleCall

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

the class XtextValidationTest method testRuleCallAllowed_09_335692.

@Test
public void testRuleCallAllowed_09_335692() throws Exception {
    String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model : value=ID FRAGMENT;\n" + "SubModel : FRAGMENT;\n" + "terminal fragment FRAGMENT: ';';";
    Grammar grammar = (Grammar) getModel(grammarAsText);
    ParserRule rule = (ParserRule) grammar.getRules().get(0);
    RuleCall ruleCall = (RuleCall) ((Group) rule.getAlternatives()).getElements().get(1);
    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkUnassignedRuleCallAllowed(ruleCall);
    validator.checkTerminalFragmentCalledFromTerminalRule(ruleCall);
    messageAcceptor.validate();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Group(org.eclipse.xtext.Group) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Grammar(org.eclipse.xtext.Grammar) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 35 with RuleCall

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

the class ContentAssistFragment2 method generateGenJavaProposalProvider.

protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
    GeneratedJavaFileAccess _xblockexpression = null;
    {
        final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
        final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
        final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
            ArrayList<Assignment> _xblockexpression_1 = null;
            {
                final String fqFeatureName = this.getFQFeatureName(assignment);
                if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
                    processedNames.add(fqFeatureName);
                    candidates.add(assignment);
                }
                _xblockexpression_1 = candidates;
            }
            return _xblockexpression_1;
        };
        final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
        final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
            ArrayList<AbstractRule> _xblockexpression_1 = null;
            {
                final String fqnFeatureName = this.getFQFeatureName(rule);
                if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
                    processedNames.add(fqnFeatureName);
                    candidates.add(rule);
                }
                _xblockexpression_1 = candidates;
            }
            return _xblockexpression_1;
        };
        final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
        TypeReference _xifexpression = null;
        boolean _isGenerateStub = this.isGenerateStub();
        if (_isGenerateStub) {
            _xifexpression = this.getGenProposalProviderClass(this.getGrammar());
        } else {
            _xifexpression = this.getProposalProviderClass(this.getGrammar());
        }
        final TypeReference genClass = _xifexpression;
        GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
        final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
            final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("/**");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("* Represents a generated, default implementation of superclass {@link ");
                    _builder.append(superClass, " ");
                    _builder.append("}.");
                    _builder.newLineIfNotEmpty();
                    _builder.append(" ");
                    _builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("* with a more concrete subtype. ");
                    _builder.newLine();
                    _builder.append(" ");
                    _builder.append("*/");
                    _builder.newLine();
                }
            };
            it.setTypeComment(_client);
            StringConcatenationClient _client_1 = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("public ");
                    {
                        boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
                        if (_isGenerateStub) {
                            _builder.append("abstract ");
                        }
                    }
                    _builder.append("class ");
                    String _simpleName = genClass.getSimpleName();
                    _builder.append(_simpleName);
                    _builder.append(" extends ");
                    _builder.append(superClass);
                    _builder.append(" {");
                    _builder.newLineIfNotEmpty();
                    _builder.newLine();
                    {
                        boolean _isEmpty = assignments.isEmpty();
                        boolean _not = (!_isEmpty);
                        if (_not) {
                            {
                                for (final Assignment assignment : assignments) {
                                    _builder.append("\t");
                                    StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
                                    _builder.append(_handleAssignment, "\t");
                                    _builder.newLineIfNotEmpty();
                                }
                            }
                            _builder.newLine();
                        }
                    }
                    {
                        for (final AbstractRule rule : remainingRules) {
                            _builder.append("\t");
                            _builder.append("public void complete");
                            String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
                            _builder.append(_fQFeatureName, "\t");
                            _builder.append("(");
                            _builder.append(EObject.class, "\t");
                            _builder.append(" model, ");
                            _builder.append(RuleCall.class, "\t");
                            _builder.append(" ruleCall, ");
                            TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
                            _builder.append(_contentAssistContextClass, "\t");
                            _builder.append(" context, ");
                            TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
                            _builder.append(_iCompletionProposalAcceptorClass, "\t");
                            _builder.append(" acceptor) {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("// subclasses may override");
                            _builder.newLine();
                            _builder.append("\t");
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                    _builder.append("}");
                    _builder.newLine();
                }
            };
            it.setContent(_client_1);
            it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
        };
        _xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
    }
    return _xblockexpression;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ArrayList(java.util.ArrayList) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)95 ParserRule (org.eclipse.xtext.ParserRule)41 AbstractRule (org.eclipse.xtext.AbstractRule)36 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)33 Grammar (org.eclipse.xtext.Grammar)28 AbstractElement (org.eclipse.xtext.AbstractElement)26 Assignment (org.eclipse.xtext.Assignment)22 TerminalRule (org.eclipse.xtext.TerminalRule)19 Action (org.eclipse.xtext.Action)17 CrossReference (org.eclipse.xtext.CrossReference)13 Group (org.eclipse.xtext.Group)13 TypeRef (org.eclipse.xtext.TypeRef)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 InternalEObject (org.eclipse.emf.ecore.InternalEObject)10 Keyword (org.eclipse.xtext.Keyword)10 EClass (org.eclipse.emf.ecore.EClass)9 EnumRule (org.eclipse.xtext.EnumRule)9