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;
}
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);
}
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();
}
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;
}
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;
}
Aggregations