Package com.dci.intellij.dbn.language.common.element.parser

Examples of com.dci.intellij.dbn.language.common.element.parser.ParseResult


    }

    public ParseResult parse(@NotNull ParsePathNode parentNode, boolean optional, int depth, ParserContext context) throws ParseException {
        ParserBuilder builder = context.getBuilder();
        PsiBuilder.Marker marker = builder.mark(null);
        ParseResult result = super.parse(parentNode, optional, depth, context);
        if (result.getType() == ParseResultType.NO_MATCH) {
            builder.markerDrop(marker);
        } else {
            builder.markerDone(marker, getElementType());
        }
        return result.getType() == ParseResultType.NO_MATCH ?
                ParseResult.createNoMatchResult() :
                ParseResult.createFullMatchResult(result.getMatchedTokens());
    }
View Full Code Here


                            elementType.isOptional(index) && (elementType.isLast(index) || elementType.isOptionalFromIndex(index)) ? ParseResultType.FULL_MATCH :
                            !elementType.isFirst(index) && !elementType.isOptionalFromIndex(index) && !elementType.isExitIndex(index) ? ParseResultType.PARTIAL_MATCH : ParseResultType.NO_MATCH;
                    return stepOut(marker, depth, resultType, matchedTokens, node, context);
                }

                ParseResult result = ParseResult.createNoMatchResult();
                // current token can still be part of the iterated element.
                //if (elementTypes[i].containsToken(tokenType)) {
                if (isDummyToken || elementTypes[index].getLookupCache().canStartWithToken(tokenType) || isSuppressibleReservedWord(tokenType, node)) {

                    //node = node.createVariant(builder.getCurrentOffset(), i);
                    result = elementTypes[index].getParser().parse(node, elementType.isOptional(index), depth + 1, context);

                    if (result.isMatch()) {
                        matchedTokens = matchedTokens + result.getMatchedTokens();
                        tokenType = builder.getTokenType();
                        isDummyToken = isDummyToken(builder.getTokenText());
                        matches++;
                    }
                }

                // not matched and not optional
                if (result.isNoMatch() && !elementType.isOptional(index)) {
                    boolean isWeakMatch = matches < 2 && matchedTokens < 3 && index > 1 && ignoreFirstMatch();
                   
                    if (elementType.isFirst(index) || elementType.isExitIndex(index) || isWeakMatch || matches == 0) {
                        //if (isFirst(i) || isExitIndex(i)) {
                        return stepOut(marker, depth, ParseResultType.NO_MATCH, matchedTokens, node, context);
View Full Code Here

        if (variant != null) {
            LeafElementType[] elementTypes = variant.getLeafs();

            int currentSiblingPosition = 0;
            for (LeafElementType elementType : elementTypes) {
                ParseResult result = elementType.getParser().parse(node, true, depth + 1, context);
                if (result.isNoMatch()) breakelse matchedTokens = matchedTokens + result.getMatchedTokens();

                if (elementType != elementTypes[elementTypes.length -1])  {
                    result = separatorToken.getParser().parse(node, true, depth + 1, context);
                    if (result.isNoMatch()) break; else matchedTokens = matchedTokens + result.getMatchedTokens();
                }
                node.incrementIndex(builder.getCurrentOffset());
            }

            if (variant.isIncomplete()) {
View Full Code Here

        if (tokenType!= null && !tokenType.isChameleon()) {
            String tokenText = builder.getTokenText();
            // TODO !!!! if elementType is an identifier: then BUILD VARIANTS!!!
            for (ElementType elementType : getElementType().getPossibleElementTypes()) {
                if (isDummyToken(tokenText) || elementType.getLookupCache().canStartWithToken(tokenType) || isSuppressibleReservedWord(tokenType, node)) {
                    ParseResult result = elementType.getParser().parse(node, true, depth + 1, context);
                    if (result.isMatch()) {
                        return stepOut(marker, depth, result.getType(), result.getMatchedTokens(), node, context);
                    }
                }
            }
            if (!optional) {
                //updateBuilderError(builder, this);
View Full Code Here

        int matchedTokens = 0;
        boolean isWrapped = false;

        // first try to parse the wrapped element directly, for supporting wrapped elements nesting
        if (isWrappingOptional) {
            ParseResult wrappedResult = wrappedElement.getParser().parse(node, optional, depth + 1, context);
            if (wrappedResult.isMatch()) {
                matchedTokens = matchedTokens + wrappedResult.getMatchedTokens();
                return stepOut(marker, depth, wrappedResult.getType(), matchedTokens, node, context);
            } else {
                builder.markerRollbackTo(marker, null);
                marker = builder.mark(null);
            }
        }

        // parse begin token
        ParseResult beginTokenResult = beginTokenElement.getParser().parse(node, optional, depth + 1, context);

        if (beginTokenResult.isMatch()) {
            isWrapped = true;
            matchedTokens++;
        }

        if (beginTokenResult.isMatch() || isWrappingOptional) {
            ParseResult wrappedResult = wrappedElement.getParser().parse(node, false, depth -1, context);
            matchedTokens = matchedTokens + wrappedResult.getMatchedTokens();

            if (isWrapped) {
                // check the end element => exit with partial match if not available
                ParseResult endTokenResult = endTokenElement.getParser().parse(node, false, depth -1, context);
                if (endTokenResult.isMatch()) {
                    matchedTokens++;
                    return stepOut(marker, depth, ParseResultType.FULL_MATCH, matchedTokens, node, context);
                } else {
                    return stepOut(marker, depth, wrappedResult.getType(), matchedTokens, node, context);
                }
View Full Code Here

        int elementCounter = 0;
        int matchedTokens = 0;
        //TokenType tokenType = (TokenType) builder.getTokenType();
        // check if the token objectType can be part of this iteration
        //if (isDummyToken(builder.getTokenText()) || isSuppressibleReservedWord(tokenType, node) || iteratedElementType.containsToken(tokenType)) {
            ParseResult result = iteratedElementType.getParser().parse(node, optional, depth + 1, context);


            // check first iteration element
            if (result.isMatch()) {
                if (node.isRecursive(node.getStartOffset())) {
                    return stepOut(marker, depth, ParseResultType.FULL_MATCH, matchedTokens, node, context);
                }
                while (true) {
                    elementCounter++;
                    // check separator
                    // if not matched just step out
                    if (separatorTokens != null) {
                        for (TokenElementType separatorToken : separatorTokens) {
                            result = separatorToken.getParser().parse(node, false, depth + 1, context);
                            matchedTokens = matchedTokens + result.getMatchedTokens();
                            if (result.isMatch()) break;
                        }

                        if (result.isNoMatch()) {
                            // if NO_MATCH, no additional separator found, hence then iteration should exit with MATCH
                            ParseResultType resultType = matchesElementsCount(elementCounter) ?
                                    ParseResultType.FULL_MATCH :
                                    ParseResultType.PARTIAL_MATCH;
                            return stepOut(marker, depth, resultType, matchedTokens, node, context);
                        } else {
                            node.setCurrentOffset(builder.getCurrentOffset());
                        }
                    }

                    // check consecutive iterated element
                    // if not matched, step out with error

                    result = iteratedElementType.getParser().parse(node, true, depth + 1, context);

                    if (result.isNoMatch()) {
                        // missing separators permit ending the iteration as valid at any time
                        if (separatorTokens == null) {
                            ParseResultType resultType = matchesElementsCount(elementCounter) ?
                                    ParseResultType.FULL_MATCH :
                                    ParseResultType.PARTIAL_MATCH;
                            return stepOut(marker, depth, resultType, matchedTokens, node, context);
                        } else {
                            boolean exit = advanceLexerToNextLandmark(parentNode, false, context);
                            if (exit){
                                return stepOut(marker, depth, ParseResultType.PARTIAL_MATCH, matchedTokens, node, context);
                            }
                        }
                    } else {
                        matchedTokens = matchedTokens + result.getMatchedTokens();
                    }
                }
            }
        //}
        if (!optional) {
View Full Code Here

TOP

Related Classes of com.dci.intellij.dbn.language.common.element.parser.ParseResult

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.