, JS-, , - , .
JS, PEG.js, . :
{
var functions = {};
var buffer = '';
}
start
= unit* {return functions;}
unit
= func
/ string
/ multi_line_comment
/ single_line_comment
/ any_char
func
= m:multi_line_comment spaces? "function" spaces id:identifier {functions[id] = m;}
/ "function" spaces id:identifier {functions[id] = null;}
multi_line_comment
= "/*"
( !{return buffer.match(/\*\//)} c:. {buffer += c;} )*
{
var temp = buffer;
buffer = '';
return "/*" + temp.replace(/\s+/g, ' ');
}
single_line_comment
= "//" [^\r\n]*
identifier
= a:([a-z] / [A-Z] / "_") b:([a-z] / [A-Z] / [0-9] /"_")* {return a + b.join("");}
spaces
= [ \t\r\n]+ {return "";}
string
= "\"" ("\\" . / [^"])* "\""
/ "'" ("\\" . / [^'])* "'"
any_char
= .
:
function foo(x)
{
...
}
var s = " /* ... */ function notAFunction() {} ... ";
function withoutMultiLineComment() {
}
var t = ' /* ... */ function notAFunction() {} ... ';
function doc_way_above(x, y, z) {
...
}
start() :
{
"foo": "/** * This function does foo. * Call it with bar. Yadda yadda \"groo\". */",
"withoutMultiLineComment": null,
"doc_way_above": "/** * BAR! * Call it? */"
}
, , (, this.id = function() { ... }), PEG.js (, ). , , , .
, !