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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -