Parsing String in scala to custom case objects
Here's something I'm trying to accomplish:
Parsing the following String:
"this is plain text, <bold>this is bold</bold>, and <italics>this is italics</italics> etc."
The result should be somethings like:
Array(PlainText("this is plain text, "), Bold(this is bold), PlainText(", and "), Italics(this i开发者_如何转开发s italics), PlainText(" etc."))
PlainText, Bold and Italics could be case classes.
Any ideas where to start? I've tried to play around regex findAllIn(..), split but didn't figure this out yet.
If you can unambiguously define your rules, in BNF, for breaking up the String - then Scala's parser combinators could well be the way forward for you.
精彩评论