Search in sources :

Example 26 with ATEToken

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

the class ATEStringTemplateSyntaxParser method tryMatchTemplate.

private boolean tryMatchTemplate() {
    ATEToken start = T(0);
    if (start == null)
        return false;
    String name = start.getAttribute();
    if (!matchID(0))
        return false;
    currentArgs = new ArrayList<ATEToken>();
    currentArgNames.clear();
    // Match any optional argument
    matchArguments();
    // should be '::=' after arguments
    if (isDEFINED_TO_BE(0)) {
        // When a defineToBe is matched, we are at the beginning of the content of the template rule
        nextToken();
    } else {
        // Invalid template rule matching
        return false;
    }
    final ATEToken definedToBeToken = T(-1);
    currentTemplateRule = new ElementTemplateRule(this, name, start, definedToBeToken, null, currentArgs);
    // loop through all new lines
    while (matchNewline(0)) ;
    if (isOPEN_DOUBLE_ANGLE(0)) {
        if (!tryMatchTemplateBigString(start))
            return false;
    } else if (isDOUBLE_QUOTE(0)) {
        if (!tryMatchTemplateString(start))
            return false;
    } else {
        if (!tryMatchTemplateAssign(start))
            return false;
    }
    return true;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 27 with ATEToken

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

the class GrammarSyntaxParser method matchInternalRefInRule.

private boolean matchInternalRefInRule() {
    // Probably a reference inside the rule.
    ATEToken refToken = T(0);
    if (!matchID(0))
        return false;
    // Try to match the node token
    if (!matchOptionalNodeToken())
        return false;
    // foo.bar.boo
    while (isChar(0, ".") && isID(1)) {
        if (!skip(2))
            return false;
    }
    // Match any optional arguments
    matchArguments();
    // Now we have the reference token. Set the token flags
    addReference(refToken, false);
    return true;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 28 with ATEToken

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

the class GrammarSyntaxParser method matchRuleGroup.

/**
     * Matches the group token used to group rules in the rule lists
     *
     * @return true if a rule group is matched
     */
private boolean matchRuleGroup() {
    if (!isSingleComment(0))
        return false;
    ATEToken token = T(0);
    String comment = token.getAttribute();
    if (comment.startsWith(BEGIN_GROUP)) {
        groups.add(new ElementGroup(comment.substring(BEGIN_GROUP.length(), comment.length() - 1), rules.size() - 1, token));
        nextToken();
        return true;
    } else if (comment.startsWith(END_GROUP)) {
        groups.add(new ElementGroup(rules.size() - 1, token));
        nextToken();
        return true;
    }
    return false;
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 29 with ATEToken

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

the class GrammarSyntaxParser method matchInternalRefInBalancedToken.

private void matchInternalRefInBalancedToken(boolean matchInternalRef) {
    if (matchInternalRef && isChar(0, "$") && isID(1)) {
        T(0).type = GrammarSyntaxLexer.TOKEN_INTERNAL_REF;
        // Look for internal references, that is any ID preceeded by a $
        ATEToken ref = T(1);
        if (!addReference(ref, true)) {
            // The reference is not a label but a global reference.
            // The only issue with these global references is that some are not lexer or parser rules
            // but declared variables or ANTLR internal stuff. To skip these references, we
            // add all the internal references to a list of unknown reference and we check
            // after parsing if they are listed as a lexer or parser declaration. Otherwise, we
            // skip these references.
            unresolvedReferences.add(ref);
        }
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 30 with ATEToken

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

the class GrammarSyntaxParser method matchScope.

/**
     * Matches a scope declaration:
     *
     * scope [name] BLOCK
     *
     * where
     *  BLOCK = { ... }
     *
     * @return true if a scope is matched
     */
private boolean matchScope() {
    if (!isID(0, "scope"))
        return false;
    mark();
    // Must begin with the keyword 'scope'
    ATEToken start = T(0);
    if (!matchID(0, "scope"))
        return false;
    // Match the optional name
    matchID(0);
    // Match either the block or the semi
    if (isOpenBLOCK(0)) {
        ElementBlock block = new ElementBlock(start.getAttribute().toLowerCase(), start);
        ATEToken beginBlock = T(0);
        if (matchBalancedToken(ATESyntaxLexer.TOKEN_LCURLY, ATESyntaxLexer.TOKEN_RCURLY, null, true)) {
            beginBlock.type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
            T(-1).type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
            start.type = GrammarSyntaxLexer.TOKEN_BLOCK_LABEL;
            blocks.add(block);
            return true;
        }
    }
    rewind();
    return false;
}
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