我正在使用Sprache monadic解析器来解析DSL.
这是我的语法片段:
public static readonly Parser<IExpression> TerminatedStatement =
from exp in Parse.Ref(() => Expression)
from _ in Parse.Char(';').Token()
select exp;
public static readonly Parser<IExpression> Statement =
Parse.Ref(() => TerminatedStatement)
.Or(Parse.Ref(() => InvocationStatement));
public static readonly Parser<Statements> Statements =
from statements in Statement.Many()
select new Statements(statements);
Run Code Online (Sandbox Code Playgroud)
如果我然后使用它,Statements.Parse(" ")我得到一个例外,说输入意外结束.
如何Statements使用Many运算符,AFAIK产生0-n结果.
" "应该返回一个Statements包含0个语句的实例.
那么解析器如何抱怨意外结束输入呢?难道它只是得出结论,那里没有陈述?(不管构成语句的不同表达方式有什么时髦的东西)
| 归档时间: |
|
| 查看次数: |
986 次 |
| 最近记录: |