From: Clifford Heath Date: 2008-01-29T14:29:56+09:00 Subject: Re: Treetop parser (or PEG in general?) questions Clifford Heath wrote: > The keyword rule should only be called when you know you've just seen > something that can't be part of a word - never after an arbitrary > character. > rule vhdl_file_wth_port > non_port* port_decl non_port* > end > > rule non_port > comment / string / white / !port alphanumeric+ > end Hmmm, it looks like I broke my own rule here, but I didn't. There's no need to worry about non_port choosing the alphanumeric alternative, but stopping just in time to see that the AN string contains the word "port", because the + is greedy. If "alphanumeric+" sees the "port" in "supportable", it'll walk on by. The only time the negative assertion is needed is at the start of an alphanumeric string. In other words, "port_decl" will only ever get called here either at the start of the input, or after a comment, string, white or a *non-alphanumeric* (because an alphanumeric would have been eaten). Hope that clarifies. In this case greediness makes things easier :-). Clifford Heath.