This is for real. I'm considering writing a BBCode programming language, intended for use in message boards. It'd be backwards-compatible with the current BBCode, but it'd allow you to write ad-hoc programs that generate your post.
Basically, it'd be a LISP, with these four properties beyond the usual:
- Only you configure the opening and closing parens, which you can set to [].
- In the top level, any sequence of characters that is outside of any application (outside []) is evaluated as string (preserving whitespace and everything), and returned as is, except <, > and & are converted to HTML entities.
- The resulting post is the concatenation of everything that's evaluated at top level, which means you get everything in the top level outside [] and every string any functions you called returned. (Other types functions may return are converted to their canonical representation.) Function results may safely return HTML; their <, > and & are not automatically converted to HTML entities.
- When you apply a non-applicable or non-existent symbol, you get a string which consists of [, the symbol, and ], so that unrecognized tags are printed as is (which is the current behaviour in BBCode).
For example, this would define the [ b ] and [ /b ] for bold, assuming we're using { and } for open/close parens (used {} so that BBCode doesn't fuck it up)
>>1 For example, this would define the [ b ] and [ /b ] for bold,
fail bbcoder,
if you want it to appear as is, you use \ to escape
example [b]bold[/b]
;)
for all previous posts, assuming we can get the current post number with (meta 'current-post).
Hello everybody,
\[define no-u \[lambda \[x] \[limit]
"NO U at posters x, x + 1, ... limit - 1"
\[print >>x EOL \[b] "NO U" \[/b] EOL EOL]
;Note: >>x would be a macro that works at top level too
\[if \[< x limit]
\[no-u \[+ x 1] limit]]]]
\[no-u 1 \[meta 'current-post]]
Name:
Anonymous2007-07-18 9:35 ID:PTojbCHk
>>9
Failed :( Well, remove all those backslashes and you'll see what I mean.
I liek the idea. On what imageboard it will be based?
Name:
Anonymous2007-07-18 17:36 ID:qfDTgMyw
>>14
imageboard? you must mean textboard, there's no such thing as an imageboard.
but it'd obviously be based on shiichan, for it is the most enterprise quality board software available.
Name:
Anonymous2007-07-18 18:33 ID:dhjcCxRM
Actually, my reference implementation will be in Python. A Python module which you can call anytime, even in a subprocess so that you render the final text to be stored in the DB (for non-edit boards such as Shiichan). I could port it to PHP afterwards, depending on my time and interest.
Here's a serious question.
If it's Turing complete (and by which I don't mean Touring complete; that's implicitly true if it's based on BBCode), and it's interpreted server-side, how will you handle cases where a script hangs?
Any time you let people submit scripts to the server to run, you're just bending over and grabbing your ankles.
Name:
Anonymous2007-07-19 4:57 ID:5Z/iH/zm
>>17
LOL, just prove that the script doesn't hang.
Name:
Anonymous2007-07-19 5:20 ID:FiL56+Wj
>>17
I could limit the execution "amount" by allowing up to a number of calls to eval or apply. This number could be configurable, or dynamically decided based on server load. After reaching that limit, I'd exit all nested functions and append "***Killed with fire***" and return whatever output was already produced.
I'd also limit output to a configurable number of KBs, to avoid
[define [x] [display "SICP "] [x]]
Name:
Anonymous2007-07-19 5:28 ID:ZYN1gZjE
>>18
Solving the halting problem? In my bbcode interpreter?
Ok, I got myself to start writing the first BBCode implementation in Python. I'll go on vacation tomorrow so don't count on a release soon though. It's going to be a Lisp similar to Scheme, with the following features and differences:
- Customizable special characters, so it can work with [] instead of ()
- Anything at top level, except function calls, will be echoed verbatim (kind of like PHP...), so that nothing gets affected outside [] and you can post normally, no quotes required or anything.
- {} will be used for quoting strings in Perl's q{} fashion, which is far more comfortable to use than "".
- Of course, it'll have first-class functions, lexical nested scoping and tail call optimization. I already have a working prototype with these features, so count on them.
- You can call Python functions just like BBCode functions (out of those allowed in toplevel, which is going to be a Python module's namespace), and BBCode functions can be called from Python code just the same. You can even do things such as str.join to access Python's join method of the str class.
- You can have access to a BBCode function's source code and introspect its parameters as well.
- There's going to be a simple way of implementing (pure BBCode) lazy evaluation and macros, and they will be first-class macros which are little different from a function.
- Lists won't be conses, but Python lists. This means less efficient cdr, but more efficient anything else. There's going to be dictionaries.
- There's going to be syntax to index lists and dictionaries comfortably, so you can do (with Lisp characters): (display i[3]) or even (display i[(+ x 5)]). In BBCode mode, I swap [] and (). This would be the same as doing something like (display (method i __getattribute__ 3)), and method or meth will be used to call Python methods. The set special macro will support this syntax, too.
- The standard library will be much reduced and not always similar to Scheme, even in basic constructs. For example, I may not implement let but have you use define and set, as you would use = in Python, and I may borrow a lot from Python since Python objects can be seen and called as BBCode ones.
- I'm considering implementing classes, exceptions, continuations and modules, but that's certainly going far too beyond the scope of BBCode, so they won't be in the initial release.
- Finally, I'm implementing a special macro define-with-the-forced-indentation-of-code.
Just kidding.
What do you think?
Name:
Anonymous2007-07-30 15:22 ID:O/OhtPpR
Oh, and of course, the standard library will have something like: [define [b] [display "<b>"]]
[define [/b] [display "</b>"]]
etc. so that it's backwards-compatible with existing BBCode.
Name:
Anonymous2007-07-30 15:27 ID:L7wiNCwD
stupid smug bbcode newbies.. wont you realise theres no point in reinventing the wheel, common bbcode is great theres nothing to fix.
Name:
Anonymous2007-07-30 15:28 ID:87Cv1RNs
- {} will be used for quoting strings in Perl's q{} fashion, which is far more comfortable to use than "".
Kill yourself
Name:
Anonymous2007-07-30 17:11 ID:O/OhtPpR
>>28
Lol. Seriously, how many times do you need "" and how cumbersome are they to escape (not to mention the quote hell that arises from escaping escaped strings and such ("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"...."), versus how many times do you need unmatched { or }? Besides, I'm still supporting "", I'm just providing {} as an additional means of quoting for sane people.
Name:
Anonymous2007-07-30 17:22 ID:87Cv1RNs
I don't use Perl, so I don't write ugly shit. Sorry.