Skip to content

Commit

Permalink
Fix OneOf compilation and tests (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Jan 7, 2022
1 parent 5dee9de commit 457caa4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/Parlot/Fluent/OneOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ public CompilationResult Compile(CompilationContext context)
Expression group = Expression.Empty();

// The list is reversed since the parsers are unwrapped
var parsers = kvp.Value.ToArray();
parsers.Reverse();

foreach (var parser in parsers)
foreach (var parser in kvp.Value.ToArray().Reverse())
{
var groupResult = parser.Build(context);

Expand All @@ -180,7 +177,7 @@ public CompilationResult Compile(CompilationContext context)
? Expression.Empty()
: Expression.Assign(value, groupResult.Value)
),
block
group
)
);
}
Expand Down
9 changes: 5 additions & 4 deletions test/Parlot.Tests/CompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,12 @@ public void SkipWhiteSpaceCompiledShouldResponseParseContextUseNewLines()
[Fact]
public void OneOfCompileShouldNotFailWithLookupConflicts()
{
var parser = Literals.Text("abc").Or(Literals.Text("ab")).Or(Literals.Text("a")).Compile();
var parser = OneOf(Literals.Text(">="), Literals.Text(">"), Literals.Text("<="), Literals.Text("<")).Compile();

Assert.True(parser.TryParse("a", out _));
Assert.True(parser.TryParse("ab", out _));
Assert.True(parser.TryParse("abc", out _));
Assert.Equal("<", parser.Parse("<"));
Assert.Equal("<=", parser.Parse("<="));
Assert.Equal(">", parser.Parse(">"));
Assert.Equal(">=", parser.Parse(">="));
}

[Fact]
Expand Down

0 comments on commit 457caa4

Please sign in to comment.