I'm struggling with a small parser using PetitParser2. Here is a fragment of some of the rules I'm defining but their behaviour is not as I could expect:
andKeyword := 'and' asPParser trim, #letter asPParser not. notKeyword := 'not' asPParser trim, #letter asPParser not. keyword := andKeyword / notKeyword. nonKeywordIdentifier := keyword not, #letter asPParser, #word asPParser star. word := nonKeywordIdentifier, #blank asPParser star. words := word star. The behaviour of the "nonKeywordIdentifier" is the expected:
identifier end parse: 'hello'. "It parses successfully" identifier end parse: 'and'. "It fails as 'and' is a keyword" However the "words" rule's behavior is the following:
words end parse: 'hello Pharo'. "It parses successfully" words end parse: 'hello and bye'. "It parses, when I would expect it fails because 'and' is a keyword" I don't understand why the "words" rule works this way, but I'm starting with PetitParser. Any suggestions?
PS: Sorry for the cross-posting in the Pharo users mailing list.
Thank you.