From f03e80a1563aecef0f054536eb8c7312b785fd9a Mon Sep 17 00:00:00 2001 From: Acedia / Melancholy <85808999+TheGreatSageEqualToHeaven@users.noreply.github.com> Date: Tue, 15 Nov 2022 07:50:39 +0630 Subject: [PATCH 1/4] Fix #108 --- .../Lua/Portable/Syntax/SyntaxNormalizer.cs | 13 +++++++++++++ .../Test/Portable/Syntax/SyntaxNormalizerTests.cs | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs b/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs index 84ffbd9d..851d717a 100644 --- a/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs +++ b/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs @@ -957,6 +957,19 @@ private TReturn WithTempState(Func func, TArg arg) return base.VisitMethodCallExpression(node); } + // function_argument + // : expression_list_function_argument + // | string_function_argument + // | table_constructor_function_argument + // ; + public override SyntaxNode? VisitExpressionListFunctionArgument(ExpressionListFunctionArgumentSyntax node) + { + foreach (var expressionSeparator in node.Expressions.GetSeparators()) + AddSpaceAfterToken(expressionSeparator); + + return base.VisitExpressionListFunctionArgument(node); + } + // Visiting ParenthesizedExpressionSyntax is not necessary as it has no spacing. // Visiting ElementAccessExpressionSyntax is not necessary as it has no spacing. // Visiting MemberAccessExpressionSyntax is not necessary as it has no spacing. diff --git a/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs b/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs index 8c8387ee..df22fb54 100644 --- a/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs +++ b/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs @@ -6,6 +6,7 @@ using System.Text; using System.Text.RegularExpressions; using Loretta.CodeAnalysis.Lua.Test.Utilities; +using Loretta.Test.Utilities; using Xunit; using Xunit.Sdk; @@ -1223,6 +1224,17 @@ public void SyntaxNormalizer_CorrectlyRewritesTypes(string input, string expecte AssertNormalizeCore(type, expected); } + [Fact] + [WorkItem(108, "https://github.com/LorettaDevs/Loretta/issues/108")] + public void SyntaxNormalizer_CorrectlyInsertsExpressionSpaces() + { + var tree = ParseAndValidate("print(1, 2)", s_luaParseOptions); + var root = tree.GetRoot(); + + AssertNormalizeCore(root, "print(1, 2)"); + } + + #region Class Implementation Details private static void AssertNormalizeCore(SyntaxNode node, string expected) From 956b8a447857c08ef456da31ffa94ef2224c091d Mon Sep 17 00:00:00 2001 From: June <85808999+TheGreatSageEqualToHeaven@users.noreply.github.com> Date: Tue, 15 Nov 2022 07:54:40 +0630 Subject: [PATCH 2/4] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 7ecc218e..16d6369a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Fixed - Fixed `ContainedScopes` not being populated. +- Fixed NormalizeWhitespace not inserting spaces between expression list arguments. ## v0.2.10 ### Added From 586aae13faa344fb105fa0d86663683ca367b396 Mon Sep 17 00:00:00 2001 From: June <85808999+TheGreatSageEqualToHeaven@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:44:20 +0630 Subject: [PATCH 3/4] Change grammar definition --- src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs b/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs index 851d717a..823a0d1a 100644 --- a/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs +++ b/src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs @@ -957,11 +957,9 @@ private TReturn WithTempState(Func func, TArg arg) return base.VisitMethodCallExpression(node); } - // function_argument - // : expression_list_function_argument - // | string_function_argument - // | table_constructor_function_argument - // ; + // expression_list_function_argument + // : '(' (expression (',' expression)*)? ')' + // ; public override SyntaxNode? VisitExpressionListFunctionArgument(ExpressionListFunctionArgumentSyntax node) { foreach (var expressionSeparator in node.Expressions.GetSeparators()) From 950eeefe4447132cc84c56a9b60dec983fe17d4c Mon Sep 17 00:00:00 2001 From: June <85808999+TheGreatSageEqualToHeaven@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:44:54 +0630 Subject: [PATCH 4/4] Edit normalizer test --- src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs b/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs index df22fb54..937ceaee 100644 --- a/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs +++ b/src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs @@ -1228,7 +1228,7 @@ public void SyntaxNormalizer_CorrectlyRewritesTypes(string input, string expecte [WorkItem(108, "https://github.com/LorettaDevs/Loretta/issues/108")] public void SyntaxNormalizer_CorrectlyInsertsExpressionSpaces() { - var tree = ParseAndValidate("print(1, 2)", s_luaParseOptions); + var tree = ParseAndValidate("print(1,2)", s_luaParseOptions); var root = tree.GetRoot(); AssertNormalizeCore(root, "print(1, 2)");