From: Phrogz Date: 2008-01-29T23:29:56+09:00 Subject: Re: Treetop parser (or PEG in general?) questions On Jan 28, 1:22 am, Clifford Heath wrote: > Phrogz wrote: > > HANDLING EOF > > As seen in the example above, a paragraph (or any block level element, > > really) is allowed to not have a newline if it's the last thing in the > > file. Do you handle this case normally by just preprocessing the input > > and shoving a newline on the end if it doesn't exist, > > That's what I'd do. > > > or is there a > > way in Treetop to recognize the /\Z/ anchor from a Regexp? > > No. There's no EOF symbol. Perhaps there should be.. For the archives, the original PEG/packrat paper defines: EndOfFile <- !. That looks like it'll do just fine. It's interesting to note that it defines this because technically the grammar can match an input string without parsing all the text. In the paper, EndOfFile is used to anchor the end of the root rule to ensure all the text is parsed. In Treetop, this is obviated by the Treetop::Runtime::CompiledParser#consume_all_input flag, which defaults to true. Only by setting it to false do you get the (dubiously useful) behavior of ignoring the rest of the input if you've matched the root rule.