<s>
The	O
Sweble	B-Application
Wikitext	O
parser	B-Language
is	O
an	O
open-source	B-Application
tool	I-Application
to	O
parse	B-Language
the	O
Wikitext	O
markup	O
language	O
used	O
by	O
MediaWiki	B-Application
,	O
the	O
software	O
behind	O
Wikipedia	O
.	O
</s>
<s>
Based	O
on	O
the	O
statistics	O
at	O
Ohloh	B-Application
the	O
parser	B-Language
is	O
mainly	O
written	O
in	O
the	O
Java	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
The	O
parser	B-Language
itself	O
is	O
generated	O
from	O
a	O
parsing	B-Language
expression	O
grammar	O
(	O
PEG	O
)	O
using	O
the	O
.	O
</s>
<s>
The	O
encoding	O
validation	O
is	O
done	O
using	O
a	O
flex	B-General_Concept
lexical	I-General_Concept
analyser	I-General_Concept
written	O
in	O
.	O
</s>
<s>
A	O
preprint	O
version	O
of	O
the	O
paper	O
on	O
the	O
design	O
of	O
the	O
Sweble	B-Application
Wikitext	O
Parser	B-Language
can	O
be	O
found	O
at	O
the	O
projects	O
homepage	O
.	O
</s>
<s>
In	O
addition	O
to	O
that	O
,	O
a	O
summary	O
page	O
exists	O
at	O
the	O
MediaWiki	B-Application
's	O
futures	O
.	O
</s>
<s>
The	O
parser	B-Language
used	O
in	O
MediaWiki	B-Application
converts	O
the	O
content	O
directly	O
from	O
Wikitext	O
into	O
HTML	B-Language
.	O
</s>
<s>
in	O
programming	O
languages	O
like	O
C++	B-Language
.	O
</s>
<s>
Parsing	B-Language
and	O
rendering	O
of	O
the	O
now	O
fully	O
expanded	O
text	O
.	O
</s>
<s>
Hereby	O
,	O
the	O
text	O
is	O
processed	O
by	O
a	O
sequence	O
of	O
built-in	O
functions	O
of	O
MediaWiki	B-Application
that	O
each	O
recognise	O
a	O
single	O
construct	O
.	O
</s>
<s>
Those	O
analyse	O
the	O
content	O
using	O
Regular	B-Language
Expressions	I-Language
and	O
replace	O
e.g.	O
</s>
<s>
=	O
HEAD	O
=	O
with	O
its	O
HTML	B-Language
equivalent	O
<h1>HEAD</h1>	O
.	O
</s>
<s>
As	O
the	O
authors	O
of	O
Sweble	B-Application
write	O
in	O
their	O
paper	O
,	O
an	O
analysis	O
of	O
the	O
source	O
code	O
of	O
MediaWiki	B-Application
's	O
parser	B-Language
showed	O
that	O
the	O
strategy	O
of	O
using	O
separate	O
transformation	O
steps	O
leads	O
to	O
new	O
problems	O
:	O
Most	O
of	O
the	O
used	O
functions	O
do	O
not	O
take	O
the	O
scope	B-Language
of	O
the	O
surrounding	O
elements	O
into	O
account	O
.	O
</s>
<s>
This	O
consequently	O
leads	O
to	O
wrong	O
nesting	B-General_Concept
in	O
the	O
resulting	O
HTML	B-Language
output	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
the	O
evaluation	O
and	O
rendering	O
of	O
the	O
latter	O
can	O
be	O
ambiguous	O
and	O
depends	O
on	O
the	O
rendering	O
engine	O
of	O
the	O
used	O
web	B-Application
browser	I-Application
.	O
</s>
<s>
"	O
The	O
individual	O
processing	O
steps	O
often	O
lead	O
to	O
unexpected	O
and	O
inconsistent	O
behavior	O
of	O
the	O
parser	B-Language
.	O
</s>
<s>
As	O
argued	O
on	O
the	O
WikiSym	O
conference	O
in	O
2008	O
,	O
a	O
lack	O
of	O
language	O
precision	O
and	O
component	O
decoupling	O
hinders	O
evolution	O
of	O
wiki	B-Protocol
software	I-Protocol
.	O
</s>
<s>
If	O
the	O
wiki	B-Protocol
content	O
had	O
a	O
well-specified	O
representation	O
that	O
is	O
fully	O
machine	B-General_Concept
processable	I-General_Concept
,	O
this	O
would	O
not	O
only	O
lead	O
to	O
better	O
accessibility	O
of	O
its	O
content	O
but	O
also	O
improve	O
and	O
extend	O
the	O
ways	O
in	O
which	O
it	O
can	O
be	O
processed	O
.	O
</s>
<s>
In	O
addition	O
,	O
a	O
well-defined	O
object	B-Application
model	I-Application
for	O
wiki	B-Protocol
content	O
would	O
allow	O
further	O
tools	O
to	O
operate	O
on	O
it	O
.	O
</s>
<s>
Until	O
now	O
there	O
have	O
been	O
numerous	O
attempts	O
at	O
implementing	O
a	O
new	O
parser	B-Language
for	O
MediaWiki	B-Application
(	O
see	O
)	O
.	O
</s>
<s>
The	O
authors	O
of	O
Sweble	B-Application
state	O
that	O
this	O
might	O
be	O
"	O
due	O
to	O
their	O
choice	O
of	O
grammar	O
,	O
namely	O
the	O
well-known	O
LALR(1 )	O
and	O
LL(k )	O
grammars	O
.	O
</s>
<s>
While	O
these	O
grammars	O
are	O
only	O
a	O
subset	O
of	O
context-free	O
grammars	O
,	O
Wikitext	O
requires	O
global	O
parser	B-Language
state	O
and	O
can	O
therefore	O
be	O
considered	O
a	O
context-sensitive	O
language.	O
"	O
</s>
<s>
As	O
a	O
result	O
,	O
they	O
base	O
their	O
parser	B-Language
on	O
a	O
parsing	B-Language
expression	O
grammar	O
(	O
PEG	O
)	O
.	O
</s>
<s>
Sweble	B-Application
parses	B-Language
the	O
Wikitext	O
and	O
produces	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
as	O
output	O
.	O
</s>
<s>
A	O
detailed	O
description	O
of	O
the	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
model	O
can	O
be	O
found	O
in	O
a	O
technical	O
report	O
about	O
the	O
Wikitext	O
Object	B-Application
Model	I-Application
(	O
WOM	O
)	O
.	O
</s>
<s>
The	O
parser	B-Language
processes	O
Wikitext	O
in	O
five	O
stages	O
:	O
</s>
<s>
control	O
characters	O
in	O
Unicode	O
)	O
,	O
a	O
cleaning	O
step	O
is	O
needed	O
before	O
starting	O
the	O
actual	O
parsing	B-Language
.	O
</s>
<s>
In	O
this	O
process	O
it	O
must	O
be	O
ensured	O
that	O
character	O
used	O
as	O
prefix	O
for	O
the	O
parser	B-Language
are	O
not	O
escaped	O
or	O
changed	O
.	O
</s>
<s>
For	O
this	O
purpose	O
it	O
is	O
scanned	O
for	O
XML-like	O
comments	O
,	O
meta-information	O
such	O
as	O
redirections	O
et	O
cetera	O
,	O
conditional	O
tags	O
,	O
and	O
tag	O
extensions	O
.	O
</s>
<s>
The	O
latter	O
are	O
XML	B-Protocol
elements	O
that	O
are	O
treated	O
similar	O
to	O
parser	B-Language
functions	O
or	O
variables	O
,	O
respectively	O
.	O
</s>
<s>
XML	B-Protocol
elements	O
with	O
unknown	O
names	O
are	O
treated	O
as	O
if	O
they	O
are	O
generic	O
text.The	O
result	O
of	O
this	O
stage	O
is	O
an	O
AST	B-Data_Structure
which	O
consists	O
mostly	O
of	O
text	O
nodes	O
but	O
also	O
redirect	O
links	O
,	O
transclusion	O
nodes	O
and	O
the	O
nodes	O
of	O
tag	O
extensions	O
.	O
</s>
<s>
Expansion	O
Pages	O
in	O
a	O
MediaWiki	B-Application
are	O
often	O
built	O
using	O
templates	O
,	O
magic	O
words	O
,	O
parser	B-Language
functions	O
and	O
tag	O
extensions	O
.	O
</s>
<s>
To	O
use	O
the	O
AST	B-Data_Structure
in	O
a	O
WYSIWYG	B-Application
editor	I-Application
,	O
one	O
would	O
leave	O
out	O
expansion	O
to	O
see	O
the	O
unexpanded	O
transclusion	O
statements	O
and	O
parser	B-Language
function	O
calls	O
in	O
the	O
original	O
page	O
.	O
</s>
<s>
as	O
HTML	B-Language
page	O
these	O
must	O
be	O
processed	O
to	O
get	O
the	O
complete	O
output	O
.	O
</s>
<s>
Parsing	B-Language
Before	O
parsing	B-Language
starts	O
,	O
the	O
AST	B-Data_Structure
has	O
to	O
be	O
converted	O
back	O
into	O
Wikitext	O
.	O
</s>
<s>
Once	O
this	O
step	O
is	O
done	O
,	O
a	O
PEG	O
parser	B-Language
analyzes	O
the	O
text	O
and	O
generates	O
an	O
AST	B-Data_Structure
capturing	O
the	O
syntax	B-Application
and	O
semantics	B-Application
of	O
the	O
wiki	B-Protocol
page	O
.	O
</s>
<s>
Moreover	O
,	O
apostrophes	B-Language
are	O
analyzed	O
to	O
decide	O
which	O
of	O
them	O
are	O
real	O
prose	O
apostrophes	B-Language
and	O
which	O
have	O
to	O
be	O
interpreted	O
as	O
markup	O
for	O
bold	O
or	O
italic	O
font	O
in	O
Wikitext	O
.	O
</s>
<s>
Hereby	O
,	O
the	O
AST	B-Data_Structure
is	O
processed	O
using	O
a	O
depth-first	B-Algorithm
traversal	I-Algorithm
on	O
the	O
tree	B-Application
structure	I-Application
.	O
</s>
<s>
The	O
rendering	O
of	O
the	O
different	O
kinds	O
of	O
output	O
as	O
well	O
as	O
the	O
analyzing	O
functions	O
are	O
realized	O
as	O
Visitors	B-Language
.	O
</s>
<s>
This	O
helps	O
to	O
separate	O
the	O
AST	B-Data_Structure
data	B-General_Concept
structure	O
from	O
the	O
algorithms	O
that	O
operate	O
on	O
the	O
data	B-General_Concept
.	O
</s>
