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