parsing - Building a regex with packrat parsers in Scala -
i have 2 packrat parsers in scala:
val symbols : packratparser[string] = "{" | "}" | ">" val keywords : packratparser[string] = "bool" | "int"
i want build parser can recognise if statement composed of 1 or more of 2 parsers. way i'd is:
val statement : packratparser[string] = regex( "[symbols | keywords]+".r )
but wouldn't work because they're thinking want actual "symbols" or "keywords" token... can help?
you can't use regex way. however, whole point of parser combinators can combined!
val statement : packratparser[list[string]] = rep1(symbols | keywords)
Comments
Post a Comment