Search in sources :

Example 21 with ATEToken

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

the class GrammarRefactorMenu method replaceLiteralTokenWithTokenLabel.

public void replaceLiteralTokenWithTokenLabel(ATEToken t, String name) {
    // First insert the rule at the end of the grammar
    mutator.insert(window.getText().length(), "\n\n" + name + "\n\t:\t" + t.getAttribute() + "\n\t;");
    // Then rename all strings token
    List<ATEToken> tokens = window.getTokens();
    String attr = t.getAttribute();
    for (int index = tokens.size() - 1; index > 0; index--) {
        ATEToken token = tokens.get(index);
        if (token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING)
            continue;
        if (!token.getAttribute().equals(attr))
            continue;
        mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 22 with ATEToken

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

the class STRefactorMenu method rename.

public void rename() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_RENAME);
    ATEToken token = window.getCurrentToken();
    if (token == null)
        return;
    String s = (String) JOptionPane.showInputDialog(window.getJavaContainer(), "Rename '" + token.getAttribute() + "' and its usages to:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, token.getAttribute());
    if (s != null && !s.equals(token.getAttribute())) {
        beginRefactor("Rename");
        renameToken(token, s);
        endRefactor();
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 23 with ATEToken

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

the class STRefactorMenu method renameToken.

public boolean renameToken(ATEToken t, String name) {
    String attr = t.getAttribute();
    List<ATEToken> tokens = window.getTokens();
    boolean isArg = t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE;
    boolean renameRefRule = t.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || t.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL;
    if (renameRefRule) {
        for (int index = tokens.size() - 1; index > 0; index--) {
            ATEToken token = tokens.get(index);
            if (!token.getAttribute().equals(attr))
                continue;
            if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || token.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL) {
                mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
            }
        }
    } else if (isArg) {
        ElementTemplateRule rule = getRuleAtPosition(window.getCaretPosition());
        for (int index = tokens.size() - 1; index > 0; index--) {
            ATEToken token = tokens.get(index);
            if (!token.getAttribute().equals(attr))
                continue;
            if (rule.containsIndex(token.start)) {
                if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE) {
                    mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
                }
            }
        }
    } else {
        mutator.replace(t.getStartIndex(), t.getEndIndex(), name);
    }
    return true;
}
Also used : ElementTemplateRule(org.antlr.works.stringtemplate.element.ElementTemplateRule) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 24 with ATEToken

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

the class ATEStringTemplateSyntaxParser method tryMatchName.

private boolean tryMatchName() {
    ATEToken start = T(0);
    if (!matchID(0, "group"))
        return false;
    // After the 'group' comes the name of the template
    ATEToken name = T(0);
    if (!nextToken())
        return false;
    // match the optional super group
    matchSuperGroup();
    // match the optional interface/s
    matchInterface();
    // The next token must be a semi colon
    if (!matchSEMI(0))
        return false;
    this.name = new ElementTemplateName(name, start, T(-1));
    return true;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 25 with ATEToken

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

the class ATEStringTemplateSyntaxParser method tryMapDefinition.

private boolean tryMapDefinition() {
    ATEToken start = T(0);
    if (start == null)
        return false;
    String name = start.getAttribute();
    if (!matchID(0))
        return false;
    // should be '::=' right after id
    if (isDEFINED_TO_BE(0)) {
        // When a defineToBe is matched, we are at the beginning of the content of the template map
        nextToken();
    } else {
        // Invalid template map matching
        return false;
    }
    final ATEToken definedToBeToken = T(-1);
    currentTemplateMap = new ElementTemplateMapDefinition(name, start, definedToBeToken, null);
    // loop through all new lines
    while (matchNewline(0)) ;
    if (!tryMatchMapDefinitionBody(start))
        return false;
    return true;
}
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