Beispiel #1
0
        private bool ParseSeq(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (!ParseStmt(builder))
            {
                builder.Drop(start);
                return(false);
            }

            if (builder.Eof() || builder.GetTokenType() == SpringTokenType.RFBRACKET)
            {
                builder.Drop(start);
                return(true);
            }

            if (!ParseSeq(builder))
            {
                builder.Drop(start);
                return(false);
            }

            builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.SEQ, null);
            return(true);
        }
Beispiel #2
0
        private bool ParseHigh(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (!ParseIdent(builder))
            {
                builder.Drop(start);
                return(false);
            }

            if (builder.GetTokenType() == SpringTokenType.HIGH_BINOP)
            {
                AdvanceWithSpaces(builder);
                if (!ParseHigh(builder))
                {
                    builder.Drop(start);
                    return(false);
                }
                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.HIGH_BINOP, null);
                return(true);
            }

            builder.Drop(start);
            return(true);
        }
Beispiel #3
0
        private bool ParseAssign(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.IDENT)
            {
                builder.Drop(start);
                builder.Error("Missing variable");
                return(false);
            }

            AdvanceWithSpaces(builder);

            if (builder.GetTokenType() != SpringTokenType.ASSIGN)
            {
                builder.Drop(start);
                builder.Error("Missing ':='");
                return(false);
            }

            AdvanceWithSpaces(builder);

            if (!ParseLogic(builder))
            {
                builder.Drop(start);
                return(false);
            }

            builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.ASSIGN, null);
            return(true);
        }
Beispiel #4
0
        private bool ParseMedium(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (!ParseHigh(builder))
            {
                builder.Drop(start);
                return(false);
            }

            while (builder.GetTokenType() == SpringTokenType.MEDIUM_BINOP)
            {
                AdvanceWithSpaces(builder);

                if (!ParseHigh(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.MEDIUM_BINOP, null);
                builder.Precede(start);
            }

            builder.Drop(start);
            return(true);
        }
Beispiel #5
0
        private bool ParseLeftAssocBinOpSeq(Func <TokenNodeType, bool> matchOperator, Func <bool> parsePart, string ErrorMsg = "An operand expected")
        {
            var start = builder.Mark();

            if (!parsePart())
            {
                builder.Drop(start);
                return(false);
            }

            ParseLeftAssocBinOpTail(start, matchOperator, parsePart, ErrorMsg);

            builder.Drop(start);
            return(true);
        }
        private void ParseComments(PsiBuilder builder)
        {
            while (builder.GetTokenType() == GherkinTokenTypes.COMMENT)
            {
                var commentMarker = builder.Mark();
                var commentText   = builder.GetTokenText();
                builder.AdvanceLexer();
                var match = LanguagePattern.Match(commentText);
                if (match.Success)
                {
                    _lang = match.Groups["lang"].Value;
                    builder.DoneBeforeWhitespaces(commentMarker, GherkinNodeTypes.LANGUAGE_COMMENT, _lang);
                }
                else
                {
                    builder.Drop(commentMarker);
                }

                if (builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE ||
                    builder.GetTokenType() == GherkinTokenTypes.NEW_LINE)
                {
                    builder.AdvanceLexer();
                }
            }
        }
Beispiel #7
0
        private bool ParseLetBinding(PsiBuilder builder)
        {
            bool lexerAdvanced = false;
            var  mark          = builder.Mark();

            if (builder.GetTokenType() == SpringTokenType.LPAREN)
            {
                AdvanceSkippingWhitespace(builder);
                var identParsed = ParseIdentDecl(builder);
                SkipWhitespace(builder);

                var markExpr   = builder.Mark();
                var exprParsed = ParseExpr(builder);
                SkipWhitespace(builder);
                builder.Done(markExpr, SpringCompositeNodeType.BIND, null);

                lexerAdvanced = identParsed || exprParsed;

                if (builder.GetTokenType() == SpringTokenType.RPAREN)
                {
                    AdvanceSkippingWhitespace(builder);
                    builder.Drop(mark);
                }
                else
                {
                    builder.Error(mark, "Expect ')' to close binding");
                }
            }
            else
            {
                builder.Error(mark, "Expected binding!");
            }

            return(lexerAdvanced);
        }
Beispiel #8
0
        private bool ParseJsonObject(int mark)
        {
            if (!ExpectToken(JsonNewTokenNodeTypes.LBRACE))
            {
                myBuilder.Drop(mark);
                return(false);
            }

            if (GetTokenType() == JsonNewTokenNodeTypes.RBRACE)
            {
                Advance();
                Done(mark, ElementType.JSON_NEW_OBJECT);
                return(true);
            }

            ParseMembers();

            if (!ExpectToken(JsonNewTokenNodeTypes.RBRACE))
            {
                myBuilder.Drop(mark);
                return(false);
            }
            Done(mark, ElementType.JSON_NEW_OBJECT);
            return(true);
        }
Beispiel #9
0
        private bool ParseCondClause(PsiBuilder builder)
        {
            bool lexerAdvanced = false;

            if (builder.GetTokenType() == SpringTokenType.LPAREN)
            {
                bool leftExprParsed;
                var  mark = builder.Mark();
                AdvanceSkippingWhitespace(builder);
                if (builder.GetTokenType() == SpringTokenType.ELSE)
                {
                    AdvanceSkippingWhitespace(builder);
                    leftExprParsed = true;
                }
                else
                {
                    leftExprParsed = ParseExpr(builder);
                }

                SkipWhitespace(builder);
                var rightExprParsed = ParseExpr(builder);
                SkipWhitespace(builder);
                lexerAdvanced = leftExprParsed || rightExprParsed;

                if (builder.GetTokenType() == SpringTokenType.RPAREN)
                {
                    AdvanceSkippingWhitespace(builder);
                    builder.Drop(mark);
                }
                else
                {
                    builder.Error(mark, "Expect ')' in list!");
                }
            }
            else
            {
                builder.Error("Expected cond clause!");
            }

            return(lexerAdvanced);
        }
Beispiel #10
0
        private bool ParseStmt(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (builder.GetTokenType() == SpringTokenType.IF)
            {
                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '('");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseLogic(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing ')'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LFBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '{'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseSeq(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RFBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '}'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() == SpringTokenType.ELSE)
                {
                    AdvanceWithSpaces(builder);

                    if (builder.GetTokenType() != SpringTokenType.LFBRACKET)
                    {
                        builder.Drop(start);
                        builder.Error("Missing '{'");
                        return(false);
                    }

                    AdvanceWithSpaces(builder);

                    if (!ParseSeq(builder))
                    {
                        builder.Drop(start);
                        return(false);
                    }

                    if (builder.GetTokenType() != SpringTokenType.RFBRACKET)
                    {
                        builder.Drop(start);
                        builder.Error("Missing '}'");
                        return(false);
                    }

                    AdvanceWithSpaces(builder);
                }
                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.IF, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.FOR)
            {
                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '('");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseAssign(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.SEQ)
                {
                    builder.Drop(start);
                    builder.Error("Missing ';'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseLogic(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.SEQ)
                {
                    builder.Drop(start);
                    builder.Error("Missing ';'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseAssign(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing ')'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LFBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '{'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseSeq(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RFBRACKET)
                {
                    builder.Drop(start);
                    builder.Error("Missing '}'");
                    return(false);
                }

                AdvanceWithSpaces(builder);
                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.FOR, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.WRITE)
            {
                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LBRACKET)
                {
                    builder.RollbackTo(start);
                    builder.Error("Missing '('");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (!ParseLogic(builder))
                {
                    builder.Drop(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.RollbackTo(start);
                    builder.Error("Missing ')'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.WRITE, null);

                if (builder.GetTokenType() != SpringTokenType.SEQ)
                {
                    builder.Error("Missing ';'");
                    return(false);
                }

                AdvanceWithSpaces(builder);
                return(true);
            }

            if (!ParseAssign(builder))
            {
                builder.Drop(start);
                return(false);
            }

            if (builder.GetTokenType() != SpringTokenType.SEQ)
            {
                builder.Drop(start);
                builder.Error("Missing ';'");
                return(false);
            }

            AdvanceWithSpaces(builder);
            builder.Drop(start);
            return(true);
        }
Beispiel #11
0
        private bool ParseIdent(PsiBuilder builder)
        {
            var start = builder.Mark();

            if (builder.GetTokenType() == SpringTokenType.READ)
            {
                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.LBRACKET)
                {
                    builder.RollbackTo(start);
                    builder.Error("Missing '('");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.RollbackTo(start);
                    builder.Error("Missing ')'");
                    return(false);
                }

                AdvanceWithSpaces(builder);

                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.READ, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.NUMBER)
            {
                AdvanceWithSpaces(builder);
                builder.Done(start, SpringCompositeNodeType.NUMBER, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.IDENT)
            {
                AdvanceWithSpaces(builder);
                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.VARIABLE, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.STRING)
            {
                AdvanceWithSpaces(builder);
                builder.DoneBeforeWhitespaces(start, SpringCompositeNodeType.STRING, null);
                return(true);
            }

            if (builder.GetTokenType() == SpringTokenType.LBRACKET)
            {
                AdvanceWithSpaces(builder);

                if (!ParseLogic(builder))
                {
                    builder.RollbackTo(start);
                    return(false);
                }

                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.RollbackTo(start);
                    builder.Error("Missing ')'");
                    return(false);
                }

                AdvanceWithSpaces(builder);
                builder.Drop(start);
                return(true);
            }

            builder.Drop(start);
            builder.Error("Not ident");
            return(false);
        }