树顶语法线延续

Treetop grammar line continuation

我正在尝试为如下语言创建语法

someVariable = This is a string, I know it doesn't have double quotes
anotherString = This string has a continuation _
      this means I can write it on multiple line _
      like this
anotherVariable = "This string is surrounded by quotes"

正确解析前面代码的树顶语法规则是什么?

我应该能够为三个变量提取以下值

谢谢

如果您将序列“_\n”定义为单个白色-space 字符,并确保在接受行尾之前对其进行测试,您的VB 风格的续行应该直接退出。在 VB 中,换行符“\n”本身并不是白色的 space,而是一个独特的语句终止符。根据您的输入字符处理规则,您可能还需要处理回车 returns。我会这样写 white-space 规则:

rule white
  ( [ \t] / "_\n" "\r"? )+
end

那么你的语句规则是这样的:

rule variable_assignment
  white* var:([[:alpha:]]+) white* "=" white* value:((white / !"\n" .)*) "\n"
end

以及您的首要规则:

rule top
    variable_assignment*
end

你的语言似乎没有比这更明显的结构了。