Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80728 views
1
"use strict";
2
var parser = require("./parser")["default"];
3
var AST = require("./ast")["default"];
4
var WhitespaceControl = require("./whitespace-control")["default"];
5
var Helpers = require("./helpers");
6
var extend = require("../utils").extend;
7
8
exports.parser = parser;
9
10
var yy = {};
11
extend(yy, Helpers, AST);
12
13
function parse(input, options) {
14
// Just return if an already-compiled AST was passed in.
15
if (input.type === 'Program') { return input; }
16
17
parser.yy = yy;
18
19
// Altering the shared object here, but this is ok as parser is a sync operation
20
yy.locInfo = function(locInfo) {
21
return new yy.SourceLocation(options && options.srcName, locInfo);
22
};
23
24
var strip = new WhitespaceControl();
25
return strip.accept(parser.parse(input));
26
}
27
28
exports.parse = parse;
29