GoldParser: Accept programs not ending with an empty line

246 views Asked by At

I'm rewriting a GoldParser Grammar for VBScript. In VBScript Statements are terminated using either a newline or ':'. Therefore i use the following terminal:

NewLine        = {All Newline}
               | ':'

Because every statement has to end with the Newline terminal, only programs ending with an empty line are accepted. How can i extend the newline terminal to also accept programs not ending with an empty line? I tried the following:

NewLine        = {All Newline}
               | ':'
               | {EOF}

This does not work because the {EOF} (End of File) group does not exist.

1

There are 1 answers

0
Lucero On BEST ANSWER

EOF is a special token and I'm not aware of any syntax allowing you to use it in a production rule. It is emitted when the tokenizer receives no more data, and as such it is not a control character you could use in a terminal definition either.

That being said, you have different possibilities to parse the (strictly speaking invalid) input. The simplest may be to just append a newline at the end of the string or text being tokenized. While this will not make it parse correctly in the GOLD Builder test window, it will make your code process the data as expected and it will not add complexity to the grammar.