Permalink
Browse files

ExpressionSample - support INPUT with no prompt

  • Loading branch information...
bobbymcr committed Apr 15, 2018
1 parent 6083c90 commit cccef25ae9d68a8ac4ff92938af50208719d6c23
@@ -0,0 +1,46 @@
// <copyright file="Input.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace GWParse.Test.Statements
{
using Xunit;
public sealed class Input
{
[InlineData("INPUT A", "Input(\"\", NumV(A))")]
[InlineData("INPUT A$", "Input(\"\", StrV(A))")]
[InlineData("INPUT A(1)", "Input(\"\", NumA(A, NumL(1)))")]
[InlineData("INPUT A$(1)", "Input(\"\", StrA(A, NumL(1)))")]
[Theory]
public void VarOnly(string input, string output)
{
Test.Good(input, output);
}
[InlineData("input A", "Input(\"\", NumV(A))")]
[InlineData("InPuT a", "Input(\"\", NumV(A))")]
[Theory]
public void IgnoreCase(string input, string output)
{
Test.Good(input, output);
}
[InlineData(" INPUT A", "Input(\"\", NumV(A))")]
[InlineData("INPUT A ", "Input(\"\", NumV(A))")]
[InlineData(" INPUT A ", "Input(\"\", NumV(A))")]
[Theory]
public void IgnoreSpaces(string input, string output)
{
Test.Good(input, output);
}
[InlineData("INPUTA")]
[InlineData("INPUT1")]
[Theory]
public void Invalid(string input)
{
Test.Bad(input);
}
}
}
@@ -0,0 +1,20 @@
// <copyright file="InputStatement.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace GWParse.Statements
{
using GWParse.Expressions;
internal sealed class InputStatement : BasicStatement
{
private readonly BasicExpression v;
public InputStatement(BasicExpression v)
{
this.v = v;
}
public override string ToString() => "Input(\"\", " + this.v + ")";
}
}
@@ -59,6 +59,11 @@ internal static class Stmt
private static readonly Parser<BasicStatement> Print =
PrintNMany.Or(PrintMany).Or(PrintEmpty);
private static readonly Parser<BasicStatement> Input =
from k in Kw.Input
from v in Expr.AnyVar
select new InputStatement(v);
private static readonly Parser<BasicStatement> Gosub =
from k in Kw.Gosub
from n in Parse.Number
@@ -71,7 +76,7 @@ internal static class Stmt
select new AssignmentStatement(left, right);
private static readonly Parser<BasicStatement> Any =
Rem.Or(Cls).Or(Dim).Or(Print).Or(Gosub).Or(Assign);
Rem.Or(Cls).Or(Dim).Or(Print).Or(Input).Or(Gosub).Or(Assign);
public static BasicStatement FromString(string input)
{
@@ -97,6 +102,7 @@ private static class Kw
public static readonly Parser<IEnumerable<char>> Cls = Parse.IgnoreCase("CLS");
public static readonly Parser<IEnumerable<char>> Dim = Parse.IgnoreCase("DIM").Token();
public static readonly Parser<IEnumerable<char>> Gosub = Parse.IgnoreCase("GOSUB ").Token();
public static readonly Parser<IEnumerable<char>> Input = Parse.IgnoreCase("INPUT ").Token();
public static readonly Parser<IEnumerable<char>> Print = Parse.IgnoreCase("PRINT ").Token();
public static readonly Parser<IEnumerable<char>> PrintE = Parse.IgnoreCase("PRINT");
public static readonly Parser<IEnumerable<char>> Rem = Parse.IgnoreCase("REM ");

0 comments on commit cccef25

Please sign in to comment.