mediawiki-extensions-Visual.../modules/parser/test/parserTests.pegjs
Carl Fürstenberg dca609e3f9 Parsoid: move tests/parser to modules/parser/test
In preparation for the big extraction of Parsoid out of VisualEditor,
we'll start by moving the tests into the parsoid location.

Change-Id: I4a926ee4aad1490d4f769d44e91af80842b881f0
2012-07-25 02:29:25 +02:00

150 lines
2 KiB
JavaScript

/**
* PEG.js grammar for reading MediaWiki parser tests files
* 2011-07-20 Brion Vibber <brion@pobox.com>
*/
testfile =
chunk+
eol = "\n"
whitespace = [ \t]+
ws = whitespace
rest_of_line = c:([^\n]*) eol
{
return c.join('');
}
line = (!"!!") line:rest_of_line
{
return line;
}
text = lines:line*
{
return lines.join('\n');
}
chunk =
comment /
article /
test /
line /
hooks /
functionhooks
comment =
"#" text:rest_of_line
{
return {
type: 'comment',
comment: text
}
}
empty =
eol /
ws eol
{
return {
type: 'empty'
}
}
article =
start_article title:line start_text text:text end_article
{
return {
type: 'article',
title: title,
text: text
}
}
start_article =
"!!" ws? "article" ws? eol
start_text =
"!!" ws? "text" ws? eol
end_article =
"!!" ws? "endarticle" ws? eol
// function hooks
functionhooks = start_functionhooks text:text end_functionhooks
{
return {
type: 'functionhooks',
text: text
}
}
start_functionhooks =
"!!" ws? "functionhooks" ":"? ws? eol
end_functionhooks =
"!!" ws? "endfunctionhooks" ":"? ws? eol
end_test =
"!!" ws? "end" ws? eol
test =
start_test
title:text
sections:section*
end_test
{
var test = {
type: 'test',
title: title
};
for (var i = 0; i < sections.length; i++) {
var section = sections[i];
test[section.name] = section.text;
}
return test;
}
section =
"!!" ws? (!"end") name:(c:[a-zA-Z0-9]+ { return c.join(''); }) rest_of_line
text:text
{
return {
name: name,
text: text
};
}
/* the : is for a stray one, not sure it should be there */
start_test =
"!!" ws? "test" ":"? ws? eol
end_test =
"!!" ws? "end" ws? eol
hooks =
start_hooks text:text end_hooks
{
return {
type: 'hooks',
text: text
}
}
start_hooks =
"!!" ws? "hooks" ":"? ws? eol
end_hooks =
"!!" ws? "endhooks" ws? eol