I am making bbcode parser with PEG (Citrus implementation for Ruby) and I am stuck on parsing this [b]sometext[anothertext[/b]
There is code
grammar BBCodeParser
rule document
(open_tag | close_tag | new_line | text)*
end
rule open_tag
("[" tag_name "="? tag_data? "]")
end
rule close_tag
("[/" tag_name "]")
end
rule text
[^\n\[\]]+
end
rule new_line
("\r\n" | "\n")
end
rule tag_name
# [p|br|b|i|u|hr|code|quote|list|url|img|\*|color]
[a-zA-Z\*]+
end
rule tag_data
([^\[\]\n])+
end
end
Problem is with rule text
I dont know how to say, that text can contain everything except \r, \n, open_tag or close_tag.
With this implementation it fail on example because of exclude of [ and ] (thats wrong)
So finaly question is how to do rule, that can match anything except \r, \n or exact match of open_tag or close_tag
If you have solution for another PEG implementation, give it there too. I can switch :)