_Core/Lang/Plugins/Parser/TimePlugin.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.Lang;
namespace ComLib.Lang.Extensions
{
/* *************************************************************************
<doc:example>
// Time plugin provides a convenient way to represent time in fluent syntax.
var t = 12:30 pm;
if t is 12:30 pm then
print it's time to go to lunch!
</doc:example>
***************************************************************************/
/// <summary>
/// Combinator for handling dates. noon afternoon. evening, nite midnight
/// </summary>
public class TimePlugin : ExprPlugin
{
private static string[] _tokens = new string[] { "$NumberToken", "Noon", "noon", "midnight", "Midnight" };
private static Dictionary<string, TimeSpan> _aliases;
/// <summary>
/// Initialize
/// </summary>
static TimePlugin()
{
_aliases = new Dictionary<string, TimeSpan>();
_aliases["noon"] = new TimeSpan(12, 0, 0);
_aliases["Noon"] = new TimeSpan(12, 0, 0);
_aliases["midnight"] = new TimeSpan(0, 0, 0);
_aliases["Midnight"] = new TimeSpan(0, 0, 0);
}
/// <summary>
/// Initialize
/// </summary>
public TimePlugin()
{
_startTokens = _tokens;
}
/// <summary>
/// The grammer for the function declaration
/// </summary>
public override string Grammer
{
get
{
return "( ( noon | Noon | midnight | Midnight ) | ( <number> ( ':' <number> ){1,2} ( am | pm ) ) ";
}
后面还有 135 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
