2012-01-04 18:31:19 +00:00
|
|
|
/*\
|
|
|
|
title: js/JavaScriptParser.js
|
|
|
|
|
2012-01-05 10:00:21 +00:00
|
|
|
Parses JavaScript source code into a parse tree using PEGJS
|
2012-01-04 18:31:19 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var JavaScriptParseTree = require("./JavaScriptParseTree.js").JavaScriptParseTree,
|
|
|
|
pegjs = require("pegjs");
|
|
|
|
|
2012-01-05 10:00:21 +00:00
|
|
|
// Initialise the parser
|
2012-01-04 18:31:19 +00:00
|
|
|
var JavaScriptParser = function(parserText) {
|
|
|
|
this.parser = pegjs.buildParser(parserText);
|
|
|
|
};
|
|
|
|
|
2012-01-05 10:00:21 +00:00
|
|
|
// Parse a string of JavaScript code and return the parse tree
|
2012-01-04 18:31:19 +00:00
|
|
|
JavaScriptParser.prototype.parse = function(code) {
|
|
|
|
return new JavaScriptParseTree(this.parser.parse(code),this);
|
|
|
|
};
|
|
|
|
|
2012-01-05 10:00:21 +00:00
|
|
|
// Create a parse tree object from a raw tree
|
2012-01-04 18:31:19 +00:00
|
|
|
JavaScriptParser.prototype.createTree = function(tree) {
|
2012-01-05 10:00:21 +00:00
|
|
|
return new JavaScriptParseTree(tree);
|
2012-01-04 18:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.JavaScriptParser = JavaScriptParser;
|
|
|
|
|
|
|
|
})();
|