flex: How can I match text only at the end of a file?
How can I match text only at the end of a file?
===============================================
There is no way to write a rule which is "match this text, but only if
it comes at the end of the file". You can fake it, though, if you
happen to have a character lying around that you don't allow in your
input. Then you redefine 'YY_INPUT' to call your own routine which, if
it sees an 'EOF', returns the magic character first (and remembers to
return a real 'EOF' next time it's called). Then you could write:
<COMMENT>(.|\n)*{EOF_CHAR} /* saw comment at EOF */