Search in sources :

Example 1 with ElementRule

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);
    }
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 2 with ElementRule

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;
}
Also used : ElementReference(org.antlr.works.grammar.element.ElementReference) ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 3 with ElementRule

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();
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 4 with ElementRule

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;
}
Also used : ElementReference(org.antlr.works.grammar.element.ElementReference) ElementRule(org.antlr.works.grammar.element.ElementRule)

Example 5 with ElementRule

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);
        }
    }
}
Also used : Set(java.util.Set) ElementRule(org.antlr.works.grammar.element.ElementRule) 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