Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to parse an empty list #43

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading