http://pegjs.org/online
Expression
= head:Factor tail:Factor* {
return head + tail.join("");
}
Factor
= "[" expr:Expression "]" { return "[<em>"+expr+"</em>]"; }
/ RegularChar
RegularChar
= [^\[\]]+ { return text(); }
Such as:
[test1] test2 ([[readonly ][optionality ][argumentType ]argumentName[ = defaultValue]]...) [test3] test4
Notice it breaks when there are unclosed [ or unopened ]. Try:
[this one is closed] but [this one is not
If it is OK, then go and generate the .js. If not, edit the grammar until so.