use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.
the class GrammarWindow method ateCaretUpdate.
public void ateCaretUpdate(int index) {
updateCursorInfo();
if (getTextPane().hasFocus()) {
editorIdeas.hide();
if (textEditor.getTextPane().isWritable()) {
editorIdeas.display(getCaretPosition());
}
}
// Update the auto-completion list
autoCompletionMenu.updateAutoCompleteList();
// Only display ideas using the mouse because otherwise when a rule
// is deleted (for example), the idea might be displayed before
// the parser was able to complete
// display(e.getDot());
ElementRule rule = editorRules.selectRuleInTreeAtPosition(index);
if (rule == null || rule.name == null) {
updateVisualization(false);
lastSelectedRule = null;
return;
}
if (lastSelectedRule == null || !lastSelectedRule.equals(rule.name)) {
lastSelectedRule = rule.name;
updateVisualization(false);
}
}
use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.
the class GrammarWindow method autoCompletionMenuGetMatchingWordsForPartialWord.
/** AutoCompletionMenuDelegate method: return the list of corresponding words
* given a partial word
*/
public List<String> autoCompletionMenuGetMatchingWordsForPartialWord(String partialWord) {
if (grammarEngine.getNumberOfRules() == 0) {
return null;
}
partialWord = partialWord.toLowerCase();
List<String> matchingRules = new ArrayList<String>();
if (editorRules.isRuleAtIndex(getCaretPosition())) {
// Inside a rule - show all rules in alphabetical order
List<ElementRule> sortedRules = Collections.list(Collections.enumeration(grammarEngine.getRules()));
Collections.sort(sortedRules, new Comparator<ElementRule>() {
public int compare(ElementRule o1, ElementRule o2) {
return o1.name.compareToIgnoreCase(o2.name);
}
});
for (ElementRule rule : sortedRules) {
if (rule.name.toLowerCase().startsWith(partialWord) && !matchingRules.contains(rule.name))
matchingRules.add(rule.name);
}
} else {
// Not inside rule - show only undefined rules
List<ElementReference> sortedUndefinedReferences = Collections.list(Collections.enumeration(grammarEngine.getUndefinedReferences()));
Collections.sort(sortedUndefinedReferences, new Comparator<ElementReference>() {
public int compare(ElementReference o1, ElementReference o2) {
return o1.rule.name.compareToIgnoreCase(o2.rule.name);
}
});
for (ElementReference ref : sortedUndefinedReferences) {
String attr = ref.token.getAttribute();
if (attr.toLowerCase().startsWith(partialWord) && !attr.equals(partialWord) && !matchingRules.contains(attr)) {
matchingRules.add(attr);
}
}
}
return matchingRules;
}
use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.
the class RulesDependency method getDOTString.
@Override
public String getDOTString() throws Exception {
ElementRule rule = window.getCurrentRule();
visitedRules.clear();
visitedRefs.clear();
dependency = new StringBuilder();
dependency.append("digraph {\n");
buildGraph(rule);
dependency.append("}");
return dependency.toString();
}
use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.
the class RulesDependency method willLaunch.
@Override
protected boolean willLaunch() {
if (!checkForCurrentRule())
return false;
ElementRule rule = window.getCurrentRule();
List<ElementReference> refs = window.editorRules.getReferencesInRule(rule);
if (refs == null || refs.isEmpty()) {
XJAlert.display(window.getJavaContainer(), "Error", "The selected rule doesn't contain any references");
return false;
}
includeLexerRefs = true;
if (!rule.lexer && window.getGrammarEngine().isCombinedGrammar()) {
includeLexerRefs = XJAlert.displayAlertYESNO(window.getJavaContainer(), "Rule Dependency Graph", "Do you want to include lexer references ?") == XJAlert.YES;
}
return true;
}
use of org.antlr.works.grammar.element.ElementRule in project antlrworks by antlr.
the class ANTLRGrammarEngineImpl method markLeftRecursiveRules.
private void markLeftRecursiveRules(List rules) {
// 'rules' is a list of set of rules given by ANTLR
for (Object ruleSet : rules) {
final Set rulesSet = (Set) ruleSet;
for (Object rule : rulesSet) {
final Rule aRule = (Rule) rule;
final ElementRule r = engine.getRuleWithName(aRule.name);
if (r == null)
continue;
r.setLeftRecursiveRulesSet(rulesSet);
}
}
}
Aggregations