开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜