简体   繁体   English

GoldParser:接受不以空行结尾的程序

[英]GoldParser: Accept programs not ending with an empty line

I'm rewriting a GoldParser Grammar for VBScript. 我正在为VBScript重写GoldParser语法。 In VBScript Statements are terminated using either a newline or ':' . 在VBScript中,语句使用换行符或':'终止。 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. 因为每个语句都必须以Newline ,所以仅接受以空行结尾的程序。 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. 这不起作用,因为{EOF} (文件末尾)组不存在。

EOF is a special token and I'm not aware of any syntax allowing you to use it in a production rule. EOF是一个特殊的标记,我不知道有任何语法允许您在生产规则中使用它。 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. 虽然这不能使它在GOLD Builder测试窗口中正确解析,但是它将使您的代码按预期方式处理数据,并且不会增加语法的复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM