Search in sources :

Example 31 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class GrammarSyntaxParser method matchAssignment.

private boolean matchAssignment(LabelTable labels) {
    mark();
    ATEToken label = T(0);
    if (matchID(0)) {
        if (matchChar(0, "=")) {
            label.type = GrammarSyntaxLexer.TOKEN_LABEL;
            labels.add(label.getAttribute());
            return true;
        } else if (isChar(0, "+") && isChar(1, "=")) {
            label.type = GrammarSyntaxLexer.TOKEN_LABEL;
            labels.add(label.getAttribute());
            skip(2);
            return true;
        }
    }
    rewind();
    return false;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 32 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class GrammarSyntaxParser method resolveReferencesWithExternalNames.

/**
     * Resolves the unresolved references by using externally provided names. For example,
     * reading a file of token using the option tokenVocab will invoke this method to solve
     * any remaining references that are still unresolved.
     *
     * @param externalNames A list of string representing the external declared reference names
     */
public void resolveReferencesWithExternalNames(Set<String> externalNames) {
    for (int i = unresolvedReferences.size() - 1; i >= 0; i--) {
        ATEToken ref = unresolvedReferences.get(i);
        if (externalNames.contains(ref.getAttribute())) {
            ref.type = GrammarSyntaxLexer.TOKEN_REFERENCE;
            references.add(new ElementReference(refsToRules.get(ref), ref));
            unresolvedReferences.remove(i);
        }
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 33 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class FindMenu method findUsage.

public void findUsage() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_FIND_USAGES);
    ATEToken token = delegate.getCurrentToken();
    if (token == null)
        return;
    Usages usage = new Usages(delegate, token);
    delegate.addUsagesTab(usage);
    for (ATEToken ateToken : delegate.getTokens()) {
        if (ateToken.getAttribute().equals(token.getAttribute())) {
            ElementRule matchedRule = delegate.getEditorRules().getEnclosingRuleAtPosition(ateToken.getStartIndex());
            if (matchedRule != null)
                usage.addMatch(matchedRule, ateToken);
        }
    }
}
Also used : ElementRule(org.antlr.works.grammar.element.ElementRule) Usages(org.antlr.works.find.Usages) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 34 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class GrammarMenu method ungroup.

public void ungroup() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_RULE_UNGROUP);
    ElementGroup openGroup = window.editorRules.getSelectedGroup();
    if (openGroup == null) {
        // No open group selected in the tree. Try to find the closest open group
        // by moving backward
        openGroup = window.editorRules.findOpenGroupClosestToLocation(window.getTextPane().getSelectionStart());
        if (openGroup == null) {
            // Still no open group ? Give up
            XJAlert.display(window.getJavaContainer(), "Ungroup", "Cannot ungroup because no enclosing group has been found.");
            return;
        }
    }
    ElementGroup closingGroup = window.editorRules.findClosingGroupForGroup(openGroup);
    window.beginGroupChange("Ungroup");
    if (closingGroup != null) {
        // End of file is considered as a closing group but no group really exists
        // for that purpose
        ATEToken t = closingGroup.token;
        window.replaceText(t.getStartIndex() - 1, t.getEndIndex(), "");
    }
    ATEToken t = openGroup.token;
    window.replaceText(t.getStartIndex() - 1, t.getEndIndex(), "");
    window.endGroupChange();
}
Also used : ElementGroup(org.antlr.works.grammar.element.ElementGroup) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 35 with ATEToken

use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.

the class GrammarRefactorMenu method convertLiteralsToSpecifiedQuote.

protected void convertLiteralsToSpecifiedQuote(int tokenType, char quote, char unescapeQuote) {
    List<ATEToken> tokens = window.getTokens();
    for (int index = tokens.size() - 1; index > 0; index--) {
        ATEToken token = tokens.get(index);
        if (token.type != tokenType)
            continue;
        // FIX AW-56
        if (RefactorEngine.ignoreScopeForDoubleQuoteLiteral(token.scope))
            continue;
        String attribute = token.getAttribute();
        String stripped = attribute.substring(1, attribute.length() - 1);
        if (stripped.indexOf(quote) != -1 || stripped.indexOf(unescapeQuote) != -1)
            stripped = escapeStringQuote(stripped, quote, unescapeQuote);
        mutator.replace(token.getStartIndex(), token.getEndIndex(), quote + stripped + quote);
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Aggregations

ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)42 ElementGroup (org.antlr.works.grammar.element.ElementGroup)2 ElementRule (org.antlr.works.grammar.element.ElementRule)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 BadLocationException (javax.swing.text.BadLocationException)1 ATESyntaxEngine (org.antlr.works.ate.syntax.generic.ATESyntaxEngine)1 ATESyntaxParser (org.antlr.works.ate.syntax.generic.ATESyntaxParser)1 Usages (org.antlr.works.find.Usages)1 ElementAction (org.antlr.works.grammar.element.ElementAction)1 ElementBlock (org.antlr.works.grammar.element.ElementBlock)1 GrammarSyntaxLexer (org.antlr.works.grammar.syntax.GrammarSyntaxLexer)1 ElementTemplateRule (org.antlr.works.stringtemplate.element.ElementTemplateRule)1