Exemplo n.º 1
0
        private bool ParseCompoundStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startCompoundStmt = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.BEGIN)
            {
                builder.RollbackTo(startCompoundStmt);
                return(false);
            }

            builder.AdvanceLexer();
            if (!ParseStmtList(builder))
            {
                builder.Error("Expected STATEMENT");
            }

            if (builder.GetTokenType() != SpringTokenType.END)
            {
                builder.Error("Expected \"end\"");
            }
            else
            {
                builder.AdvanceLexer();
            }

            builder.Done(startCompoundStmt, SpringCompositeNodeType.COMPOUND_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 2
0
        private bool ParseTerm(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int  startTerm = builder.Mark();
            bool res       = ParseFactor(builder);

            if (!res)
            {
                builder.Error("Expected FACTOR");
            }
            else
            {
                while (builder.GetTokenType() == SpringTokenType.FACTOR_OPS)
                {
                    builder.AdvanceLexer();
                    if (!ParseFactor(builder))
                    {
                        builder.Error("expected FACTOR");
                        break;
                    }
                }
            }
            builder.Done(startTerm, SpringCompositeNodeType.TERM, null);
            SkipWhitespace(builder);
            return(res);
        }
Exemplo n.º 3
0
        private bool ParseSimpleExpression(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int  startSimpleExpr = builder.Mark();
            bool res             = ParseTerm(builder);

            if (!res)
            {
                builder.Error("Expected TERM");
            }
            else
            {
                // throw new Exception("Token past Term: " + builder.GetTokenType().ToString() + " \"" + builder.GetTokenText() + '"');
                while (builder.GetTokenType() == SpringTokenType.TERM_OPS)
                {
                    builder.AdvanceLexer();
                    if (!ParseTerm(builder))
                    {
                        builder.Error("Expected TERM");
                        break;
                    }
                }
            }
            builder.Done(startSimpleExpr, SpringCompositeNodeType.SIMPLE_EXPR, null);
            SkipWhitespace(builder);
            return(res);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private bool ParseCaseHead(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            var curToken = builder.GetTokenType();

            if (!curToken.IsConstantLiteral && !curToken.IsStringLiteral)
            {
                return(false);
            }

            builder.AdvanceLexer();
            SkipWhitespace(builder);
            if (builder.GetTokenType() == SpringTokenType.DOUBLEDOTS)
            {
                builder.AdvanceLexer();
                SkipWhitespace(builder);
                curToken = builder.GetTokenType();
                if (!curToken.IsConstantLiteral && !curToken.IsStringLiteral)
                {
                    builder.Error("expected constant");
                }
                else
                {
                    builder.AdvanceLexer();
                }
            }

            SkipWhitespace(builder);
            while (builder.GetTokenType() == SpringTokenType.COMMA)
            {
                builder.AdvanceLexer();
                SkipWhitespace(builder);
                curToken = builder.GetTokenType();
                if (!curToken.IsConstantLiteral && !curToken.IsStringLiteral)
                {
                    break;
                }

                builder.AdvanceLexer();
                SkipWhitespace(builder);
                if (builder.GetTokenType() == SpringTokenType.DOUBLEDOTS)
                {
                    builder.AdvanceLexer();
                    SkipWhitespace(builder);
                    curToken = builder.GetTokenType();
                    if (!curToken.IsConstantLiteral && !curToken.IsStringLiteral)
                    {
                        builder.Error("expected constant");
                    }
                    else
                    {
                        builder.AdvanceLexer();
                    }
                }
                SkipWhitespace(builder);
            }
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 7
0
        private bool ParseWithStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.WITH)
            {
                return(false);
            }

            int mark = builder.Mark();

            builder.AdvanceLexer();
            SkipWhitespace(builder);

            if (builder.GetTokenType() != SpringTokenType.IDENTIFIER)
            {
                builder.Error("Expected variable identifier");
            }
            else
            {
                builder.AdvanceLexer();
            }

            SkipWhitespace(builder);
            while (builder.GetTokenType() == SpringTokenType.COMMA)
            {
                builder.AdvanceLexer();
                SkipWhitespace(builder);
                if (builder.GetTokenType() == SpringTokenType.IDENTIFIER)
                {
                    builder.AdvanceLexer();
                    SkipWhitespace(builder);
                }
                else
                {
                    builder.Error("Expected variable identifier");
                    break;
                }
            }

            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.DO)
            {
                builder.Error("expected 'do'");
            }
            else
            {
                builder.AdvanceLexer();
            }

            if (!ParseStatement(builder))
            {
                builder.Error("expected STMT");
            }

            builder.Done(mark, SpringCompositeNodeType.WITH_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 8
0
        private bool ParseFactor(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int  startFactor = builder.Mark();
            var  tt          = builder.GetTokenType();
            bool result      = false;

            if (ParseFunctionCall(builder))
            {
                result = true;
            }
            else if (ParseValueTypecast(builder))
            {
                result = true;
            }
            else if (ParseVariableTypecast(builder))
            {
                result = true;
            }
            else if (ParseSetCtor(builder))
            {
                result = true;
            }
            else if (ParseAddrOf(builder))
            {
                result = true;
            }
            else if (tt == SpringTokenType.IDENTIFIER || tt == SpringTokenType.NUMBER || tt == SpringTokenType.STRING)
            {
                builder.AdvanceLexer();
                result = true;
            }
            else if (tt == SpringTokenType.LBRACKET)
            {
                builder.AdvanceLexer();
                result = ParseExpression(builder);
                if (builder.GetTokenType() != SpringTokenType.RBRACKET)
                {
                    builder.Error("Expected )");
                }
                else
                {
                    builder.AdvanceLexer();
                    result = true;
                }
            }
            else
            {
                builder.Error("Expected FACTOR");
            }
            builder.Done(startFactor, SpringCompositeNodeType.FACTOR, null);
            SkipWhitespace(builder);
            return(result);
        }
Exemplo n.º 9
0
        private void ParseDefines(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            while (!builder.Eof())
            {
                var tt = builder.GetTokenType();
                if (tt == SpringTokenType.LPAREN)
                {
                    var start = builder.Mark();
                    AdvanceSkippingWhitespace(builder);
                    if (builder.GetTokenType() == SpringTokenType.DEFINE)
                    {
                        AdvanceSkippingWhitespace(builder);
                        ParseIdentDecl(builder);
                        SkipWhitespace(builder);
                        ParseExpr(builder);
                        SkipWhitespace(builder);
                    }
                    else
                    {
                        builder.Error("Expected definition!");
                    }

                    /*
                     * if (builder.GetTokenType() == SpringTokenType.RPAREN)
                     *  builder.AdvanceLexer();
                     * else
                     *  builder.Error("Expected ')' to close definition!");
                     *
                     * builder.Done(start, SpringCompositeNodeType.DEFINE, null);
                     */

                    SkipWhitespace(builder);
                    if (builder.GetTokenType() == SpringTokenType.RPAREN)
                    {
                        builder.AdvanceLexer();
                        builder.Done(start, SpringCompositeNodeType.DEFINE, null);
                    }
                    else
                    {
                        builder.Error(start, "Expected ')' to close definition!");
                    }
                }
                else
                {
                    var tokenType = builder.GetTokenType();
                    var mark      = builder.Mark();
                    builder.AdvanceLexer();
                    builder.Error(mark, "Expected '(', but got: " + tokenType.TokenRepresentation);
                }

                SkipWhitespace(builder);
            }
        }
Exemplo n.º 10
0
        private bool ParseForStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startForStmt = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.FOR)
            {
                builder.RollbackTo(startForStmt);
                return(false);
            }

            builder.AdvanceLexer();
            if (!ParseAssignStmt(builder))
            {
                builder.Error("Expected variable declaration");
            }

            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.CYCLE_DIR)
            {
                builder.Error("expected 'to' or 'downto'");
            }
            else
            {
                builder.AdvanceLexer();
            }

            if (!ParseExpression(builder))
            {
                builder.Error("Expected EXPRESSION");
            }

            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.DO)
            {
                builder.Error("expected 'do'");
            }
            else
            {
                builder.AdvanceLexer();
            }

            if (!ParseStatement(builder))
            {
                builder.Error("expected STATEMENT");
            }

            builder.Done(startForStmt, SpringCompositeNodeType.FOR_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 11
0
        private bool ParseFunctionCall(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startFuncCall = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.IDENTIFIER)
            {
                // throw new Exception("NOT AN IDENTIFIER");
                builder.RollbackTo(startFuncCall);
                return(false);
            }

            builder.AdvanceLexer();
            if (builder.GetTokenType() != SpringTokenType.LBRACKET)
            {
                builder.Done(startFuncCall, SpringCompositeNodeType.FUNC_CALL, null);
                return(true);
                // builder.RollbackTo(startFuncCall);
                // return false;
            }

            builder.AdvanceLexer();
            SkipWhitespace(builder);

            if (ParseExpression(builder))
            {
                while (builder.GetTokenType() == SpringTokenType.COMMA)
                {
                    builder.AdvanceLexer();
                    if (!ParseExpression(builder))
                    {
                        builder.Error("Expected EXPRESSION");
                        break;
                    }
                }
            }

            if (builder.GetTokenType() != SpringTokenType.RBRACKET)
            {
                builder.Error("Expected )");
            }
            else
            {
                builder.AdvanceLexer();
            }

            builder.Done(startFuncCall, SpringCompositeNodeType.FUNC_CALL, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 12
0
        private bool ParseAssignStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startAssignStmt = builder.Mark();

            if (!ParseVariableTypecast(builder))
            {
                if (builder.GetTokenType() != SpringTokenType.IDENTIFIER)
                {
                    builder.RollbackTo(startAssignStmt);
                    return(false);
                }

                builder.AdvanceLexer();
            }

            SkipWhitespace(builder);

            if (builder.GetTokenType() != SpringTokenType.ASSGN)
            {
                builder.RollbackTo(startAssignStmt);
                return(false);
            }

            builder.AdvanceLexer();
            SkipWhitespace(builder);

            if (!ParseExpression(builder))
            {
                builder.Error("Expected EXPRESSION");
            }
            builder.Done(startAssignStmt, SpringCompositeNodeType.ASSGN_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 13
0
        private bool ParseExpression(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int  startExpr = builder.Mark();
            bool res       = ParseSimpleExpression(builder);

            if (!res)
            {
                // builder.Error("Expected Expression");
                builder.RollbackTo(startExpr);
                return(false);
            }
            else
            {
                while (builder.GetTokenType() == SpringTokenType.REL_OPS)
                {
                    builder.AdvanceLexer();
                    if (!ParseSimpleExpression(builder))
                    {
                        builder.Error("Expected SIMPLE EXPRESSION");
                        break;
                    }
                }
            }
            builder.Done(startExpr, SpringCompositeNodeType.EXPR, null);
            SkipWhitespace(builder);
            return(res);
        }
Exemplo n.º 14
0
        private void ParseBlock(PsiBuilder builder)
        {
            while (!builder.Eof())
            {
                var tt = builder.GetTokenType();
                if (tt == SpringTokenType.LeftBrace)
                {
                    var start = builder.Mark();
                    builder.AdvanceLexer();
                    ParseBlock(builder);

                    if (builder.GetTokenType() != SpringTokenType.RightBrace)
                    {
                        builder.Error("Expected '}'");
                    }
                    else
                    {
                        builder.AdvanceLexer();
                    }

                    builder.Done(start, SpringCompositeNodeType.BLOCK, null);
                }
                else if (tt == SpringTokenType.RightBrace)
                {
                    return;
                }
                else
                {
                    builder.AdvanceLexer();
                }
            }
        }
Exemplo n.º 15
0
        private bool ParseRepeatStatement(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.REPEAT)
            {
                return(false);
            }

            int startRepeatStmt = builder.Mark();

            builder.AdvanceLexer();
            SkipWhitespace(builder);

            if (!ParseStatement(builder))
            {
                builder.Error("expected STMT");
            }
            SkipWhitespace(builder);
            while (builder.GetTokenType() == SpringTokenType.SEMICOLON)
            {
                builder.AdvanceLexer();
                if (!ParseStatement(builder))
                {
                    builder.Error("expected STMT");
                    break;
                }
            }
            SkipWhitespace(builder);

            if (builder.GetTokenType() != SpringTokenType.UNTIL)
            {
                builder.Error("Expected 'until'");
            }
            else
            {
                builder.AdvanceLexer();
            }

            if (!ParseExpression(builder))
            {
                builder.Error("expected EXPR");
            }

            builder.Done(startRepeatStmt, SpringCompositeNodeType.REPEAT_STMT, null);
            return(true);
        }
Exemplo n.º 16
0
        private bool ParseIfStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startIfStmt = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.IF)
            {
                builder.RollbackTo(startIfStmt);
                return(false);
            }

            builder.AdvanceLexer();
            if (!ParseExpression(builder))
            {
                builder.Error("Expected EXPRESSION");
            }

            if (builder.GetTokenType() != SpringTokenType.THEN)
            {
                builder.Error("Expected then");
            }
            else
            {
                builder.AdvanceLexer();
            }

            if (!ParseStatement(builder))
            {
                builder.Error("Expected STATEMENT");
            }

            if (builder.GetTokenType() == SpringTokenType.ELSE)
            {
                builder.AdvanceLexer();
                if (!ParseStatement(builder))
                {
                    builder.Error("Expected STATEMENT");
                }
            }

            builder.Done(startIfStmt, SpringCompositeNodeType.IF_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 17
0
        public void ParseFile()
        {
            var mark = MarkNoSkipWhitespace();

            ParseJsonValue();
            SkipWhitespaces();

            if (!myBuilder.Eof())
            {
                var errorMark = MarkNoSkipWhitespace();
                while (!myBuilder.Eof())
                {
                    Advance();
                }

                myBuilder.Error(errorMark, GetExpectedMessage("EOF"));
            }

            Done(mark, ElementType.JSON_NEW_FILE);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        private bool ParseWhileStmt(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            int startWhile = builder.Mark();

            if (builder.GetTokenType() != SpringTokenType.WHILE)
            {
                builder.RollbackTo(startWhile);
                return(false);
            }

            builder.AdvanceLexer();
            SkipWhitespace(builder);
            if (!ParseExpression(builder))
            {
                builder.Error("expected EXPR");
            }

            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.DO)
            {
                builder.Error("expected 'do'");
            }
            else
            {
                builder.AdvanceLexer();
            }

            SkipWhitespace(builder);
            if (!ParseStatement(builder))
            {
                builder.Error("expected STMT");
            }

            builder.Done(startWhile, SpringCompositeNodeType.WHILE_STMT, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 20
0
        private bool ParseCase(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            if (!ParseCaseHead(builder))
            {
                return(false);
            }
            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.COLON)
            {
                builder.Error("Expected ':'");
            }
            else
            {
                builder.AdvanceLexer();
            }
            SkipWhitespace(builder);
            if (!ParseStatement(builder))
            {
                builder.Error("Expected STMT");
            }

            return(true);
        }
Exemplo n.º 21
0
 // Leaves mark after ')'
 private void ParseList(PsiBuilder builder, Predicate <PsiBuilder> elementParser)
 {
     if (builder.GetTokenType() == SpringTokenType.LPAREN)
     {
         AdvanceSkippingWhitespace(builder);
         ParseSpaceSeparatedList(builder, elementParser);
         SkipWhitespace(builder);
         if (builder.GetTokenType() == SpringTokenType.RPAREN)
         {
             AdvanceSkippingWhitespace(builder);
         }
     }
     else
     {
         builder.Error("Expected list!");
     }
 }
Exemplo n.º 22
0
        private bool ParseAddrOf(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.ADDRESSOF)
            {
                return(false);
            }

            int start = builder.Mark();

            builder.AdvanceLexer();
            if (!ParseFactor(builder))
            {
                builder.Error("expected FACTOR");
            }
            builder.Done(start, SpringCompositeNodeType.ADDR_OF, null);
            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 23
0
        private static bool ParseIdentCommon(PsiBuilder builder, SpringCompositeNodeType type)
        {
            var lexerAdvanced = false;
            var start         = builder.Mark();
            var defineName    = builder.GetTokenType();

            if (defineName == SpringTokenType.IDENT)
            {
                lexerAdvanced = true;
                builder.AdvanceLexer();
                builder.Done(start, type, null);
            }
            else
            {
                builder.Error(start, "Expected identifier!");
            }

            return(lexerAdvanced);
        }
Exemplo n.º 24
0
        // Left mark on ')'
        private void ParseSpaceSeparatedList(PsiBuilder builder, Predicate <PsiBuilder> elementParser)
        {
            var mark = builder.Mark();

            while (builder.GetTokenType() != SpringTokenType.RPAREN && !builder.Eof())
            {
                if (!elementParser(builder) && !builder.Eof())
                {
                    builder.AdvanceLexer();
                }

                SkipWhitespace(builder);
            }

            if (builder.GetTokenType() != SpringTokenType.RPAREN)
            {
                builder.Error("Expect ')' in list!");
            }

            builder.Done(mark, SpringCompositeNodeType.LIST, null);
        }
Exemplo n.º 25
0
        private bool ParseSetGroup(PsiBuilder builder)
        {
            SkipWhitespace(builder);

            if (!ParseExpression(builder))
            {
                return(false);
            }

            if (builder.GetTokenType() == SpringTokenType.DOUBLEDOTS)
            {
                builder.AdvanceLexer();
                if (!ParseExpression(builder))
                {
                    builder.Error("Expected EXPR");
                }
            }

            SkipWhitespace(builder);
            return(true);
        }
Exemplo n.º 26
0
        private bool ParseExpr(PsiBuilder builder)
        {
            var lexerAdvanced = false;
            var markExpr      = builder.Mark();
            var expr          = builder.GetTokenType();

            if (expr == SpringTokenType.LIT)
            {
                lexerAdvanced = true;
                var mark = builder.Mark();
                builder.AdvanceLexer();
                builder.Done(mark, SpringCompositeNodeType.LIT, null);
            }
            else if (expr == SpringTokenType.IDENT)
            {
                lexerAdvanced = true;
                var mark = builder.Mark();
                builder.AdvanceLexer();
                builder.Done(mark, SpringCompositeNodeType.IDENT, null);
            }
            else if (expr == SpringTokenType.QUOTE)
            {
                var mark = builder.Mark();
                builder.AdvanceLexer();
                lexerAdvanced = ParseExpr(builder);
                builder.Done(mark, SpringCompositeNodeType.QUOTE, null);
            }
            else if (expr == SpringTokenType.LPAREN)
            {
                ParseBlock(builder);
            }
            else
            {
                builder.Error("Expected an expression!");
            }

            builder.Done(markExpr, SpringCompositeNodeType.EXPR, null);
            return(lexerAdvanced);
        }
Exemplo n.º 27
0
        public IFile ParseFile()
        {
            using (var def = Lifetime.Define())
            {
                var builder  = new PsiBuilder(myLexer, SpringFileNodeType.Instance, new TokenFactory(), def.Lifetime);
                var fileMark = builder.Mark();

                // ParseBlock(builder);
                // ParseExpression(builder);
                ParseCompoundStmt(builder);

                builder.Done(fileMark, SpringFileNodeType.Instance, null);

                if (!builder.Eof())
                {
                    builder.Error("Unexpected token");
                }

                var file = (IFile)builder.BuildTree();
                return(file);
            }
        }
Exemplo n.º 28
0
        private bool ParseSetCtor(PsiBuilder builder)
        {
            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.SET_START)
            {
                return(false);
            }

            int startCtor = builder.Mark();

            builder.AdvanceLexer();

            while (ParseSetGroup(builder))
            {
                if (builder.GetTokenType() == SpringTokenType.COMMA)
                {
                    builder.AdvanceLexer();
                }
                else
                {
                    break;
                }
            }

            SkipWhitespace(builder);
            if (builder.GetTokenType() != SpringTokenType.SET_END)
            {
                builder.Error("Expecting ]");
            }
            else
            {
                builder.AdvanceLexer();
            }

            builder.Done(startCtor, SpringCompositeNodeType.SET_CTOR, null);
            return(true);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
        }