Hello!
I'm new to parslet, and I've never used any parsers before now (and btw,
thanks for making this great library, it's been fun to use so far!) I'm
trying to make an interface where I can create calendar events by typing in
natural-like phrases. I've written rules to match dates, times, and entire
date ranges. Next I was going to build on top of this so that I can say
something like "lesson with John Doe on Friday at 2:00pm". The part that
I'm having trouble is matching the name.
I tried to do something like this:
rule(:word) { match('\\w').repeat }
rule(:attendee) { ( word | ( word >> ( space >> word ) ) ).as(:attendee) }
rule(:event_type) { ( str('lesson') | str('class') | str('interview')
).as(:event_type) }
rule(:event) do
event_type >> space >> ( str('with ') >> attendee >> space ).maybe >> (
range | datetime | date | time )
end
It is correctly matching "lesson with John Friday at 2:00pm", but it's not
matching "lesson with john doe friday at 2:00pm", and I'm having trouble
getting it to do this. I suppose there could even be multi-word last names
such as "ludwig van beethoven" but since I can't even get "john doe" to
match yet I figure there is no reason to try to get larger names to match
yet. :)
Is there a common strategy for trying to do something like this?
Thanks very much,
Cody