Search in sources :

Example 16 with ATEToken

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

the class ATEStringTemplateSyntaxParser method resolveReferences.

/**
     * Resolves the unresolved references by looking at the set of declared references
     */
private void resolveReferences() {
    for (int i = unresolvedReferences.size() - 1; i >= 0; i--) {
        ATEToken ref = unresolvedReferences.get(i);
        if (declaredReferenceNames.contains(ref.getAttribute())) {
            ref.type = ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE;
            references.add(new ElementTemplateReference(refsToRules.get(ref), ref));
            unresolvedReferences.remove(i);
        }
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 17 with ATEToken

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

the class ATEStringTemplateSyntaxParser method tryMatchKey.

private boolean tryMatchKey() {
    if (matchID(0, "default"))
        return true;
    if (!isDOUBLE_QUOTE(0))
        return false;
    ATEToken start = T(0);
    start.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
    nextToken();
    while (true) {
        ATEToken t = T(0);
        if (isDOUBLE_QUOTE(0) || isNewline(0)) {
            t.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
            nextToken();
            return true;
        }
        t.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
        if (!nextToken())
            return false;
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 18 with ATEToken

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

the class ATEStringTemplateSyntaxParser method matchLiteral.

private boolean matchLiteral() {
    ATEToken t = T(0);
    if (t == null)
        return false;
    t.type = ATEStringTemplateSyntaxLexer.TOKEN_LITERAL;
    nextToken();
    return true;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 19 with ATEToken

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

the class ATESyntaxLexer method tokenize.

protected void tokenize() {
    while (nextCharacter()) {
        ATEToken token = customMatch();
        if (token != null) {
        // custom match matched something
        } else if (c0 == '\'')
            token = matchSingleQuoteString();
        else if (c0 == '\"')
            token = matchDoubleQuoteString();
        else if (c0 == '/' && c1 == '/')
            token = matchSingleComment();
        else if (c0 == '/' && c1 == '*')
            token = matchComplexComment();
        else if (isLetter())
            token = matchID();
        else if (c0 == '(')
            token = createNewToken(TOKEN_LPAREN);
        else if (c0 == ')')
            token = createNewToken(TOKEN_RPAREN);
        else if (c0 == '{')
            token = createNewToken(TOKEN_LCURLY);
        else if (c0 == '}')
            token = createNewToken(TOKEN_RCURLY);
        else if (c0 == '[')
            token = createNewToken(TOKEN_LBRACK);
        else if (c0 == ']')
            token = createNewToken(TOKEN_RBRACK);
        else if (c0 == ':')
            token = createNewToken(TOKEN_COLON);
        else if (c0 == ';')
            token = createNewToken(TOKEN_SEMI);
        else if (!isWhitespace())
            token = createNewToken(TOKEN_CHAR);
        addToken(token);
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 20 with ATEToken

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

the class GrammarRefactorMenu method replaceLiteralWithTokenLabel.

public void replaceLiteralWithTokenLabel() {
    StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_REPLACE_LITERALS);
    ATEToken token = window.getCurrentToken();
    if (token == null)
        return;
    if (token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
        XJAlert.display(window.getJavaContainer(), "Cannot Replace Literal With Token Label", "The current token is not a literal.");
        return;
    }
    window.selectTextRange(token.getStartIndex(), token.getEndIndex());
    String s = (String) JOptionPane.showInputDialog(window.getJavaContainer(), "Replace Literal '" + token.getAttribute() + "' with token label:", "Replace Literal With Token Label", JOptionPane.QUESTION_MESSAGE, null, null, "");
    if (s != null && !s.equals(token.getAttribute())) {
        beginRefactor("Replace Literal With Token Label");
        replaceLiteralTokenWithTokenLabel(token, s);
        endRefactor();
    }
}
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