Parse tilde in function input description

This commit is contained in:
Alexander Luzgarev 2018-04-04 10:44:44 +02:00
parent 98060d36b6
commit fbcba4edf2
2 changed files with 23 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Lexer;
using NUnit.Framework;
@ -400,5 +401,17 @@ namespace Parser.Tests
Assert.IsInstanceOf<UnaryPrefixOperationExpressionNode>(f.Elements.Elements[1]);
Assert.AreEqual(text, actual.FullText);
}
[Test]
public void ParseTildeAsFunctionInputReplacement()
{
var text = "function a(b, ~, c) end";
var sut = CreateParser(text);
var actual = sut.ParseStatement();
Assert.IsInstanceOf<FunctionDeclarationNode>(actual);
var f = (FunctionDeclarationNode) actual;
Assert.AreEqual(3, f.InputDescription.Parameters.Parameters.Count);
CollectionAssert.AreEqual(new[] { "b", "~", "c" }, f.InputDescription.Parameters.Parameters.Select(p => (p as TokenNode).Token.PureToken.LiteralText));
}
}
}

View File

@ -181,10 +181,18 @@ namespace Parser
identifierTokens.Add(EatToken(TokenKind.Comma));
}
if (CurrentToken.Kind == TokenKind.Not)
{
var notToken = EatToken();
identifierTokens.Add(notToken);
}
else
{
identifierTokens.Add(EatToken(TokenKind.Identifier));
}
}
return Factory.ParameterList(identifierTokens.Select(token => new TokenNode(token) as SyntaxNode).ToList());
return Factory.ParameterList(identifierTokens.Select(token => Factory.Token(token) as SyntaxNode).ToList());
}
private FunctionInputDescriptionNode ParseFunctionInputDescription()