I need to parse a Time span based string. something line:
3 hrs 2 minutes baby sitting with sally.
here's the code but it's not working.
var line = new NonTerminal("Line");
var lines = new NonTerminal("Lines");
var data = new NonTerminal("data");
var HOUR = ToTerm("hours") | "hrs" | "hour" | "hr";
var MINS = ToTerm("minutes") | "mins" | "min";
NumberLiteral number = new NumberLiteral("number");
IdentifierTerminal identifier = new IdentifierTerminal("identifier");
NonTerminal TimeInHoursMins = new NonTerminal("TimeInHoursMins");
TimeInHoursMins.Rule = number + HOUR | number + MINS | number + HOUR + number + MINS;
var comment = new FreeTextLiteral("Comment", "\n");
line.Rule = TimeInHoursMins + comment + NewLine;
lines.Rule = MakeStarRule(lines, line);
data.Rule = lines + NewLineStar; //to allow empty lines after
this.Root = data;
this.LanguageFlags |= LanguageFlags.NewLineBeforeEOF;
The problem I'm having is that the 'Comment' is picking up the minutes too.
I want it to parse out the hours and minutes, and either shove everything after that into the 'comment' or just ignore everything else without error.
Any advice would be awesome. :)