0

如何使用 ~> 或 <~ 运算符的正确位置忽略这些语法规则中的所有字符串?

def typeDefBody = ident ~ ":" ~ ident ~ "{" ~ fieldBody ~ "}"

def fieldBody = "validation" ~ "{" ~ validationBody ~ "}"

def validationBody = length ~ pattern

def length = "length" ~ "=" ~ wholeNumber ~ "to" ~ wholeNumber

def pattern = "pattern" ~ "=" ~ stringLiteral
4

1 回答 1

0

我找到了解决方案,我应该打破typeDefBody3 无终端规则,如下所示

def typeDefBody =  ident ~ typeDefBodySequence1

def typeDefBodySequence1 = ":" ~> ident ~ typeDefBodySequence2

def typeDefBodySequence2 = "{" ~> fieldBody <~ "}"

def fieldBody = "validation" ~ "{" ~> validationBody <~ "}"

def validationBody = length ~ pattern

def length = "length" ~ "=" ~> wholeNumber ~ "to" ~ wholeNumber

def pattern = "pattern" ~ "=" ~> stringLiteral
于 2013-09-04T13:40:34.397 回答