parslet
Jordan Orelli 9 years ago
parent 914935e186
commit bed657f0e8

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

Loading…
Cancel
Save