2011-05-05 44 views
2

這裏的東西我試圖做到:解析字符串中階自定義對象來說

解析以下字符串:

"this is plain text, <bold>this is bold</bold>, and <italics>this is italics</italics> etc." 

的結果應該是像出頭:

陣列(明文(「這是純文本」), 粗體(這是粗體), PlainText(「,and」), 斜體(這是斜體), PlainText(「etc.」))

PlainText,Bold和Italics可以是案例類。

任何想法從哪裏開始?我試圖玩正則表達式findAllIn(..),拆分,但 沒有弄清楚這一點呢。

+0

[算術表達式語法和解析器](http://stackoverflow.com/questions/5805496/arithmetic-expression-grammar-and-parser) – 2011-05-06 16:04:40

回答

3

如果你可以明確定義你的規則,在BNF中,分手的字符串 - 然後Scala's parser combinators很可能是你的前進方向。