How to match against end-of-file?

175 Views Asked by At

I want to match either newline ("\n"), semi-colon (";") or eof as being a valid end of statement. The first two are obvious, e.g.

eos = "\n" | ";";

but I'm not sure how to also match against the eof in the same way.

Is there some way to match against eof? I wondered if empty would work but I'm not sure how to use it.

1

There are 1 best solutions below

1
On

Here's a small machine with an action on the end-of-statement terminator or EOF.

%%{
    machine test;

    eos = (';' | '\n') ${ /* terminator code here */ } >eof{ /* eof code here */ };
    main := ('a' 'b' eos)*;

    write data;
    write init;
    write exec;

}%%