Search in sources :

Example 51 with Keyword

use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.

the class FormatFormatter method configKeywordPair.

/**
 * Configure formatting for KeywordPair.
 *
 * @param config
 *          the FormattingConfig
 * @param elements
 *          the KeywordPair access
 */
private void configKeywordPair(final FormattingConfig config, final KeywordPairElements elements) {
    for (Keyword keyword : elements.findKeywords(".")) {
        config.setNoSpace().around(keyword);
    }
    config.setNoSpace().after(elements.getLeftParenthesisKeyword_0());
    config.setNoSpace().before(elements.getRightParenthesisKeyword_3());
}
Also used : Keyword(org.eclipse.xtext.Keyword)

Example 52 with Keyword

use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.

the class ScopeFormatter method configureFormatting.

@Override
protected void configureFormatting(final FormattingConfig cfg) {
    final ScopeGrammarAccess g = (ScopeGrammarAccess) getGrammarAccess();
    cfg.setAutoLinewrap(MAX_LINE_LENGTH);
    // Comments
    cfg.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
    cfg.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
    cfg.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
    // general keywords
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("(", ")")) {
        cfg.setNoSpace().before(pair.getFirst());
        cfg.setNoSpace().after(pair.getFirst());
        cfg.setNoSpace().before(pair.getSecond());
    }
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("[", "]")) {
        cfg.setNoSpace().after(pair.getFirst());
        cfg.setNoSpace().before(pair.getSecond());
    }
    for (final Pair<Keyword, Keyword> pair : g.findKeywordPairs("{", "}")) {
        if (pair.getFirst() == g.getListLiteralAccess().getLeftCurlyBracketKeyword_1()) {
            continue;
        }
        cfg.setLinewrap().after(pair.getFirst());
        cfg.setIndentationIncrement().after(pair.getFirst());
        cfg.setLinewrap().before(pair.getSecond());
        cfg.setIndentationDecrement().before(pair.getSecond());
    }
    for (final Keyword delimiter : g.findKeywords(",")) {
        cfg.setNoSpace().before(delimiter);
    }
    for (final Keyword delimiter : g.findKeywords(";")) {
        cfg.setNoSpace().before(delimiter);
        cfg.setLinewrap().after(delimiter);
    }
    for (final Keyword delimiter : g.findKeywords("#", ".", "::")) {
        cfg.setNoSpace().around(delimiter);
    }
    // ScopeModel
    final ScopeModelElements sm = g.getScopeModelAccess();
    cfg.setLinewrap(2).between(sm.getNameAssignment_1(), sm.getImportsAssignment_3());
    cfg.setLinewrap(1).before(sm.getImportsAssignment_3());
    cfg.setLinewrap(2).between(sm.getImportsAssignment_3(), sm.getExtensionsAssignment_4());
    cfg.setLinewrap(1).before(sm.getExtensionsAssignment_4());
    cfg.setLinewrap(2).between(sm.getExtensionsAssignment_4(), sm.getInjectionsAssignment_5());
    cfg.setLinewrap(1).before(sm.getInjectionsAssignment_5());
    cfg.setLinewrap(2).before(sm.getNamingAssignment_6());
    cfg.setLinewrap(2).before(sm.getScopesAssignment_7());
    // ScopeDefinition
    final ScopeDefinitionElements sd = g.getScopeDefinitionAccess();
    cfg.setSpace(" ").before(sd.getLeftParenthesisKeyword_1_0());
    cfg.setLinewrap(1, 1, 2).before(sd.getRulesAssignment_4());
    // ScopeRule
    final ScopeRuleElements sr = g.getScopeRuleAccess();
    cfg.setIndentationIncrement().after(sr.getEqualsSignKeyword_2());
    cfg.setLinewrap(0, 0, 1).after(sr.getEqualsSignKeyword_2());
    cfg.setLinewrap(0, 0, 1).before(sr.getGreaterThanSignGreaterThanSignKeyword_4_0());
    cfg.setLinewrap(0, 0, 1).before(sr.getSemicolonKeyword_5());
    cfg.setIndentationDecrement().before(sr.getSemicolonKeyword_5());
    // NamedScopeExpression
    final NamedScopeExpressionElements nse = g.getNamedScopeExpressionAccess();
    cfg.setLinewrap(0, 0, 1).before(nse.getCaseDefCaseKeyword_1_0_0());
    cfg.setLinewrap(0, 0, 1).before(nse.getAsKeyword_2_0());
}
Also used : NamedScopeExpressionElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.NamedScopeExpressionElements) ScopeGrammarAccess(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess) Keyword(org.eclipse.xtext.Keyword) ScopeModelElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeModelElements) ScopeDefinitionElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeDefinitionElements) ScopeRuleElements(com.avaloq.tools.ddk.xtext.scope.services.ScopeGrammarAccess.ScopeRuleElements)

Example 53 with Keyword

use of org.eclipse.xtext.Keyword in project dsl-devkit by dsldevkit.

the class FormatHyperlinkHelper method isOverrideKeyword.

/**
 * Checks if grammar element is one of Rule's "override" Keywords.
 *
 * @param grammarElement
 *          the grammar element
 * @return true, if is override keyword
 */
private boolean isOverrideKeyword(final EObject grammarElement) {
    Keyword override1 = ((FormatGrammarAccess) grammarAccess).getWildcardRuleAccess().getOverrideOverrideKeyword_1_0();
    Keyword override2 = ((FormatGrammarAccess) grammarAccess).getGrammarRuleAccess().getOverrideOverrideKeyword_0_0();
    return override1.equals(grammarElement) || override2.equals(grammarElement);
}
Also used : Keyword(org.eclipse.xtext.Keyword)

Example 54 with Keyword

use of org.eclipse.xtext.Keyword in project smarthome by eclipse.

the class ThingSyntacticSequencerExtension method emit_ModelThing_ThingKeyword_0_q.

@Override
protected void emit_ModelThing_ThingKeyword_0_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    ILeafNode node = nodes != null && nodes.size() == 1 && nodes.get(0) instanceof ILeafNode ? (ILeafNode) nodes.get(0) : null;
    Keyword keyword = grammarAccess.getModelThingAccess().getThingKeyword_0();
    acceptUnassignedKeyword(keyword, keyword.getValue(), node);
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) Keyword(org.eclipse.xtext.Keyword)

Example 55 with Keyword

use of org.eclipse.xtext.Keyword in project n4js by eclipse.

the class GrammarLinter method printKeywordsInTypesButNotInN4JS.

private void printKeywordsInTypesButNotInN4JS() {
    Grammar n4js = grammarAccess.getGrammar();
    Grammar types = typesGrammarAccess.getGrammar();
    ListMultimap<String, Keyword> n4jsKeywords = getAllKeywords(n4js);
    ListMultimap<String, Keyword> typesKeywords = getAllKeywords(types);
    typesKeywords.keySet().removeAll(n4jsKeywords.keySet());
    System.out.println("Keywords which do not occur in n4js rules: ");
    for (String keyword : typesKeywords.keySet()) {
        System.out.println("  " + keyword);
    }
    System.out.println();
}
Also used : Keyword(org.eclipse.xtext.Keyword) Grammar(org.eclipse.xtext.Grammar)

Aggregations

Keyword (org.eclipse.xtext.Keyword)70 RuleCall (org.eclipse.xtext.RuleCall)17 EObject (org.eclipse.emf.ecore.EObject)16 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 INode (org.eclipse.xtext.nodemodel.INode)13 AbstractElement (org.eclipse.xtext.AbstractElement)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 CrossReference (org.eclipse.xtext.CrossReference)9 Grammar (org.eclipse.xtext.Grammar)9 ParserRule (org.eclipse.xtext.ParserRule)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 Test (org.junit.Test)9 Action (org.eclipse.xtext.Action)8 Assignment (org.eclipse.xtext.Assignment)8 Alternatives (org.eclipse.xtext.Alternatives)7 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)7 EnumRule (org.eclipse.xtext.EnumRule)7 TerminalRule (org.eclipse.xtext.TerminalRule)6 Group (org.eclipse.xtext.Group)5 ArrayList (java.util.ArrayList)4