1 | // @ts-check
|
2 | /** @typedef {import("./parsing/parser").AST} AST */
|
3 |
|
4 | const tokenizer = require("./parsing/tokenizer");
|
5 | const parser = require("./parsing/parser");
|
6 | const transformer = require("./parsing/transformer");
|
7 | const compiler = require("./compilation/compiler");
|
8 |
|
9 | module.exports = {
|
10 | /**
|
11 | * Parses a VMF string into JSON
|
12 | * @param {string} input The VMF source string to parse
|
13 | * @param {Object} options The options object
|
14 | * @returns {AST|Object} Either the AST or the JSON representation, depending on options
|
15 | */
|
16 | parse(input, options) {
|
17 | options = Object.assign({
|
18 | ast: false
|
19 | }, options);
|
20 |
|
21 | const tokens = tokenizer(input);
|
22 | const ast = parser(tokens);
|
23 |
|
24 | return options.ast ? ast : transformer(ast);
|
25 | },
|
26 |
|
27 | /**
|
28 | * Compiles a JSON object into VMF
|
29 | * @param {Object} input The JSON object to compile
|
30 | * @returns {string} The VMF representation
|
31 | */
|
32 | compile(input) {
|
33 | return compiler(input);
|
34 | }
|
35 | }; |
\ | No newline at end of file |