I have written a treetop grammer file that mostly works. For tags like [b]
I want to pass them into a function that has a hash of configured BBCodes for that forum. If bold was allowed it would return the HTML, otherwise it would ignore the BB code.
rule tag
tag:('[' [a-zA-Z]+ ']')
inner_tag:(
!('[/' [a-zA-Z]+ ']')
(tag <ForumBB::TagNode> / .)
)+
'[/' [a-zA-Z]+ ']'
end
This doesn't work with nested tags. For example, [b][i]Bold and italics[/i][/b]
won't be handled correctly because they match the first closing tag of [/i]
.
How can I make it so when it finds a tag it looks for the closing tag in the negative lookhead?
I'd rather not have to write all the rules out for each kind of BBCode as this is a dynamic system where forum administrators turn on/off certain tags.