Parse tilde as missing output parameter marker

This commit is contained in:
Alexander Luzgarev 2018-04-02 17:03:45 +02:00
parent e5d0b0fe2e
commit d376d691c4
3 changed files with 25 additions and 0 deletions

View File

@ -387,5 +387,18 @@ namespace Parser.Tests
Assert.IsInstanceOf<BinaryOperationExpressionNode>(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<ArrayLiteralExpressionNode>(actual);
var f = (ArrayLiteralExpressionNode) actual;
Assert.AreEqual(3, f.Elements.Elements.Count);
Assert.IsInstanceOf<UnaryPrefixOperationExpressionNode>(f.Elements.Elements[1]);
Assert.AreEqual(text, actual.FullText);
}
}
}

View File

@ -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)

View File

@ -449,6 +449,7 @@ namespace Parser
get { yield break; }
}
public override string FullText => "";
}
public class CompoundNameNode : ExpressionNode