Jan Hidders wrote:
Timwi wrote:
Michael Becker wrote:
I'm going to break out my compiler books and
start working on a CFG
for the wiki code
I am already working on this.
Yes. Impressive. But do you already have a grammar that describes what
your parser parses?
I have indeed been told by a friend that it would be a better idea to
write down the BNF for the grammar before starting to write the yacc
file. So I tried. But then, when I finally did the yacc file, I
realised that it was not such a good idea after all. In fact, it was a
waste of time. You need to be able to test the grammar while you are
working on it, and you want to be able to tweak certain parts before
writing certain other parts that depend on them.
This is quite different from planning a software project, where you
sketch your system and its modules in a very rough outline first.
Rather, when writing the yacc file, you are actually writing the
grammar. With BNF, you would also be writing the grammar, but without
the benefit of being able to test it. In particular, in BNF you
wouldn't be able to described transformations like the one I needed to
do for lists. You would instead rack your brains over how to parse the
lists directly, never coming to a conclusion (because it is probably
impossible).
If you are still interested, please find below the BNF I originally
wrote. However, the current yacc file I use is quite different from it.
I haven't even done links yet, and I already know that the below grammar
will not work for links, because it will treat the pipe character as
text inside the double square brackets.
Timwi
article ::= e | block | article NEWLINE+ block
block ::= paragraph | heading | bulletedlist | numberedlist | preblock |
comment
paragraph ::= nonemptytext | paragraph NEWLINE nonemptytext
comment ::= EMPTYCOMMENT | BEGINCOMMENT TEXT ENDCOMMENT
| BEGINCOMMENT TEXT | BEGINCOMMENT
heading ::= headinglevel1 | headinglevel2 | headinglevel3
| headinglevel4 | headinglevel5 | headinglevel6
headinglevel1 ::= HEADING1 nonemptytext ENDHEADING?
headinglevel2 ::= HEADING2 nonemptytext ENDHEADING?
headinglevel3 ::= HEADING3 nonemptytext ENDHEADING?
headinglevel4 ::= HEADING4 nonemptytext ENDHEADING?
headinglevel5 ::= HEADING5 nonemptytext ENDHEADING?
headinglevel6 ::= HEADING6 nonemptytext ENDHEADING?
bulletedlist ::= LISTBULLET text
| bulletedlist NEWLINE LISTBULLET text
| bulletedlist NEWLINE NEWLINE LISTBULLET text
numberedlist ::= LISTNUMBERED text
| numberedlist NEWLINE LISTNUMBERED text
| numberedlist NEWLINE NEWLINE LISTNUMBERED text
preblock ::= PRELINE text | preblock NEWLINE* PRELINE text
nonemptytext ::= intext | intext nonemptytext
text ::= e | nonemptytext
intext ::= TEXT | EXTENSION | comment | dblsqbr | PIPE | templateinclusion
| templatevariable | bold | italics | APOSTROPHE | DOUBLEQUOTE
# Things that are invalid syntax but we need to allow:
| ENDCOMMENT | OPENDBLSQBR CLOSEDBLSQBR | OPENLINK
CLOSEDBLSQBR
dblsqbr ::= linkorimageorcategory | forcedlink
linkorimageorcategory ::= OPENDBLSQBR linkinside CLOSEDBLSQBR
forcedlink ::= OPENLINK linkinside CLOSEDBLSQBR
linkinside ::= nonemptytext | linkinside PIPE nonemptytext