n 11/13/07, Steve Bennett stevagewp@gmail.com wrote:
On 11/13/07, Virgil Ierubino virgil.ierubino@gmail.com wrote:
It's clear that BNF can't formulate outside these constraints because if (1) was false, you'd never get to the end of the specification, and (2) can't be false simply because it restates (1) but also allows for languages with nested syntax. If it were false that the nested/complex syntax could be broken down into basic syntax, then that complex syntax would simply BE basic syntax, and you are left with just rule (1).
Wikitext fails these constraints because the construct:
**bullet 1 **bullet 2
I think there's a pretty simple solution.
Given some input:
*a *#b *#c ***d *##e
First, naively turn *a into <ul><li>a</li></ul> etc on a line by line basis:
<ul><li>a</li></ul> <ul><ol><li>b</li></ol></ul> <ul><ol><li>c</li></ol></ul> <ul><ul><ul><li>d</li></ul></ul></ul> <ul><ol><ol><li>e</li></ol></ol></ul>
This can be done with a BNF-based parser, I think.
Then, simply repeatedly collapse adjacent pairs of </ul><ul> and </ol><ol>:
<ul><li>a</li> <ol><li>b</li> <li>c</li></ol> <ul><ul><li>d</li></ul></ul> <ol><ol><li>e</li></ol></ol></ul>
I think this will always yield the result we want. Not that I've tried to prove it or anything ;)
Interestingly, the second phase is only actually required for ordered lists. Unordered lists and indented lists (:) would probably render ok after the first phase.
Steve