سؤال

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
هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top