# EOF in TreeTop?

**URL:** <https://www.ruby-forum.com/t/eof-in-treetop/129227>\
**Category:** Ruby\
**Created:** [February 15, 2008, 4:55pm UTC](https://www.ruby-forum.com/t/eof-in-treetop/129227 "2008-02-15T16:55:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Day](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@Day](https://www.ruby-forum.com/u/Day)\
**Post date:** [February 15, 2008, 4:55pm UTC](https://www.ruby-forum.com/t/eof-in-treetop/129227/1 "2008-02-15T16:55:30Z")

</div>

I ran into a problem writing my praser: there’s a comment in the last  
line of my file and I’d defined comments to be ‘\*’ followed by  
anything that’s not a newline followed by a newline. The final comment  
isn’t followed by a newline (it might be, but it doesn’t have to be),  
so I need to tell TreeTop that comments can go until newline or end of  
file, but the treetop web page doesn’t seem to indicate a symbol for  
EOF. I’m not at home and can’t put subversion on this machine, so I  
can’t mess with it until I figure it out just now, so I thought I’d  
see if anyone knew off the top of their head… I’m looking for  
something like this, I think:

rule comment  
'_’ (!"\n" !eof .)_ ("\n" / eof)  
end

Thanks.

Ben

---

<div class="post-metadata">

**Author:** ![Day](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@Day](https://www.ruby-forum.com/u/Day)\
**Post date:** [February 15, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/eof-in-treetop/129227/2 "2008-02-15T22:26:10Z")

</div>

Day wrote:

> see if anyone knew off the top of their head… I’m looking for  
> something like this, I think:
> 
> rule comment  
> '_’ (!"\n" !eof .)_ ("\n" / eof)  
> end

This should work for detecting eof:

rule eof  
! .  
end

You might simplify by defining end of comment:

rule eoc  
“\n” / eof  
end

Then comment becomes:

rule comment  
'_’ (!eoc .)_ eoc  
end

Clifford H…

---

<div class="post-metadata">

**Author:** ![Day](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@Day](https://www.ruby-forum.com/u/Day)\
**Post date:** [February 15, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/eof-in-treetop/129227/3 "2008-02-15T23:51:50Z")

</div>

On Feb 15, 2008 3:24 PM, Clifford H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> Then comment becomes:
> 
> rule comment  
> '_’ (!eoc .)_ eoc  
> end

Nice! I’ll try it out this evening. It never occured to me that EOF  
would be “not anything”. Sort of a funny concept. Thanks!

Ben
