|
|
|
@ -13,40 +13,24 @@ module Bristlecode
|
|
|
|
|
rule(:space) { match('\s').repeat(1) }
|
|
|
|
|
rule(:space?) { space.maybe }
|
|
|
|
|
|
|
|
|
|
rule(:bold_open) {
|
|
|
|
|
(str('[b]') | str('[B]'))
|
|
|
|
|
}
|
|
|
|
|
rule(:bold_close) {
|
|
|
|
|
(str('[/b]') | str('[/B]'))
|
|
|
|
|
}
|
|
|
|
|
rule(:bold) {
|
|
|
|
|
(bold_open >> children.as(:bold) >> bold_close)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rule(:italic_open) {
|
|
|
|
|
(str('[i]') | str('[I]'))
|
|
|
|
|
}
|
|
|
|
|
rule(:italic_close) {
|
|
|
|
|
(str('[/i]') | str('[/I]'))
|
|
|
|
|
}
|
|
|
|
|
rule(:italic) {
|
|
|
|
|
(italic_open >> children.as(:italic) >> italic_close)
|
|
|
|
|
}
|
|
|
|
|
rule(:bold_open) { str('[b]') | str('[B]') }
|
|
|
|
|
rule(:bold_close) { str('[/b]') | str('[/B]') }
|
|
|
|
|
rule(:bold) { bold_open >> children.as(:bold) >> bold_close }
|
|
|
|
|
|
|
|
|
|
rule(:italic_open) { str('[i]') | str('[I]') }
|
|
|
|
|
rule(:italic_close) { str('[/i]') | str('[/I]') }
|
|
|
|
|
rule(:italic) { italic_open >> children.as(:italic) >> italic_close }
|
|
|
|
|
|
|
|
|
|
rule(:eof) { any.absent? }
|
|
|
|
|
rule(:tag) { (bold | italic) }
|
|
|
|
|
rule(:tag) { bold | italic }
|
|
|
|
|
rule(:elem) { text | tag }
|
|
|
|
|
rule(:tag_open) { bold_open | italic_open }
|
|
|
|
|
rule(:tag_close) { bold_close | italic_close }
|
|
|
|
|
rule(:tag_delim) { tag_open | tag_close }
|
|
|
|
|
|
|
|
|
|
rule(:text) { (tag_delim.absent? >> any).repeat(1).as(:text) }
|
|
|
|
|
rule(:children) {
|
|
|
|
|
space? >> elem.repeat(1)
|
|
|
|
|
}
|
|
|
|
|
rule(:doc) {
|
|
|
|
|
space? >> elem.repeat(1).as(:doc)
|
|
|
|
|
}
|
|
|
|
|
rule(:children) { space? >> elem.repeat(1) }
|
|
|
|
|
rule(:doc) { space? >> elem.repeat(1).as(:doc) }
|
|
|
|
|
root(:doc)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|