1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-26 01:50:28 +00:00
TiddlyWiki5/js/JavaScriptParser.js
2012-01-05 10:00:21 +00:00

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;
})();