Detect end of text

Skip to first unread message

Rob Nichols

Feb 14, 2017, 5:15:05 PM2/14/17
to Treetop Development

I'm building a postal address parser, and one thing I am having a problem with is detecting when an element is the last text in the input. 

For example, I can parse these addresses:
  • 9 Some-Other ROAD, Bristol, BS7 8DB
  • 9 Some-Other ROAD, Bristol, Avon
  • 9 Some-Other ROAD, Bristol, Avon, BS7 8DB
Because I can identify the county (there are only a limited number) and postcode (it has a specific pattern). In each case 'Bristol' is correctly identified as the town.

However, I'm struggling with addresses which have neither a county nor postcode:
  • 9 Some-Other ROAD, Bristol
These are the town rules:

  rule town
((town_text county) / (town_text postcode) / (town_text "\n"))

  rule town_text
(word)* <TownNode>

I was hoping that the last option in `(town_text "\n")` would detect the case when the town was the last element - but I think it is failing as there is no carriage return at the end of the line (it just ends).

How do I detect the end of the text being parsed? Or how do I detect than an element is the last element?
Reply all
Reply to author
0 new messages