Search in sources :

Example 6 with ElementRule

use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.

the class EditorRules method selectRuleNameInTree.

public ElementRule selectRuleNameInTree(String name) {
    if (programmaticallySelectingRule || getGrammarEngine().getRules() == null)
        return null;
    ElementRule rule = null;
    programmaticallySelectingRule = true;
    for (ElementRule r : getGrammarEngine().getRules()) {
        if (r.name.equals(name)) {
            selectRuleInTree(r);
            rule = r;
            break;
        }
    }
    programmaticallySelectingRule = false;
    return rule;
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 7 with ElementRule

use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.

the class GrammarMenu method showTokensSD.

public void showTokensSD() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SHOW_TOKENS_SD);
    window.syntaxDiagramTab.setRule(new ElementRule(Grammar.ARTIFICIAL_TOKENS_RULENAME), true);
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 8 with ElementRule

use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.

the class GrammarRefactorMenu method removeLeftRecursion.

public void removeLeftRecursion() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_REMOVE_LEFT_RECURSION);
    ElementRule rule = window.editorRules.getEnclosingRuleAtPosition(window.getCaretPosition());
    if (rule == null) {
        XJAlert.display(window.getJavaContainer(), "Remove Left Recursion", "There is no rule at cursor position.");
        return;
    }
    if (!rule.hasLeftRecursion()) {
        XJAlert.display(window.getJavaContainer(), "Remove Left Recursion", "The rule doesn't have a left recursion.");
        return;
    }
    beginRefactor("Remove Left Recursion");
    String ruleText = rule.getTextRuleAfterRemovingLeftRecursion();
    mutator.replace(rule.getInternalTokensStartIndex(), rule.getInternalTokensEndIndex(), ruleText);
    endRefactor();
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 9 with ElementRule

use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.

the class GrammarRefactorMenu method insertionIndexForRule.

public int insertionIndexForRule(boolean lexer) {
    // Add the rule in the next line by default
    Point p = window.getTextEditor().getLineTextPositionsAtTextPosition(window.getCaretPosition());
    int insertionIndex = p.y;
    ElementRule rule = window.editorRules.getEnclosingRuleAtPosition(window.getCaretPosition());
    if (rule != null) {
        if (rule.lexer) {
            if (lexer) {
                // Add new rule just after this one
                insertionIndex = rule.getEndIndex();
            } else {
                // Add new rule after the last parser rule
                ElementRule last = window.editorRules.getLastParserRule();
                if (last != null)
                    insertionIndex = last.getEndIndex();
            }
        } else {
            if (lexer) {
                // Add new rule after the last lexer rule
                ElementRule last = window.editorRules.getLastLexerRule();
                if (last != null) {
                    insertionIndex = last.getEndIndex();
                } else {
                    // Add new rule after the last rule
                    last = window.editorRules.getLastRule();
                    if (last != null)
                        insertionIndex = last.getEndIndex();
                }
            } else {
                // Add new rule just after this one
                insertionIndex = rule.getEndIndex();
            }
        }
    }
    return insertionIndex;
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 10 with ElementRule

use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.

the class EditorRules method selectRuleInTreeAtPosition.

public ElementRule selectRuleInTreeAtPosition(int pos) {
    if (programmaticallySelectingRule || getGrammarEngine().getRules() == null)
        return null;
    programmaticallySelectingRule = true;
    ElementRule rule = getEnclosingRuleAtPosition(pos);
    selectRuleInTree(rule);
    programmaticallySelectingRule = false;
    return rule;
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Aggregations

ElementRule (org.antlr.works.grammar.element.ElementRule)30 ElementReference (org.antlr.works.grammar.element.ElementReference)3 ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)2 IOException (java.io.IOException)1 Set (java.util.Set)1 ATEGutterItem (org.antlr.works.ate.gutter.ATEGutterItem)1 Usages (org.antlr.works.find.Usages)1 ElementAction (org.antlr.works.grammar.element.ElementAction)1 ElementGroup (org.antlr.works.grammar.element.ElementGroup)1 SDGenerator (org.antlr.works.visualization.SDGenerator)1