Detect end of text

17 views
Skip to first unread message

Rob Nichols

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

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
    element_separator
((town_text county) / (town_text postcode) / (town_text "\n"))
 
end


  rule town_text
   
(word)* <TownNode>
 
end

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
Forward
0 new messages