diff --git a/CanonSharp.Combinator/Abstractions/ParseResult.cs b/CanonSharp.Combinator/Abstractions/ParseResult.cs index 7f58852..e38be41 100644 --- a/CanonSharp.Combinator/Abstractions/ParseResult.cs +++ b/CanonSharp.Combinator/Abstractions/ParseResult.cs @@ -12,11 +12,6 @@ public abstract class ParseResult /// public abstract T Value { get; } - protected ParseResult() - { - - } - /// /// 在当前结果上应用下一个解析器 /// diff --git a/CanonSharp.Combinator/ParserBuilder.cs b/CanonSharp.Combinator/ParserBuilder.cs index 5d84120..b4bde54 100644 --- a/CanonSharp.Combinator/ParserBuilder.cs +++ b/CanonSharp.Combinator/ParserBuilder.cs @@ -157,7 +157,7 @@ public static class ParserBuilder /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Parser Choice(IEnumerable> parsers) - => parsers.Reverse().Aggregate((next, parser) => parser.Alternative(next)); + => parsers.Aggregate((result, parser) => result.Alternative(parser)); /// /// 按照给定的解析器组依次尝试 @@ -218,6 +218,5 @@ public static class ParserBuilder public static Parser> Take1Till(Parser termintor) => Any().Many1Till(termintor); - #endregion } diff --git a/CanonSharp.Combinator/Parsers/Bases/FixParser.cs b/CanonSharp.Combinator/Parsers/Bases/FixParser.cs index a8f3b3a..81b9bab 100644 --- a/CanonSharp.Combinator/Parsers/Bases/FixParser.cs +++ b/CanonSharp.Combinator/Parsers/Bases/FixParser.cs @@ -22,12 +22,3 @@ internal sealed class FixParser : Parser Func, ParseResult> continuation) => _parser.Run(state, continuation); } - -internal sealed class FixParser( - Func>, TParameter, Parser> func, - TParameter parameter) : Parser -{ - internal override ParseResult Run(TState state, - Func, ParseResult> continuation) - => func(p => new FixParser(func, p), parameter).Run(state, continuation); -} diff --git a/CanonSharp.Common/CanonSharp.Common.csproj b/CanonSharp.Common/CanonSharp.Common.csproj index fbfc2bd..4359b8a 100644 --- a/CanonSharp.Common/CanonSharp.Common.csproj +++ b/CanonSharp.Common/CanonSharp.Common.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs b/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs index 25c4eed..b70d3be 100644 --- a/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs +++ b/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs @@ -28,7 +28,8 @@ public class CombinatorParserTests : ParserTestsBase Parser> parser = Sequence(Token('a'), Token('b'), Token('c')); ValidateSuccessfulResult(parser, ['a', 'b', 'c'], "abc"); - parser = Sequence([Token('a'), Token('b'), Token('c')]); + IEnumerable> parsers = [Token('a'), Token('b'), Token('c')]; + parser = Sequence(parsers); ValidateSuccessfulResult(parser, ['a', 'b', 'c'], "abc"); } diff --git a/CanonSharp.Tests/CombinatorsTests/PrimitiveParserTests.cs b/CanonSharp.Tests/CombinatorsTests/PrimitiveParserTests.cs index 504af07..39d1825 100644 --- a/CanonSharp.Tests/CombinatorsTests/PrimitiveParserTests.cs +++ b/CanonSharp.Tests/CombinatorsTests/PrimitiveParserTests.cs @@ -52,6 +52,13 @@ public class PrimitiveParserTests : ParserTestsBase ValidateFailedResult(parser, "123"); } + [Fact] + public void SatisfyFailedTest() + { + Parser parser = Satisfy(char.IsLetter); + ValidateFailedResult(parser, ""); + } + [Fact] public void AnyTest() {