From fbcba4edf27a45f6406edd78024e7e20af8516f8 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Wed, 4 Apr 2018 10:44:44 +0200 Subject: [PATCH] Parse tilde in function input description --- Parser.Tests/MParserShould.cs | 13 +++++++++++++ Parser/MParser.cs | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Parser.Tests/MParserShould.cs b/Parser.Tests/MParserShould.cs index 5ceeda8..c2b8b44 100644 --- a/Parser.Tests/MParserShould.cs +++ b/Parser.Tests/MParserShould.cs @@ -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(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(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)); + } } } \ No newline at end of file diff --git a/Parser/MParser.cs b/Parser/MParser.cs index a9fb988..2ab4a01 100644 --- a/Parser/MParser.cs +++ b/Parser/MParser.cs @@ -181,10 +181,18 @@ namespace Parser identifierTokens.Add(EatToken(TokenKind.Comma)); } - identifierTokens.Add(EatToken(TokenKind.Identifier)); + 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()