Search in sources :

Example 6 with RuleNames

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

the class GrammarAccessExtensions method ruleName.

public String ruleName(final AbstractRule rule) {
    final RuleNames ruleNames = RuleNames.tryGetRuleNames(rule);
    String _elvis = null;
    String _antlrRuleName = null;
    if (ruleNames != null) {
        _antlrRuleName = ruleNames.getAntlrRuleName(rule);
    }
    if (_antlrRuleName != null) {
        _elvis = _antlrRuleName;
    } else {
        String _ruleName = AntlrGrammarGenUtil.getRuleName(rule);
        _elvis = _ruleName;
    }
    return _elvis;
}
Also used : RuleNames(org.eclipse.xtext.xtext.RuleNames)

Example 7 with RuleNames

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

the class GrammarFlatteningTest method getModel.

public Grammar getModel(final String model, final boolean dropUnreachable) throws Exception {
    EObject _model = super.getModel(model);
    Grammar grammar = ((Grammar) _model);
    RuleNames ruleNames = RuleNames.getRuleNames(grammar, false);
    RuleFilter filter = new RuleFilter();
    filter.setDiscardUnreachableRules(dropUnreachable);
    Grammar result = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar();
    XtextResource resource = this.<XtextResource>get(XtextResource.class);
    resource.getContents().add(result);
    resource.setURI(URI.createURI("synthetic://flattened.xtext"));
    return result;
}
Also used : RuleNames(org.eclipse.xtext.xtext.RuleNames) EObject(org.eclipse.emf.ecore.EObject) RuleFilter(org.eclipse.xtext.xtext.RuleFilter) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) FlattenedGrammarAccess(org.eclipse.xtext.xtext.FlattenedGrammarAccess)

Aggregations

RuleNames (org.eclipse.xtext.xtext.RuleNames)7 Grammar (org.eclipse.xtext.Grammar)4 FlattenedGrammarAccess (org.eclipse.xtext.xtext.FlattenedGrammarAccess)4 RuleFilter (org.eclipse.xtext.xtext.RuleFilter)4 RuleWithParameterValues (org.eclipse.xtext.xtext.RuleWithParameterValues)3 AbstractRule (org.eclipse.xtext.AbstractRule)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 EObject (org.eclipse.emf.ecore.EObject)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 ParserRule (org.eclipse.xtext.ParserRule)1 RuleCall (org.eclipse.xtext.RuleCall)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1