Page 1 of 1

BBEngine : Dynamically Extendable BBCode Parser/UnParser

Posted: Fri Sep 19, 2008 8:32 am
by ASDen
Hello
This idea is based on giving an easily extendable BBCode Parser not just with smiles or simple BBCodes but also with Complex ones ( nested , custom PHP handling function )
In PHPClasses : http://www.phpclasses.org/browse/package/4829.html
Documentation , Details & Example : http://harrrrpo.googlepages.com/bbengine
---
Features and main points in brief :-
1)It depends on saving tags info in a DB for easy Extendability (as it provides out-of-code dynamic of adding , removing and deleting )

2)Provides Processing Priority for each tag allowing for writting tags that depends on each others with no code modifications

3)The Class Provides Parsing/UnParsing in 4 types
  • Direct :-
    • Direct Words : Directly replace words with others like ( {:)} =>Smile photo (html <img>) )
    • Direct Tags : Replace Html Tags with BBCode directly (text replace) like ( {b}ASD{/b} => <strong>ASD</strong> )
  • Indirect :-
    • Indirect Non Recursive : Mainpulate content in BBCode with user defined function both for Parsing & UnParsing (Stored in DB) Content and Arguments of BB tag is supplied to the function here BBCode tags can't be Nested like ( {url=http://google.com}Google{/url} => <a href="http://google.com">Google</a> )
    • Indirect Recursive : The Same Indirect manner with the added ability of Parsing Nested tags like ( {size=20}Big {size=40}Bigger{/size}Word{/size} => <span style="font-size: 20px;">Big<span style="font-size:40px;">Big Label</span>Word</span> )
4)It also comes with some pre-made BBCodes as an SQL dump to provide most famous BBCodes
----
want to hear from you what you think about idea , implementation and any possible enhancements

Re: BBEngine : Dynamically Extendable BBCode Parser/UnParser

Posted: Fri Sep 19, 2008 8:47 am
by jayshields
Are you using curly brackets instead of square ones for the BBCode stuff? Or did you do that so this forum wouldn't convert your tags?

If the former, then it's not backwards compatible, so no existing forums will take it on.

Re: BBEngine : Dynamically Extendable BBCode Parser/UnParser

Posted: Fri Sep 19, 2008 9:19 am
by ASDen
no i just used {} so the forum doesn't convert them
The codes are compatible with *Standard* -well known - BBCodes

Re: BBEngine : Dynamically Extendable BBCode Parser/UnParser

Posted: Fri Sep 19, 2008 9:24 am
by jayshields
Ok, cool. Is every tag in the database? Or just ones which you can extend with? That seems to be the only thing you've mentioned that current BBCode implementations (which I know about) don't already do. If every tag is stored in the database, ie. {b}, then I guess it will be much slower than just regexp, expecially if there's loads of tags to fetch.

What other things can it do which other BBCode parsers don't already do? And have you benchmarked yours and other implementaions?

Re: BBEngine : Dynamically Extendable BBCode Parser/UnParser

Posted: Fri Sep 19, 2008 9:51 am
by ASDen
Is every tag in the database? Or just ones which you can extend with?
yes , every tag is in DB , this is how it's dynamic
If every tag is stored in the database, ie. {b}, then I guess it will be much slower than just regexp, expecially if there's loads of tags to fetch
not that slow , ofcourse you can't expect to be faster that hard coding , but two things can make it a competent if not a bit faster
1) in hard coded implemetations , there is the problem that the text whatever it's contents will - in most implementations- go through all available RegExps to be parsed - which is slow and not necessary - , here this is not the case only tags used in text is retrieved from DB and parsed [available now]

2) applying a cache mechanism will also make it much faster as things like {b},{u} will be always living in cache [this is not yet implemented in class , but will shortly be]

a last thing to mention - you may not like this - BBCode Parsers doesn't have to be blazing fast , e.g. in forums / blogs ..etc you only parse once and view thousands , but provided with previous two points it's not slower
What other things can it do which other BBCode parsers don't already do
special things is Indirect Tags (that is parsed with custom supplied function) in both types (nested and not nested)
as far as i know , dynamic addition of those isn't supported by most of them ,as in most cases you will have to hard code these things in original BBCode Parser (which is a typical miss)

aside from this , i think , isolated SQL dumps from the parsing logic is better than current mixing of both (e.g. hard coded Regexps in BBCode Parsers are much like mixed PHP and Html )
And have you benchmarked yours and other implementaions?
Not yet , just hand testing , shows it's fast