Skip to content

Commit

Permalink
Make it possible to parse an empty list (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
IO5 authored Jul 3, 2024
1 parent 26c7c08 commit 3dc1427
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions source/ContractConfigurator/ExpressionParser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,33 +530,47 @@ public virtual TResult ParseList<TResult>()
try
{
List<T> values = new List<T>();
values.Add(ParseStatement<T>());

Token token = null;
while (token == null)
string savedExpression = expression;

Token token = ParseToken();
if (token == null)
{
token = ParseToken();
if (token == null)
{
throw new ArgumentException("Expected ',' or ']', got end of statement.");
}
throw new ArgumentException("Unexpected end of statement while parsing list.");
}

switch (token.tokenType)
if (token.tokenType != TokenType.LIST_END)
{
expression = savedExpression;

values.Add(ParseStatement<T>());

token = null;
while (token == null)
{
case TokenType.COMMA:
values.Add(ParseStatement<T>());
token = null;
break;
case TokenType.LIST_END:
break;
default:
expression = token.sval + expression;
throw new ArgumentException(StringBuilderCache.Format("Unexpected value: {0}", token.sval));
token = ParseToken();
if (token == null)
{
throw new ArgumentException("Expected ',' or ']', got end of statement.");
}

switch (token.tokenType)
{
case TokenType.COMMA:
values.Add(ParseStatement<T>());
token = null;
break;
case TokenType.LIST_END:
break;
default:
expression = token.sval + expression;
throw new ArgumentException(StringBuilderCache.Format("Unexpected value: {0}", token.sval));
}
}
}

// See what's next to parse
string savedExpression = expression;
savedExpression = expression;
token = ParseToken();
ExpressionParser<List<T>> parser = GetParser<List<T>>(this);
if (token == null)
Expand Down

0 comments on commit 3dc1427

Please sign in to comment.