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 () ); }
public bool TryParse(Tokens tokens, IScope scope, out IStatement statement) { tokens.SetMark (); Expression value = _expressionParser.ParseValue ( scope, tokens ); // Look ahead to see if this is an assignment if ( value is Variable && tokens.PullTokenIfEqual ( "=" ) ) { Assign assign = new Assign ( _executorFactory.GetAssignExecutor() ); assign.Ident = value as Variable; Expression expression = _expressionParser.ParseExpression ( scope, tokens ); assign.Expr = expression; statement = assign; return true; } // Failed to parse as assignment, rollback. tokens.RollbackToMark (); statement = null; return false; }