diff --git a/Source/Silverfly.Testing/SnapshotParserTestBase.cs b/Source/Silverfly.Testing/SnapshotParserTestBase.cs index 5ac4c72..a3a9f94 100644 --- a/Source/Silverfly.Testing/SnapshotParserTestBase.cs +++ b/Source/Silverfly.Testing/SnapshotParserTestBase.cs @@ -33,7 +33,11 @@ public static Task Test(string source) useStatementsAtToplevel: _options.UseStatementsAtToplevel, filename: _options.Filename); - var result = new TestResult(parsed.Tree.Accept(new PrintVisitor()), parsed.Document); + object result = parsed.Tree; + if (_options.OutputMode == OutputMode.Small) + { + result = new TestResult(parsed.Tree.Accept(new PrintVisitor()), parsed.Document); + } return Verify(result, _settings); } diff --git a/Source/Silverfly.Testing/TestOptions.cs b/Source/Silverfly.Testing/TestOptions.cs index 2241f34..cb640c9 100644 --- a/Source/Silverfly.Testing/TestOptions.cs +++ b/Source/Silverfly.Testing/TestOptions.cs @@ -1,5 +1,11 @@ namespace Silverfly.Testing; -public record TestOptions(bool UseStatementsAtToplevel, string Filename = "syntetic.dsl") +public enum OutputMode +{ + Small, + Full +} + +public record TestOptions(bool UseStatementsAtToplevel, string Filename = "test.src", OutputMode OutputMode = OutputMode.Small) { } diff --git a/Source/Silverfly.Testing/TestResult.cs b/Source/Silverfly.Testing/TestResult.cs index 211b2ea..2f4e0c9 100644 --- a/Source/Silverfly.Testing/TestResult.cs +++ b/Source/Silverfly.Testing/TestResult.cs @@ -2,6 +2,6 @@ namespace Silverfly.Testing; -public record TestResult(string ParsedTree, SourceDocument Document) +public record TestResult(object ParsedTree, SourceDocument Document) { } diff --git a/Source/Silverfly/Parselets/BlockParselet.cs b/Source/Silverfly/Parselets/BlockParselet.cs index 577df54..2c308b3 100644 --- a/Source/Silverfly/Parselets/BlockParselet.cs +++ b/Source/Silverfly/Parselets/BlockParselet.cs @@ -17,7 +17,11 @@ public AstNode Parse(Parser parser, Token token) while (!parser.Match(Terminator)) { var node = parser.ParseStatement(wrapExpressions); - children.Add(node with { Parent = block }); + + if (node is not InvalidNode) + { + children.Add(node with { Parent = block }); + } if (Seperator != null && parser.IsMatch(Seperator)) { diff --git a/Source/Silverfly/Parser.Helpers.cs b/Source/Silverfly/Parser.Helpers.cs index 04b0f9f..34f7599 100644 --- a/Source/Silverfly/Parser.Helpers.cs +++ b/Source/Silverfly/Parser.Helpers.cs @@ -67,12 +67,17 @@ public ImmutableList ParseSeperated(Symbol seperator, Symbol terminator do { - args.Add(Parse(bindingPower)); + var node = Parse(bindingPower); + + if (node is not InvalidNode) + { + args.Add(node); + } } while (Match(seperator)); Consume(terminator); - return args.ToImmutableList(); + return [.. args]; } public ImmutableList ParseList(Symbol terminator, int bindingPower = 0) @@ -81,12 +86,17 @@ public ImmutableList ParseList(Symbol terminator, int bindingPower = 0) while (!IsMatch(terminator)) { - args.Add(Parse(bindingPower)); + var node = Parse(bindingPower); + + if (node is not InvalidNode) + { + args.Add(node); + } } Consume(terminator); - return args.ToImmutableList(); + return [.. args]; } public ImmutableList ParseSeperated(Symbol seperator, int bindingPower = 0, params Symbol[] terminators) @@ -100,11 +110,16 @@ public ImmutableList ParseSeperated(Symbol seperator, int bindingPower do { - args.Add(Parse(bindingPower)); + var node = Parse(bindingPower); + + if (node is not InvalidNode) + { + args.Add(node); + } } while (Match(seperator)); Match(terminators); - return args.ToImmutableList(); + return [.. args]; } } diff --git a/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.received.txt b/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.received.txt deleted file mode 100644 index 7e0a8cb..0000000 --- a/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.received.txt +++ /dev/null @@ -1,9 +0,0 @@ -{ - $type: TestResult, - Tree: ((a) (b ? c : d), (e + f)); , - Document: { - Filename: syntethic.dsl, - Source: a(b ? c : d, e + f), - Messages: [] - } -} \ No newline at end of file diff --git a/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.verified.txt b/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.verified.txt index fda2de4..7e0a8cb 100644 --- a/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.verified.txt +++ b/Source/TestProject/TestResults/Tests.FunctionCall_Complex_Should_Pass.verified.txt @@ -1,69 +1,6 @@ { - $type: TranslationUnit, - Tree: { - $type: BlockNode, - SeperatorSymbol: ;, - Terminator: #eof, - Children: { - $type: ImmutableList, - $values: [ - { - $type: CallNode, - FunctionExpr: { - $type: NameNode, - Name: a, - Range: 1:1-1:1 - }, - Arguments: { - $type: ImmutableList, - $values: [ - { - $type: TernaryOperatorNode, - FirstExpr: { - $type: NameNode, - Name: b, - Range: 1:3-1:3 - }, - SecondExpr: { - $type: NameNode, - Name: c, - Range: 1:7-1:7 - }, - ThirdExpr: { - $type: NameNode, - Name: d, - Range: 1:11-1:11 - }, - Range: 1:3-1:5 - }, - { - $type: BinaryOperatorNode, - LeftExpr: { - $type: NameNode, - Name: e, - Range: 1:14-1:14 - }, - Operator: +, - RightExpr: { - $type: NameNode, - Name: f, - Range: 1:18-1:18 - }, - Range: 1:14-1:18 - } - ] - }, - Range: 1:1-1:2, - Parent: { - $type: BlockNode, - SeperatorSymbol: ;, - Terminator: #eof - } - } - ] - }, - Range: 1:1-1:23 - }, + $type: TestResult, + Tree: ((a) (b ? c : d), (e + f)); , Document: { Filename: syntethic.dsl, Source: a(b ? c : d, e + f),