parsing - How to combine Regexp and keywords in Scala parser combinators -
i've seen 2 approaches building parsers in scala.
the first extends regexparsers , define won lexical patterns. issue see don't understand how deals keyword ambiguities. example, if keyword match same pattern idents, processes keywords idents.
to counter that, i've seen posts this one show how use standardtokenparsers specify keywords. then, don't understand how specify regexp patterns! yes, standardtokenparsers comes "ident" doesn't come other ones need (complex floating point number representations, specific string literal patterns , rules escaping, etc).
how both ability specify keywords , ability specify token patterns regular expressions?
i've written regexparsers
-derived parsers, this:
val name: parser[string] = "[a-z_a-z][a-z_a-z0-9]*".r val kwif: parser[string] = "if\\b".r val kwfor: parser[string] = "for\\b".r val kwwhile: parser[string] = "while\\b".r val reserved: parser[string] = ( kwif | kwfor | kwwhile ) val identifier: parser[string] = not(reserved) ~> name
Comments
Post a Comment