saidone.org -
Save water -- drink beer!
Main menu
Development
Mailing lists

Swamp
Links
ush.it
aghers.org
saidone@ush
gameknot
BBCode-like parser work in progress - posted by saidone on Fri, 08 Aug 2008 10:13:17 GMT
This page is a test for the new MediaWiki BBCode like parser. I was tired to write and maintain very big and complex parsers, so I decided to rewrite it using JavaCC, a parser/scanner generator for java. I hope that this will fit all my needs.
In the beginning I was thinking to implement some sort of MediaWiki syntax, but I found that is more prone to ambiguity and a parser would become too bloated (maybe I'm wrong eh?). I don't like these things, here's an example:

' stands for apostrophe
'' for italics
''' for bold

Now the string ''' can be interpreted in various modes... an italicized apostrophe waiting for the italic end tag, an apostrophe followed by the italic start tag, the bold tag itself, or a sequence of three apostrophes. Yes, we can match and replace something with regular expressions, and maybe obtain a somewhat good result, but the code rapidly become a mess and adding further tags is far from trivial then. So, at the moment, I choose BBCode as a lightweight markup language for the posts.

Here's some tests:

italic
bold
italic + bold
strikethru

quoted text



This is an url: http://www.ush.it
and another: ush.it - a beautiful place

10 REM YOU WILL HARDLY NOTICE THE "CODE" TAG
20 REM WITH THIS CSS!
30 PRINT "CIAO"
40 GOTO 30

*colored text* (only hex encoded colors at the moment)

...and yes, there's also the img tag: (actually, my car ;-))

Here's the grammar source code (to be polished): KBbCodeParser.jj

REFERENCES

JavaCC home: https://javacc.dev.java.net/
An excellent FAQ maintained by Theodore S. Norvell: http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq-moz.htm



No comments yet.



Post a new comment

<-- comment title (well, not really mandatory)
<-- your name
<-- your e-mail
<-- multiply 8 by 53

back to home
[[[[[[[ served by kugelmass ]]]]]]]
I don't have a drinking problem except when I can't get a drink. - Tom Waits