コード例 #1
0
ファイル: EffectParser.cs プロジェクト: nikolaiklimov/SharpDX
        private Ast.MethodExpression ParseMethodExpression()
        {
            if (!ExpectNext(TokenType.LeftParent))
                return null;

            var methodExp = new Ast.MethodExpression {Span = currentToken.Span};

            int expectedArguments = 0;
            bool continueParsing = true;
            do
            {
                var token = NextToken();
                switch (token.Type)
                {
                    case TokenType.RightParent:
                        continueParsing = false;
                        break;

                    default:
                        var nextValue = ParseExpression();
                        if (nextValue == null)
                        {
                            continueParsing = false;
                        }
                        else
                        {
                            methodExp.Arguments.Add(nextValue);

                            NextToken();

                            if (currentToken.Type == TokenType.RightParent)
                            {
                                continueParsing = false;
                            }
                            else if (currentToken.Type == TokenType.Comma)
                            {
                                expectedArguments += (expectedArguments == 0) ? 2 : 1;
                            }
                            else
                            {
                                Logger.Error("Unexpected token [{0}]. Expecting tokens [',', ')']", currentToken.Span, currentToken);
                                continueParsing = false;
                            }
                        }
                        break;
                }
            } while (continueParsing);

            int argCount = methodExp.Arguments.Count;
            if (expectedArguments > 0 && expectedArguments != argCount)
                Logger.Error("Unexpected number of commas.", currentToken.Span);

            return methodExp;
        }
コード例 #2
0
ファイル: EffectParser.cs プロジェクト: oeoen/SharpDX
        private Ast.MethodExpression ParseMethodExpression()
        {
            if (!ExpectNext(TokenType.LeftParent))
            {
                return(null);
            }

            var methodExp = new Ast.MethodExpression {
                Span = currentToken.Span
            };

            int  expectedArguments = 0;
            bool continueParsing   = true;

            do
            {
                var token = NextToken();
                switch (token.Type)
                {
                case TokenType.RightParent:
                    continueParsing = false;
                    break;

                default:
                    var nextValue = ParseExpression();
                    if (nextValue == null)
                    {
                        continueParsing = false;
                    }
                    else
                    {
                        methodExp.Arguments.Add(nextValue);

                        NextToken();

                        if (currentToken.Type == TokenType.RightParent)
                        {
                            continueParsing = false;
                        }
                        else if (currentToken.Type == TokenType.Comma)
                        {
                            expectedArguments += (expectedArguments == 0) ? 2 : 1;
                        }
                        else
                        {
                            Logger.Error("Unexpected token [{0}]. Expecting tokens [',', ')']", currentToken.Span, currentToken);
                            continueParsing = false;
                        }
                    }
                    break;
                }
            } while (continueParsing);

            int argCount = methodExp.Arguments.Count;

            if (expectedArguments > 0 && expectedArguments != argCount)
            {
                Logger.Error("Unexpected number of commas.", currentToken.Span);
            }

            return(methodExp);
        }