我正在尝试创建一个解析器,一个文件。我正在尝试使用创建的这个文件由解析器解析。步骤是:
添加 pegjs
使用var parserFile创建解析器
使用var makeFile创建文件
添加 contentFile、nameFile 和 var contentFile、nameFile并在此处:var makeFile
在var makeFile中使用解析器和var parserFile
// @author dikafon
// @license runFile, license: Open source, 05-10-2019
// @readme Include pegs.js and build parser, generate file, include grammar in file, download, run script.rF ( template, output )
var head = document.getElementsByTagName('head')[0];
var fileScript = document.createElement('script');
fileScript.type = 'text/javascript';
fileScript.src = 'https://pegjs.org/vendor/pegjs/peg.js';
head.appendChild(fileScript);
var runFile = (function () {
// make, Grammar
var parserFile;
parserFile = PEG.buildParser(
"start\n"+
"= comment def runFile msgbox rules_list\n"+
"comment = COMSTART (not_com/comment)* COMSTOP\n"+
"not_com = (!COMSTOP !COMSTART.)\n"+
"COMSTART='.'\n"+
"COMSTOP='.'\n"+
"def\n"+
"= def:'runFile'? __ { return runFile; }\n"+
"runFile\n"+
"= runFile:('bat'/'cmd'/'hta'/'vbs'/'rF') _ { return runFile;}\n"+
"msgbox\n"+
"= msgbox:('runFile')_ { return msgbox;}\n"+
"rules_list\n"+
"= '(' _ exp:[a-zA-Z]+ _ ')' { return [ exp.join('') ]; }\n"+
"_ = [ \t\r\n]*\n"+
"__ = [ \t\r\n]"
);
// make, File
var makeFile = document.createElement("a");
document.body.appendChild(a);
makeFile.style = "display: none";
// grammar how 'content, File' && 'name, File'
return function (contentFile, nameFile) {
// setting, file
var define = file,
blob = new Blob([text], {type: "text/plain;charset=utf-8"}),
url = window.URL.createObjectURL(blob);
makeFile.href = url;
makeFile.download = nameFile;
makeFile.click();
window.URL.revokeObjectURL(url);
};
}());
// content, file
var file = (function () {
var contentFile, nameFile, finishFile;
contentFile = (". runFile, license: Open source, 05-10-2019. \n"+ "def
runFile(rF) \n"+"msgbox('runFile');"+"\n");
finishFile = runFile(contentFile , nameFile);
nameFile = "script.rF";
})();
// call, file & grammar
// show
console.log(
". runFile, license: Open source, 05-10-2019. \n"+
"def runFile(rF) \n"+
"msgbox('runFile');"+
"\n"
);
// generate, file and download, run script ( contentFile, nameFile )
// build parser, parser.parse
console.log((parser.parse(runFile(file))));
未捕获的 SyntaxError:意外的标记 ')'
第 1 行,第 1 列:应为“。” 但找到了“2”。