This project has moved and is read-only. For the latest updates, please go here.

Newbie question

Feb 23, 2012 at 3:26 AM

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. :)


Feb 23, 2012 at 4:47 AM

try setting 

comment.Priority = TerminalPriority.MinimalPriority

Feb 23, 2012 at 2:08 PM

Woohoo!  that did the trick!   

There wasn't a MinimalPriority but I set it to Low and it worked great. 

Is there a help file or something that lists all the members and what they do?  I should have been able to figure this out myself.

Thanks again. :)