Package org.antlr.works.ate.syntax.misc

Examples of org.antlr.works.ate.syntax.misc.ATEToken


            return false;
        }
    }

    private boolean tryMatchName() {
        ATEToken start = T(0);

        // Check if the grammar has a type (e.g. lexer, parser, tree, etc)
        if(ElementGrammarName.isKnownType(start.getAttribute())) {
            if(!nextToken()) return false;
        }

        if(!matchID(0, "grammar")) return false;

        // After the type comes the name of the grammar
        ATEToken name = T(0);
        if(!nextToken()) return false;

        // The next token must be a semi colon
        if(!matchSEMI(0)) return false;
View Full Code Here


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

        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 first name
        if (matchID(0)) {
View Full Code Here

        if(label == null && !isID(0)) return false;
        if(label != null && !isID(0, label)) return false;

        mark();

        ATEToken start = T(0);
        int startIndex = getPosition();
        if(label == null) {
            if(!matchID(0)) return false;
        } else {
            if(!matchID(0, label)) return false;
        }

        ElementBlock block = new ElementBlock(start.getAttribute().toLowerCase(), start);
        ATEToken beginBlock = T(0);
        if(matchBalancedToken(ATESyntaxLexer.TOKEN_LCURLY, ATESyntaxLexer.TOKEN_RCURLY, block, true)) {
            beginBlock.type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
            T(-1).type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
            start.type = GrammarSyntaxLexer.TOKEN_BLOCK_LABEL;
            blocks.add(block);
View Full Code Here

            currentRule = null;
        }
    }

    private boolean tryMatchRule() {
        ATEToken start = T(0);
        if(start == null) return false;

        // Match any modifiers
        if(ruleModifiers.contains(start.getAttribute())) {
            // skip the modifier
            if(!nextToken()) return false;
        }

        // Match the name (it has to be an ID)
        ElementToken tokenName = (ElementToken) T(0);
        String name = tokenName.getAttribute();
        if(!matchID(0)) return false;

        // Match any optional argument
        matchArguments();

        // Match any comments
        while(true) {
            if(matchSingleComment(0)) continue;
            if(matchComplexComment(0)) continue;
            break;
        }

        // Match any returns
        if(matchID(0, "returns")) {
            matchArguments();
        }

        // Match any optional "!"
        matchChar(0, "!");

        // Match any comments, scopes and blocks
        while(true) {
            if(matchScopeUse()) continue;
            if(matchBlock()) continue;
            if(matchSingleComment(0)) continue;
            if(matchComplexComment(0)) continue;

            if(isCOLON(0)) {
                // When a colon is matched, we are at the beginning of the content of the rule
                nextToken();
                break;
            } else {
                // Invalid rule matching
                return false;
            }
        }

        // Parse the content of the rule (after the ':')
        final ATEToken colonToken = T(-1);
        final int oldRefsSize = references.size();
        final int oldBlocksSize = blocks.size();
        final int oldActionsSize = actions.size();
        currentRule = new ElementRule(this, name, start, colonToken, null);
        labels.clear();
View Full Code Here

        return true;
    }

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

    private boolean matchAction() {
        if(!isOpenBLOCK(0)) return false;

        // Match an action
        ATEToken t0 = T(0);
        ElementAction action = new ElementAction(this, currentRule, t0);
        if(matchBalancedToken(ATESyntaxLexer.TOKEN_LCURLY, ATESyntaxLexer.TOKEN_RCURLY, action, true)) {
            t0.type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
            T(-1).type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
View Full Code Here

    }

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

     * @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;
View Full Code Here

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

TOP

Related Classes of org.antlr.works.ate.syntax.misc.ATEToken

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.