# uPresent grammar
# written in nearley
# see test.up for an example of what this parses
main -> config _ presentation {% function(d) {
return [d[0], d[2]];
} %}
config -> pphrase |
pphrase _ configOption:+ [\s]
configOption -> "+" pphrase "\n" {% function(d) { return [d[1], true] } %}
| "-" pphrase "\n" {% function(d) { return [d[1], false] } %}
| pphrase ": " pphrase "\n" {% function(d) { return [d[0], d[2]] } %}
presentation -> slide:+ {% function(d) { return [].concat.apply([], d) } %}
slide -> "-":+ "\n" content {% function(d) { return d[2] } %}
content -> line:+ {% function(d) { return d[0].join(""); } %}
line -> marker "\n" {% function(d) { return d[0] } %} |
lphrase "\n" {% function(d) { return "
" + d[0] + "
" } %} |
listnode:+ "\n" {% function(d) { return "" } %} |
"\n" {% function(d) { return ""; } %}
italics -> "_" lphrase "_" {% function(d) { return "" + d[1] + "" } %}
bold -> "**" lphrase "**" {% function(d) { return "" + d[1] + "" } %}
image -> "" {% function(d) { return '
' } %}
linkprotocol -> "http" | "https"
domain -> [A-Za-z\.]:+ {% function(d) { return d[0].join(""); } %}
rawlink -> linkprotocol "://" domain "/" [^ \n\t]:* {% function(d) {
return "" + d[0] + d[1] + d[2] + d[3] + d[4].join("") + "";
} %}
namelink -> "[" pphrase "](" path ")" {% function(d) { return '' + d[1] + ""; } %}
ln -> nophrase linecharacter:+ {%
function(d, blah, fail) {
d[1] = d[1].join("");
if(d[1].indexOf("http://") > -1 || d[1].indexOf("https://") > -1) {
return fail;
}
return d[0]+d[1]
}
%}
lphrase -> ln {% id %}
| nphrase {% id %}
lophrase -> ln {% id %}
| nphrase {% id %}
| _ {% function(d) { return "" } %}
nophrase -> nphrase {% id %} | _ {% function() { return "" } %}
nphrase -> lphrase [#] {% function(d) { return d[0]+d[1] } %}
| lophrase italics {% function(d) { return d[0]+d[1] } %}
| lophrase bold {% function(d) { return d[0]+d[1] } %}
| lphrase image {% function(d) { return d[0]+d[1] } %}
| lphrase [\-] {% function(d) { return d[0]+d[1] } %}
| lphrase [!] [^\[] {% function(d) { return d[0]+d[1]+d[2] } %}
| bphrase rawlink [\s] {% function(d) { return d[0]+d[1] } %}
| bphrase namelink {% function(d) { return d[0]+d[1] } %}
| lphrase "[" {% function(d) { return d[0]+d[1] } %}
bphrase -> lphrase {% id %}
| _ {% function() { return "" } %}
pphrase -> [ A-Za-z0-9!@#$%^&*()_+\-\=}{\[\]"':;?/>.<,i]:+ {% function(d) { return d[0].join("") } %}
linecharacter -> [A-Za-z0-9 @$%^&()+=.,<>/?'";:\|\]\{\}\(\)]
marker -> "# " lphrase "\n" {% function(d) {
return "" +
d[1] +
"
";
} %}
| image bphrase {% function(d) {
return "" + d[0] + d[1] + "
";
} %}
| "[linebreak]\n" {% function(d) { return "
"; } %}
| "[" pphrase "] " lphrase "\n" {% function(d) {
return "" + d[3] + "
";
} %}
path -> [A-Za-z0-9:\/!@#$%^&*()_+=\-\'\.\(\)]:+ {% function(d) { return d[0].join("") } %}
listnode -> "~ " lphrase "\n" {% function(d) {
return "" + d[1] + "";
} %}
| _ "~~ " lphrase "\n" {% function(d) {
return "" + d[2] + ""
} %}
_ -> null {% function(){ return null } %}
| [\s] _ {% function() { return null } %}