chore: keyword 'div' instead of 'divide'.
rename 'ScannerTest' to 'ScannerTests'.
This commit is contained in:
parent
65d6b9794c
commit
fee62ec289
|
@ -22,7 +22,7 @@ public interface IFailedResult<TToken, out T> : IParseResult<TToken, T>
|
|||
/// <summary>
|
||||
/// 解析失败的异常
|
||||
/// </summary>
|
||||
public ParseException Exception => new(ToString());
|
||||
public ParseException Exception => new(Message);
|
||||
|
||||
/// <summary>
|
||||
/// 转换该失败结果的类型
|
||||
|
@ -42,6 +42,4 @@ public interface IFailedResult<TToken, out T> : IParseResult<TToken, T>
|
|||
TResult IParseResult<TToken, T>.CaseOf<TResult>(Func<ISuccessfulResult<TToken, T>, TResult> successfulHandler,
|
||||
Func<IFailedResult<TToken, T>, TResult> failedHandler)
|
||||
=> failedHandler(this);
|
||||
|
||||
string IParseResult<TToken, T>.ToString() => $"Parse Failed: {Message}";
|
||||
}
|
||||
|
|
|
@ -40,6 +40,4 @@ public interface IParseResult<TToken, out T>
|
|||
/// <returns>最后的解析结果</returns>
|
||||
public TResult CaseOf<TResult>(Func<ISuccessfulResult<TToken, T>, TResult> successfulHandler,
|
||||
Func<IFailedResult<TToken, T>, TResult> failedHandler);
|
||||
|
||||
public string ToString();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,4 @@ public interface ISuccessfulResult<TToken,out T> : IParseResult<TToken, T>
|
|||
TResult IParseResult<TToken, T>.CaseOf<TResult>(Func<ISuccessfulResult<TToken, T>, TResult> successfulHandler,
|
||||
Func<IFailedResult<TToken, T>, TResult> failedHandler)
|
||||
=> successfulHandler(this);
|
||||
|
||||
string IParseResult<TToken, T>.ToString() => Value?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
|
|
@ -19,4 +19,6 @@ internal sealed class FailedResultWithError<TToken, TState, T>(TState state) : I
|
|||
{
|
||||
return new FailedResultWithError<TToken, TState, TNext>(state);
|
||||
}
|
||||
|
||||
public override string ToString() => $"Parse failed: {Message}.";
|
||||
}
|
||||
|
|
|
@ -10,15 +10,18 @@ namespace CanonSharp.Combinator.Results;
|
|||
/// <typeparam name="TToken">输入流类型</typeparam>
|
||||
/// <typeparam name="TState">当前输入流状态的类型</typeparam>
|
||||
/// <typeparam name="T">解析结果的类型</typeparam>
|
||||
public class FailedResultWithException<TToken, TState, T>(Exception exception, TState state) : IFailedResult<TToken, T>
|
||||
internal sealed class FailedResultWithException<TToken, TState, T>(Exception exception, TState state)
|
||||
: IFailedResult<TToken, T>
|
||||
where TState : IReadState<TToken, TState>
|
||||
{
|
||||
public IReadState<TToken> State => state;
|
||||
|
||||
public ParseException Exception => new(ToString(), exception);
|
||||
public ParseException Exception => new(Message, exception);
|
||||
|
||||
public string Message => $"Exception occured: {exception}.";
|
||||
|
||||
public IFailedResult<TToken, TNext> Convert<TNext>()
|
||||
=> new FailedResultWithException<TToken, TState, TNext>(exception, state);
|
||||
|
||||
public override string ToString() => $"Parse failed: {Message}.";
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace CanonSharp.Combinator.Results;
|
|||
/// <typeparam name="TToken">输入流的类型</typeparam>
|
||||
/// <typeparam name="TState">读取状态类型</typeparam>
|
||||
/// <typeparam name="T">解析结果的类型</typeparam>
|
||||
internal sealed class FailedResultWithMessage<TToken, TState, T>(string message, TState state) : IFailedResult<TToken, T>
|
||||
internal sealed class FailedResultWithMessage<TToken, TState, T>(string message, TState state)
|
||||
: IFailedResult<TToken, T>
|
||||
where TState : IReadState<TToken, TState>
|
||||
{
|
||||
public IReadState<TToken> State => state;
|
||||
|
@ -21,4 +22,6 @@ internal sealed class FailedResultWithMessage<TToken, TState, T>(string message,
|
|||
{
|
||||
return new FailedResultWithMessage<TToken, TState, TNext>(message, state);
|
||||
}
|
||||
|
||||
public override string ToString() => $"Parse failed: {Message}.";
|
||||
}
|
||||
|
|
|
@ -22,4 +22,6 @@ internal sealed class InternalSuccessfulResult<TToken, TState, T>(T result, TSta
|
|||
|
||||
public IParseResult<TToken, TResult> Map<TResult>(Func<T, TResult> map)
|
||||
=> new InternalSuccessfulResult<TToken, TState, TResult>(map(Value), state);
|
||||
|
||||
public override string ToString() => Value?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public sealed class LexicalScanner
|
|||
StringIgnoreCase("real"),
|
||||
StringIgnoreCase("boolean"),
|
||||
StringIgnoreCase("char"),
|
||||
StringIgnoreCase("divide"),
|
||||
StringIgnoreCase("div"),
|
||||
StringIgnoreCase("not"),
|
||||
StringIgnoreCase("mod"),
|
||||
StringIgnoreCase("and"),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using CanonSharp.Pascal.Scanner;
|
||||
using CanonSharp.Tests.Utils;
|
||||
|
||||
namespace CanonSharp.Tests.ScannerTest;
|
||||
namespace CanonSharp.Tests.ScannerTests;
|
||||
|
||||
public class LexicalParserTests : LexicalTestBase
|
||||
{
|
|
@ -4,7 +4,7 @@ using CanonSharp.Combinator.Extensions;
|
|||
using CanonSharp.Pascal.Scanner;
|
||||
using CanonSharp.Tests.Utils;
|
||||
|
||||
namespace CanonSharp.Tests.ScannerTest;
|
||||
namespace CanonSharp.Tests.ScannerTests;
|
||||
|
||||
public class LexicalTokenParserTest : LexicalTestBase
|
||||
{
|
||||
|
@ -27,6 +27,11 @@ public class LexicalTokenParserTest : LexicalTestBase
|
|||
[InlineData("true")]
|
||||
[InlineData("false")]
|
||||
[InlineData("while")]
|
||||
[InlineData("div")]
|
||||
[InlineData("not")]
|
||||
[InlineData("mod")]
|
||||
[InlineData("and")]
|
||||
[InlineData("or")]
|
||||
public void KeywordParserTest(string literalValue)
|
||||
{
|
||||
IParser<char, LexicalToken> keyword = LexicalScanner.KeywordParser();
|
Loading…
Reference in New Issue
Block a user