Пример #1
0
        public void TestSetRollbackPoint()
        {
            Tokens tokens = new Tokens();
            tokens.AddTokens ( new string[] { "1", "2", "3", "4", "5" } );

            Assert.AreEqual ( "1", tokens.PeekToken () );

            tokens.SetMark ();
            Assert.AreEqual ( "1", tokens.PullToken () );
            Assert.AreEqual ( "2", tokens.PullToken () );
            Assert.AreEqual ( "3", tokens.PullToken () );

            tokens.RollbackToMark ();
            Assert.AreEqual ( "1", tokens.PeekToken () );
        }
Пример #2
0
        public bool TryParse(Tokens tokens, IScope scope, out IStatement statement)
        {
            // This is a block call
            Variable variable = new Variable ( _executorFactory.GetVariableExecutor() );
            variable.Scope = scope;
            variable.Ident = tokens.PullToken ();

            // Check if there is an indexer into the variable
            if (tokens.PeekToken () == "[")
            {
                tokens.PullToken ();
                variable.Indexer = _expressionParser.ParseExpression ( scope, tokens );
                tokens.RemoveNextToken ("]");
            }

            if ( tokens.NextTokenIs("(") )
            {
                // Parse the parameters..
                variable.Parameters = _expressionParser.ParseArray( scope, tokens ) as ArrayExpr;
            }

            statement = variable;
            return true;
        }
Пример #3
0
        /// <summary>
        /// Value is a constant string, number or variable name.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        public Expression ParseValue( IScope scope, Tokens tokens )
        {
            Expression value = null;

            if ( tokens.NextTokenIs ( BeginBlock ) )
            {
                value = _blockParser.GetBlock ( scope, tokens );
            }
            else if ( tokens.PeekToken().StartsWith ( "'" ) && tokens.PeekToken().EndsWith ( "'" ) )
            {
                string literal = tokens.PullToken().Trim ( '\'' );
                value = new StringLiteral
                {
                    Value = literal
                };
            }
            else if ( tokens.PeekToken().IsNumber () )
            {
                value = new NumberLiteral
                {
                    Value = double.Parse ( tokens.PullToken() )
                };
            }
            else if ( tokens.NextTokenIs(BeginArray) )
            {
                return this.ParseArray ( scope, tokens );
            }
            else
            {
                var variable = new Variable ( _executorFactory.GetVariableExecutor () );
                variable.Scope = scope;
                variable.Ident = tokens.PullToken();

                // Check if there is an indexer into the variable
                if (tokens.PeekToken () == "[")
                {
                    tokens.PullToken ();
                    variable.Indexer = ParseExpression ( scope, tokens );
                    tokens.RemoveNextToken ("]");
                }

                value = variable;
            }

            return value;
        }