I'm using Sprache monadic parser to parse a DSL.
This is a snippet of my grammar:
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);
if I then use that with Statements.Parse(" ")
I get an exception saying that there was an unexpected end of input.
How can that be when the Statements
use the Many
operator, which AFAIK yields 0-n results.
" "
should return a Statements
instance containing 0 statements.
So how can the parser complain that there is an unexpected end of input? shouldnt it just conclude that there are no statements there? (no matter what funky stuff the different expressions that make up the statements do)