Permalink
Browse files

ExpressionSample - support DIM of one or more arrays

  • Loading branch information...
bobbymcr committed Apr 15, 2018
1 parent 07b7062 commit a40868f0bd6e9fff4cbe3a3e2a029329d494c148
@@ -16,6 +16,22 @@ public void OneItem(string input, string output)
Test.Good(input, output);
}
[InlineData("DIM R(1),S$(2)", "Dim(NumA(R, NumL(1)), StrA(S, NumL(2)))")]
[InlineData("DIM R(1,2),S$(A)", "Dim(NumA(R, NumL(1), NumL(2)), StrA(S, NumV(A)))")]
[Theory]
public void TwoItems(string input, string output)
{
Test.Good(input, output);
}
[InlineData("DIM R(1),S$(2),A12(3)", "Dim(NumA(R, NumL(1)), StrA(S, NumL(2)), NumA(A12, NumL(3)))")]
[InlineData("DIM ST$(1,2,3),F(5),SIX$(7)", "Dim(StrA(ST, NumL(1), NumL(2), NumL(3)), NumA(F, NumL(5)), StrA(SIX, NumL(7)))")]
[Theory]
public void ThreeItems(string input, string output)
{
Test.Good(input, output);
}
[InlineData("dim R(1)", "Dim(NumA(R, NumL(1)))")]
[InlineData("DiM r(1)", "Dim(NumA(R, NumL(1)))")]
[InlineData("dIm R(1)", "Dim(NumA(R, NumL(1)))")]
@@ -4,17 +4,22 @@
namespace GWParse.Statements
{
using System.Collections.Generic;
using System.Linq;
using GWParse.Expressions;
internal sealed class DimensionStatement : BasicStatement
{
private readonly BasicExpression a;
private readonly BasicExpression[] list;
public DimensionStatement(BasicExpression a)
public DimensionStatement(IEnumerable<BasicExpression> list)
{
this.a = a;
this.list = list.ToArray();
}
public override string ToString() => "Dim(" + this.a + ")";
public override string ToString()
{
return "Dim(" + string.Join<BasicExpression>(", ", this.list) + ")";
}
}
}
@@ -27,10 +27,15 @@ internal static class Stmt
from k in Parse.IgnoreCase("CLS")
select new ClearScreenStatement();
private static readonly Parser<IEnumerable<BasicExpression>> Arrays =
from head in Expr.AnyArray.Once()
from rest in Parse.Char(',').Then(_ => Expr.AnyArray).Many()
select head.Concat(rest);
private static readonly Parser<BasicStatement> Dim =
from k in Parse.IgnoreCase("DIM").Token()
from a in Expr.AnyArray
select new DimensionStatement(a);
from list in Arrays
select new DimensionStatement(list);
private static readonly Parser<BasicStatement> Assign =
from left in Expr.AnyVar

0 comments on commit a40868f

Please sign in to comment.