// installation hook to re-direct the output to some // arbitrary location public void redirect(LineConsumer redirection) { lock (line) { this.redirection = redirection; } }
public void Redirect(LineConsumer r) { lock (line) { this.redirection = r; } }
public void TestSingleLine() { { // simple int string[] strings = { "5" }; LineConsumer lines = new LineConsumer(strings); IScope scope = CreateScope(); Value value = EvalLines.Do(lines, scope); Assert.AreEqual(5, value.AsInt); } { // function string[] strings = { "subtract [ 7 4 ]" }; LineConsumer lines = new LineConsumer(strings); IScope scope = CreateScope(); Value value = EvalLines.Do(lines, scope); Assert.AreEqual(3, value.AsInt); } #if false { // functions string[] strings = { "subtract [ 7 subtract [ 15 11 ] ]" }; LineConsumer lines = new LineConsumer(strings); IScope scope = CreateScope(); Value value = EvalLines.Do(lines, scope); Assert.AreEqual(3, value.AsInt); } #endif }
public void TestNestedBodies() { { // 5 + (3 + 4) + 7 string[] strings = { "add", " 5", " add", " 3", " 4", " 7" }; LineConsumer lines = new LineConsumer(strings); IScope scope = CreateScope(); Value value = EvalLines.Do(lines, scope); Assert.AreEqual(19, value.AsInt); } }
public void TestBody() { { string[] strings = { "add", " 5", " 4" }; LineConsumer lines = new LineConsumer(strings); IScope scope = CreateScope(); Value value = EvalLines.Do(lines, scope); Assert.AreEqual(9, value.AsInt); } }
public PrintStream(bool iserr) : base() { this.iserr = iserr; this.line = new System.Text.StringBuilder(); this.redirection = null; }
internal override Value Eval(Value arg, IScope scope) { List<DelimiterList> body = ValueFunction.ExtractBody(arg); LineConsumer consumer = new LineConsumer(body); int total = 0; while (consumer.HasCurrent()) { Value value = EvalLines.DoOne(consumer, scope); total += value.AsInt; } return new ValueInt(total); }