mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-19 16:24:51 +00:00
33 lines
764 B
JavaScript
33 lines
764 B
JavaScript
/*\
|
|
title: js/JavaScriptParser.js
|
|
|
|
Parses JavaScript source code into a parse tree using PEGJS
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true */
|
|
"use strict";
|
|
|
|
var JavaScriptParseTree = require("./JavaScriptParseTree.js").JavaScriptParseTree,
|
|
pegjs = require("pegjs");
|
|
|
|
// Initialise the parser
|
|
var JavaScriptParser = function(parserText) {
|
|
this.parser = pegjs.buildParser(parserText);
|
|
};
|
|
|
|
// Parse a string of JavaScript code and return the parse tree
|
|
JavaScriptParser.prototype.parse = function(code) {
|
|
return new JavaScriptParseTree(this.parser.parse(code),this);
|
|
};
|
|
|
|
// Create a parse tree object from a raw tree
|
|
JavaScriptParser.prototype.createTree = function(tree) {
|
|
return new JavaScriptParseTree(tree);
|
|
};
|
|
|
|
exports.JavaScriptParser = JavaScriptParser;
|
|
|
|
})();
|