1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00
TiddlyWiki5/js/JavaScriptParser.js

33 lines
764 B
JavaScript
Raw Normal View History

/*\
title: js/JavaScriptParser.js
2012-01-05 10:00:21 +00:00
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");
2012-01-05 10:00:21 +00:00
// Initialise the parser
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
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
JavaScriptParser.prototype.createTree = function(tree) {
2012-01-05 10:00:21 +00:00
return new JavaScriptParseTree(tree);
};
exports.JavaScriptParser = JavaScriptParser;
})();