I have this parser:
import scala.util.parsing.combinator.JavaTokenParsers
class RequestMappingParser extends JavaTokenParsers {
def requestMapping: Parser[Any] = "@RequestMapping(" ~ commaDelimitedSeq ~ ")"
def commaDelimitedSeq: Parser[Any] = repsep(keyValue, ",")
def keyValue: Parser[Any] = key ~ "=" ~ value
def key: Parser[Any] = "value" | "method"
def value: Parser[Any] = """[^)]*""".r
}
I have this simple class:
class MethodRequestMapping(val value: String, val method: String)
My parser can parse this string:
"@RequestMapping(value = \"/ex/foos\", method = RequestMethod.GET)"
and return a result of Parser[Any]. I would like it to return a result of Parser[MethodRequestMapping].
How do I do this? I know I have to do something like this:
def requestMapping: Parser[MethodRequestMapping] = "@RequestMapping(" ~ commaDelimitedSeq ~ ")" ^^ {
// Some sort of pattern matching and creation of MethodRequestMapping
// ???
}
But what goes in the ???? Or is it better to do it some entirely different way?