From f752a387db352ec1ee602705638654471b982399 Mon Sep 17 00:00:00 2001 From: io Date: Fri, 31 May 2024 20:33:41 +0200 Subject: [PATCH] Made it possible to parse an empty list --- .../ExpressionParser/ExpressionParser.cs | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/source/ContractConfigurator/ExpressionParser/ExpressionParser.cs b/source/ContractConfigurator/ExpressionParser/ExpressionParser.cs index d4b5c7c9..a1a56881 100644 --- a/source/ContractConfigurator/ExpressionParser/ExpressionParser.cs +++ b/source/ContractConfigurator/ExpressionParser/ExpressionParser.cs @@ -530,33 +530,47 @@ public virtual TResult ParseList() try { List values = new List(); - values.Add(ParseStatement()); - 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()); + + token = null; + while (token == null) { - case TokenType.COMMA: - values.Add(ParseStatement()); - 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()); + 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> parser = GetParser>(this); if (token == null)