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

Examples of com.dci.intellij.dbn.language.common.element.TokenElementType


        return false;
    }

    public boolean isSameAs(LeafElementType elementType) {
        if (elementType instanceof TokenElementType) {
            TokenElementType token = (TokenElementType) elementType;
            return token.getTokenType() == getTokenType();
        }
        return false;
    }
View Full Code Here


        if (separatorTokenIds != null) {
            StringTokenizer tokenizer = new StringTokenizer(separatorTokenIds, ",");
            List<TokenElementType> separators = new ArrayList<TokenElementType>();
            while (tokenizer.hasMoreTokens()) {
                String separatorTokenId = tokenizer.nextToken().trim();
                TokenElementType separatorToken = new TokenElementTypeImpl(bundle, this, separatorTokenId, TokenElementType.SEPARATOR);
                        //bundle.getTokenElementType(separatorTokenId);
                separatorToken.setDefaultFormatting(separatorToken.isCharacter() ?
                        FormattingDefinition.NO_SPACE_BEFORE :
                        FormattingDefinition.ONE_SPACE_BEFORE);
                separators.add(separatorToken);
            }
            separatorTokens = separators.toArray(new TokenElementType[separators.size()]);
View Full Code Here

        for (LeafElementType leaf : leafs) {
            if (leaf instanceof IdentifierElementType) {
                IdentifierElementType identifierElementType = (IdentifierElementType) leaf;
                buffer.append(identifierElementType.getObjectTypeName());
            } else if (leaf instanceof TokenElementType) {
                TokenElementType tokenElementType = (TokenElementType) leaf;
                buffer.append(tokenElementType.getTokenType().getValue());
            }
            if (leaf != leafs[leafs.length-1]) {
                buffer.append('.');
            }
        }
View Full Code Here

        }
        return buffer.toString();
    }

    public boolean matchesPsiElement(QualifiedIdentifierPsiElement psiElement) {
        TokenElementType separatorToken = psiElement.getElementType().getSeparatorToken();
        PsiElement[] children = psiElement.getChildren();
        int index = 0;
        for (PsiElement child : children) {
            if (child instanceof LeafPsiElement) {
                LeafPsiElement leafPsiElement = (LeafPsiElement) child;
View Full Code Here

    protected void loadDefinition(Element def) throws ElementTypeDefinitionException {
        super.loadDefinition(def);
        ElementTypeBundle bundle = getElementBundle();
        String templateId = def.getAttributeValue("template");

        TokenElementType beginTokenElement;
        TokenElementType endTokenElement;
        if (StringUtil.isEmpty(templateId)) {
            String startTokenId = def.getAttributeValue("begin-token");
            String endTokenId = def.getAttributeValue("end-token");

            beginTokenElement = new TokenElementTypeImpl(bundle, this, startTokenId, "begin-token");
            endTokenElement = new TokenElementTypeImpl(bundle, this, endTokenId, "end-token");
        } else {
            WrapperElementTypeTemplate template = WrapperElementTypeTemplate.valueOf(templateId);
            beginTokenElement = new TokenElementTypeImpl(bundle, this, template.getBeginToken(), "begin-token");
            endTokenElement = new TokenElementTypeImpl(bundle, this, template.getEndToken(), "end-token");

            if (template.isBlock()) {
                beginTokenElement.setDefaultFormatting(FormattingDefinition.LINE_BREAK_AFTER);
                endTokenElement.setDefaultFormatting(FormattingDefinition.LINE_BREAK_BEFORE);
                setDefaultFormatting(FormattingDefinition.LINE_BREAK_BEFORE);
            }
        }

        wrappingDefinition = new WrappingDefinition(beginTokenElement, endTokenElement);
View Full Code Here

    public PsiBuilder.Marker mark(@Nullable ParsePathNode node){
        PsiBuilder.Marker marker = builder.mark();
        if (node != null) {
            WrappingDefinition wrapping = node.getElementType().getWrapping();
            if (wrapping != null) {
                TokenElementType beginElementType = wrapping.getBeginElementType();
                TokenType beginTokenType = beginElementType.getTokenType();
                while(builder.getTokenType() == beginTokenType) {
                    PsiBuilder.Marker beginTokenMarker = builder.mark();
                    advanceLexer(node.getParent(), true);
                    beginTokenMarker.done((IElementType) beginElementType);
                }
View Full Code Here

    public void markerDone(PsiBuilder.Marker marker, ElementType elementType, @Nullable ParsePathNode node) {
        if (marker != null) {
            if (node != null) {
                WrappingDefinition wrapping = node.getElementType().getWrapping();
                if (wrapping != null) {
                    TokenElementType endElementType = wrapping.getEndElementType();
                    TokenType endTokenType = endElementType.getTokenType();
                    while (builder.getTokenType() == endTokenType) {
                        PsiBuilder.Marker endTokenMarker = builder.mark();
                        advanceLexer(node, true);
                        endTokenMarker.done((IElementType) endElementType);
                    }
View Full Code Here

    public ParseResult parse(@NotNull ParsePathNode parentNode, boolean optional, int depth, ParserContext context) throws ParseException {
        ParserBuilder builder = context.getBuilder();
        logBegin(builder, optional, depth);
        ParsePathNode node = createParseNode(parentNode, builder.getCurrentOffset());

        TokenElementType separatorToken = getElementType().getSeparatorToken();

        PsiBuilder.Marker marker = builder.mark(node);
        int matchedTokens = 0;

        QualifiedIdentifierVariant variant = getMostProbableParseVariant(builder, node);
        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()) {
                Set<TokenType> expected = new THashSet<TokenType>();
                expected.add(separatorToken.getTokenType());
                ParseBuilderErrorHandler.updateBuilderError(expected, context);
                return stepOut(marker, depth, ParseResultType.PARTIAL_MATCH, matchedTokens, node, context);
            } else {
                return stepOut(marker, depth, ParseResultType.FULL_MATCH, matchedTokens, node, context);
            }
View Full Code Here

        return mostProbableVariant;
    }

    private QualifiedIdentifierVariant getMostProbableParseVariant_(ParserBuilder builder, ParsePathNode node) {

        TokenElementType separatorToken = getElementType().getSeparatorToken();

        QualifiedIdentifierVariant mostProbableVariant = null;
        int initialSiblingIndex = node.getCurrentSiblingIndex();

        try {
            for (LeafElementType[] variants : getElementType().getVariants()) {
                int offset = 0;
                //PsiBuilder.Marker marker = builder.mark();
                int matchedTokens = 0;
                for (int i=0; i< variants.length; i++) {
                    TokenType tokenType = builder.lookAhead(offset);
                    // if no mach -> consider as partial if not first element

                    node.setCurrentSiblingIndex(i);
                    if (match(variants[i], tokenType, node, true)) {
                        matchedTokens++;
                        offset++;


                        tokenType = builder.lookAhead(offset);
                        boolean isSeparator = tokenType == separatorToken.getTokenType();
                        boolean isFullMatch = matchedTokens == variants.length;
                        boolean isLastElement = i == variants.length - 1;

                        if (isLastElement) {
                            QualifiedIdentifierVariant variant = new QualifiedIdentifierVariant(variants, matchedTokens);
View Full Code Here

    private boolean match(LeafElementType leafElementType, TokenType tokenType, PathNode node, boolean leniant) {
        if (leafElementType instanceof IdentifierElementType) {
            return tokenType != null && (tokenType.isIdentifier() || (leniant && isSuppressibleReservedWord(tokenType, node)));
        } else if (leafElementType instanceof TokenElementType) {
            TokenElementType tokenElementType = (TokenElementType) leafElementType;
            return tokenElementType.getTokenType() == tokenType;
        }
        return false;
    }
View Full Code Here

TOP

Related Classes of com.dci.intellij.dbn.language.common.element.TokenElementType

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.