diff --git a/Parser.Tests/MParserShould.cs b/Parser.Tests/MParserShould.cs index 6f0f235..5ceeda8 100644 --- a/Parser.Tests/MParserShould.cs +++ b/Parser.Tests/MParserShould.cs @@ -387,5 +387,18 @@ namespace Parser.Tests Assert.IsInstanceOf(f.Body); Assert.AreEqual(text, actual.FullText); } + + [Test] + public void ParseTildeAsResultReplacement() + { + var text = "[a, ~, b]"; + var sut = CreateParser(text); + var actual = sut.ParseExpression(); + Assert.IsInstanceOf(actual); + var f = (ArrayLiteralExpressionNode) actual; + Assert.AreEqual(3, f.Elements.Elements.Count); + Assert.IsInstanceOf(f.Elements.Elements[1]); + Assert.AreEqual(text, actual.FullText); + } } } \ No newline at end of file diff --git a/Parser/MParser.cs b/Parser/MParser.cs index c690fa2..5293c1f 100644 --- a/Parser/MParser.cs +++ b/Parser/MParser.cs @@ -598,6 +598,17 @@ namespace Parser var unaryTokenKind = ConvertToUnaryTokenKind(operation.Kind); var newPrecedence = GetPrecedence(unaryTokenKind); var operand = ParseSubExpression(options, newPrecedence); + if (operand == null) + { + if (options.ParsingArrayElements && operation.Kind == TokenKind.Not) + { + operand = Factory.EmptyExpression(); + } + else + { + throw new ParsingException($"Unexpected token {CurrentToken.Kind} at {operation.PureToken.Position}."); + } + } lhs = Factory.UnaryPrefixOperationExpression(Factory.Token(operation), operand); } else if (CurrentToken.Kind == TokenKind.At) diff --git a/Parser/SyntaxNode.cs b/Parser/SyntaxNode.cs index 27d5616..d538cd7 100644 --- a/Parser/SyntaxNode.cs +++ b/Parser/SyntaxNode.cs @@ -449,6 +449,7 @@ namespace Parser get { yield break; } } + public override string FullText => ""; } public class CompoundNameNode : ExpressionNode