Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OneOf compilation and tests #64

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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