Package org.antlr.works.grammar.element

Examples of org.antlr.works.grammar.element.ElementRule


        // 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;
        }
View Full Code Here


    }

    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();
    }
View Full Code Here

        StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_REMOVE_ALL_LEFT_RECURSION);

        beginRefactor("Remove All Left Recursion");
        List<ElementRule> rules = window.editorRules.getRules();
        for(int index = rules.size()-1; index >= 0; index--) {
            ElementRule rule = rules.get(index);
            if(rule.hasLeftRecursion()) {
                String ruleText = rule.getTextRuleAfterRemovingLeftRecursion();
                mutator.replace(rule.getInternalTokensStartIndex(), rule.getInternalTokensEndIndex(), ruleText);
            }
        }
        endRefactor();
    }
View Full Code Here

    }

    public void inlineRule() {
        StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_INLINE_RULE);

        ElementRule rule = window.editorRules.getEnclosingRuleAtPosition(window.getCaretPosition());
        if(rule == null) {
            XJAlert.display(window.getJavaContainer(), "Inline Rule", "There is no rule at cursor position.");
            return;
        }
View Full Code Here

            // More than one token, append ()
            ruleContent = "("+ruleContent+")";
        }

        for(int r=rules.size()-1; r>=0; r--) {
            ElementRule candidate = rules.get(r);
            if(candidate == rule) {
                mutator.delete(rule.getStartIndex(), rule.getEndIndex()+1);
            } else {
                List<ElementReference> references = candidate.getReferences();
                if(references == null)
                    continue;

                for(int index=references.size()-1; index>=0; index--) {
                    ElementReference ref = references.get(index);
View Full Code Here

        window.setCaretPosition(index);
        endRefactor();
    }

    public void deleteRuleAtIndex(int index) {
        ElementRule r = window.editorRules.getEnclosingRuleAtPosition(index);
        if(r != null)
            window.replaceText(r.getStartIndex(), r.getEndIndex(), "");
    }
View Full Code Here

    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();
                }
View Full Code Here

        StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SHOW_RULE_GENERATED_CODE);

        if(window.getCurrentRule() == null) {
            XJAlert.display(window.getJavaContainer(), "Error", "A rule must be selected first.");
        } else {
            ElementRule r = window.getCurrentRule();
            checkAndShowGeneratedCode(r.name, r.lexer?ElementGrammarName.LEXER:ElementGrammarName.PARSER);
        }
    }
View Full Code Here

    public void display(Point p) {
        display(window.getTextPane().viewToModel(p));
    }

    public void display(int position) {
        ElementRule enclosingRule = window.editorRules.getEnclosingRuleAtPosition(position);
        if(enclosingRule == null || enclosingRule.isExpanded())
            ideaManager.displayAnyIdeasAvailable(position);
    }
View Full Code Here

            return null;

        List<ElementRule> sortedRules = new ArrayList<ElementRule>(rules);
        Collections.sort(sortedRules);
        if(!sortedRules.isEmpty()) {
            ElementRule firstRule = sortedRules.get(0);
            if(firstRule.lexer) {
                for(int index=0; index<sortedRules.size(); index++) {
                    ElementRule rule = sortedRules.get(0);
                    if(!rule.lexer)
                        break;

                    sortedRules.add(rule);
                    sortedRules.remove(0);
View Full Code Here

TOP

Related Classes of org.antlr.works.grammar.element.ElementRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.