I have a report server that needs to parse a string with some arguments controlling what is in the report.
I am using the parser library sprache to help with this. All is working fine except for one thing I'm stuck on.
I have a time filter that can be one of the following values: today, yesterday, last week, last month, none or custom.
It is custom that is giving me some grief. All of the others are just simple strings. Custom also has a from and to properties afterwards.
private static readonly Parser<DataFilterEntity> TimeFilter =
from filter in Parse.String("today").Return(DataFilterEntity.Today)
.Or(Parse.String("yesterday").Return(DataFilterEntity.Yesterday)
.Or(Parse.String("last week").Return(DataFilterEntity.LastWeek)
.Or(Parse.String("last month").Return(DataFilterEntity.LastMonth)
.Or(Parse.String("none").Return(DataFilterEntity.None))
.Or(Parse.String("custom").Return(DataFilterEntity.Custom())))))
select filter;
The custom line is the problem. I need to parse the "custom" string but then parse the from and to DateTime fields as well and pass them through to DataFilterEntity.Custom(from, to)
Any ideas much appreciated.