Question

How can I ignore all strings in these grammar rules using correct placement of ~> or <~ operators?

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

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

def validationBody = length ~ pattern

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

def pattern = "pattern" ~ "=" ~ stringLiteral
Was it helpful?

Solution

I found the solution, I should break typeDefBody to 3 None terminal rules as below

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top