├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── LICENSE
├── README.md
├── assets
└── expected-types.txt
├── build
├── code-builder.js
├── code-builder.js.map
├── heron-ast-rewrite.js
├── heron-ast-rewrite.js.map
├── heron-compiler.js
├── heron-compiler.js.map
├── heron-defs.js
├── heron-defs.js.map
├── heron-expr.js
├── heron-expr.js.map
├── heron-name-analysis.js
├── heron-name-analysis.js.map
├── heron-normal-form.js
├── heron-normal-form.js.map
├── heron-package.js
├── heron-package.js.map
├── heron-parser.js
├── heron-parser.js.map
├── heron-refs.js
├── heron-refs.js.map
├── heron-statement.js
├── heron-statement.js.map
├── heron-to-glsl.js
├── heron-to-glsl.js.map
├── heron-to-html.js
├── heron-to-html.js.map
├── heron-to-js.js
├── heron-to-js.js.map
├── heron-to-text.js
├── heron-to-text.js.map
├── heron-type-evaluator.js
├── heron-type-evaluator.js.map
├── heron-types.js
├── heron-types.js.map
├── js-intrinsics.js
├── js-intrinsics.js.map
├── tests.js
├── tests.js.map
├── type-parser.js
├── type-parser.js.map
├── type-system.js
├── type-system.js.map
├── utils.js
└── utils.js.map
├── comparison.md
├── demo
├── demo.1.html
├── demo.html
├── js
│ ├── OrbitControls.js.download
│ ├── ParametricGeometries.js.download
│ ├── dat.gui.min.js.download
│ ├── geometry.js.download
│ └── three.min.js.download
├── node_test.js
├── output.js
└── sandbox
│ └── shaders.html
├── history.md
├── img
└── heron-source-torus.png
├── index.html
├── input
├── array.heron
├── geometry-mesh.heron
├── geometry-vector3.heron
├── intrinsics.heron
├── sandbox
│ ├── color.heron
│ ├── experiment-with-interfaces.txt
│ ├── geometry-matrix4x4.heron
│ ├── geometry-quaternion.heron
│ ├── geometry-transform.heron
│ ├── noise.heron
│ ├── seascape.heron
│ ├── simple_optimizer.py
│ ├── square-cubes.heron
│ └── voronoi-distances.heron
└── test.heron
├── node_modules
└── myna-parser
│ ├── .gitattributes
│ ├── .travis.yml
│ ├── .vscode
│ ├── launch.json
│ └── tasks.json
│ ├── LICENSE
│ ├── dist
│ └── myna.min.js
│ ├── docs
│ ├── Common_Myna.png
│ ├── Common_Myna_Thumbnail.png
│ ├── _config.yml
│ ├── android-chrome-192x192.png
│ ├── apple-touch-icon.png
│ ├── browserconfig.xml
│ ├── css
│ │ ├── bootstrap-theme.css
│ │ ├── bootstrap-theme.css.map
│ │ ├── bootstrap-theme.min.css
│ │ ├── bootstrap-theme.min.css.map
│ │ ├── bootstrap.css
│ │ ├── bootstrap.css.map
│ │ ├── bootstrap.min.css
│ │ └── bootstrap.min.css.map
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ ├── favicon.ico
│ ├── fonts
│ │ ├── glyphicons-halflings-regular.eot
│ │ ├── glyphicons-halflings-regular.svg
│ │ ├── glyphicons-halflings-regular.ttf
│ │ ├── glyphicons-halflings-regular.woff
│ │ └── glyphicons-halflings-regular.woff2
│ ├── grammars
│ │ ├── grammar_arithmetic.js
│ │ ├── grammar_csv.js
│ │ ├── grammar_glsl.js
│ │ ├── grammar_heron.js
│ │ ├── grammar_html_reserved_chars.js
│ │ ├── grammar_json.js
│ │ ├── grammar_lucene.js
│ │ ├── grammar_markdown.js
│ │ ├── grammar_mustache.js
│ │ ├── grammar_pithy.js
│ │ └── grammar_template.js
│ ├── index.html
│ ├── js
│ │ ├── bootstrap.js
│ │ ├── bootstrap.min.js
│ │ ├── ie10-viewport-bug-workaround.js
│ │ └── npm.js
│ ├── manifest.json
│ ├── mstile-150x150.png
│ ├── myna.js
│ ├── myna.ts
│ ├── safari-pinned-tab.svg
│ └── tests
│ │ ├── benchmark.js
│ │ ├── glsl_printer.js
│ │ ├── heron_tools.js
│ │ ├── mocha_runner.js
│ │ ├── myna_augment_ast.js
│ │ ├── output_grammars.js
│ │ ├── performance.html
│ │ ├── playground.js
│ │ ├── qunit-2.0.1.css
│ │ ├── qunit-2.0.1.js
│ │ ├── qunit.html
│ │ ├── readme.md
│ │ ├── rule_test_inputs.js
│ │ ├── rule_tester.js
│ │ ├── test_all_tools.js
│ │ ├── test_arithmetic.js
│ │ ├── test_browser_unpkg.html
│ │ ├── test_escape_html_chars.js
│ │ ├── test_glsl.js
│ │ ├── test_lucene.js
│ │ ├── test_markdown_to_html.js
│ │ ├── test_mustache_expander.js
│ │ ├── test_node.js
│ │ ├── test_node_example-1.js
│ │ ├── test_node_example-2.js
│ │ ├── test_parser_failure.js
│ │ ├── test_pithy.js
│ │ ├── test_tools.js
│ │ ├── test_typescript_import.js
│ │ ├── test_typescript_import.js.map
│ │ └── test_typescript_import.ts
│ ├── grammars
│ ├── grammar_arithmetic.js
│ ├── grammar_csv.js
│ ├── grammar_glsl.js
│ ├── grammar_heron.js
│ ├── grammar_html_reserved_chars.js
│ ├── grammar_json.js
│ ├── grammar_lucene.js
│ ├── grammar_markdown.js
│ ├── grammar_mustache.js
│ ├── grammar_pithy.js
│ └── readme.md
│ ├── myna.js
│ ├── myna.js.map
│ ├── myna.ts
│ ├── package.json
│ ├── packages
│ └── myna_markdown_to_html
│ │ └── package.json
│ ├── qunit-2.0.1.js
│ ├── readme.md
│ ├── sandbox
│ ├── grammars_in_progress
│ │ ├── comments.js
│ │ └── javascript_tokens.js
│ └── heron.md
│ ├── test_arithmetic.js
│ ├── tests
│ ├── benchmark.js
│ ├── heron_tools.js
│ ├── input
│ │ ├── 1K_json.js
│ │ └── primitives.heron
│ ├── mocha_runner.js
│ ├── output
│ │ ├── glsl_visitor.js
│ │ └── readme.html
│ ├── output_grammars.js
│ ├── performance.html
│ ├── qunit-2.0.1.css
│ ├── qunit-2.0.1.js
│ ├── qunit.html
│ ├── readme.md
│ ├── rule_test_inputs.js
│ ├── rule_tester.js
│ ├── test_all_tools.js
│ ├── test_browser_unpkg.html
│ ├── test_escape_html_chars.js
│ ├── test_lucene.js
│ ├── test_markdown_to_html.js
│ ├── test_mustache_expander.js
│ ├── test_node.js
│ ├── test_parser_failure.js
│ ├── test_pithy.js
│ ├── test_typescript_import.js
│ ├── test_typescript_import.js.map
│ └── test_typescript_import.ts
│ ├── tools
│ ├── myna_all.js
│ ├── myna_arithmetic_evaluator.js
│ ├── myna_augment_ast.js
│ ├── myna_build_site.js
│ ├── myna_escape_html_chars.js
│ ├── myna_generate_ast_visitor.js
│ ├── myna_markdown_to_html.js
│ ├── myna_mustache_expander.js
│ └── readme.md
│ ├── tsconfig.json
│ └── website
│ ├── index.md
│ └── index.template.html
├── package-lock.json
├── package.json
├── source-browser
├── array.html
├── geometry-mesh.html
├── geometry-vector3.html
├── intrinsics.html
├── styles.css
└── test.html
├── src
├── code-builder.ts
├── heron-ast-rewrite.ts
├── heron-compiler.ts
├── heron-defs.ts
├── heron-expr.ts
├── heron-name-analysis.ts
├── heron-normal-form.ts
├── heron-package.ts
├── heron-parser.ts
├── heron-refs.ts
├── heron-statement.ts
├── heron-to-glsl.ts
├── heron-to-html.ts
├── heron-to-js.ts
├── heron-to-text.ts
├── heron-types.ts
├── js-intrinsics.js
├── tests.ts
├── type-parser.ts
├── type-system.ts
└── utils.ts
├── todo.md
├── tools
├── gen-spec.js
└── gen-visitor.js
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/type-inference/.vscode/tasks.json
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible Node.js debug attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 |
8 | {
9 | "type": "node",
10 | "request": "launch",
11 | "name": "Heron Test Output",
12 | "program": "${workspaceRoot}/demo/node_test.js",
13 | "cwd": "${workspaceRoot}",
14 | "outFiles": ["${workspaceRoot}/build/**/*.js"],
15 | "sourceMaps": true
16 | },
17 | {
18 | "type": "node",
19 | "request": "launch",
20 | "name": "Launch Program",
21 | "program": "${workspaceRoot}/build/tests.js",
22 | "cwd": "${workspaceRoot}",
23 | "outFiles": ["${workspaceRoot}/build/**/*.js"],
24 | "sourceMaps": true
25 | },
26 | {
27 | "type": "node",
28 | "request": "attach",
29 | "name": "Attach to Process",
30 | "port": 5858,
31 | "outFiles": [],
32 | "timeout": 30000,
33 | "sourceMaps": true
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.0",
3 |
4 | // The command is tsc.
5 | "command": "tsc",
6 |
7 | // Show the output window only if unrecognized errors occur.
8 | "showOutput": "always",
9 |
10 | // Under windows use tsc.exe. This ensures we don't need a shell.
11 | "windows": {
12 | "command": "tsc"
13 | },
14 |
15 | // args is the program to compile.
16 | "args": ["--watch"],
17 |
18 | "isShellCommand": true,
19 |
20 | // use the standard tsc problem matcher to find compile problems
21 | // in the output.
22 | "problemMatcher": "$tsc"
23 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Christopher Diggins
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/build/code-builder.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | //=====================================
3 | // Helper class for constructing pretty printerd code
4 | // this is passed as a "state" object to visitors
5 | Object.defineProperty(exports, "__esModule", { value: true });
6 | function count(s, sub) {
7 | return s.split(sub).length - 1;
8 | }
9 | var CodeBuilder = /** @class */ (function () {
10 | function CodeBuilder() {
11 | this.lines = [];
12 | this.indent = 0;
13 | }
14 | Object.defineProperty(CodeBuilder.prototype, "indentString", {
15 | get: function () {
16 | var r = '';
17 | for (var i = 0; i < this.indent; ++i)
18 | r += ' ';
19 | return r;
20 | },
21 | enumerable: true,
22 | configurable: true
23 | });
24 | CodeBuilder.prototype.pushLine = function (s) {
25 | if (s === void 0) { s = ''; }
26 | this.push(s + '\n');
27 | this.lines.push(this.indentString);
28 | };
29 | CodeBuilder.prototype.push = function (s) {
30 | var indentDelta = count(s, '{') - count(s, '}');
31 | indentDelta += count(s, '(') - count(s, ')');
32 | this.indent += indentDelta;
33 | if (indentDelta < 0) {
34 | if (this.lines.length > 0) {
35 | var lastLine = this.lines[this.lines.length - 1].trim();
36 | if (lastLine.length === 0) {
37 | this.lines.pop();
38 | this.lines.push(this.indentString);
39 | }
40 | }
41 | }
42 | this.lines.push(s);
43 | };
44 | CodeBuilder.prototype.toString = function () {
45 | return this.lines.join('');
46 | };
47 | return CodeBuilder;
48 | }());
49 | exports.CodeBuilder = CodeBuilder;
50 | //# sourceMappingURL=code-builder.js.map
--------------------------------------------------------------------------------
/build/code-builder.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"code-builder.js","sourceRoot":"","sources":["../src/code-builder.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,sDAAsD;AACtD,iDAAiD;;AAEjD,eAAe,CAAS,EAAE,GAAW;IACjC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACnC,CAAC;AAED;IAAA;QAEI,UAAK,GAAa,EAAE,CAAC;QACrB,WAAM,GAAW,CAAC,CAAC;IA6BvB,CAAC;IA5BG,sBAAI,qCAAY;aAAhB;YACI,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,GAAG,CAAC,CAAC,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC9B,CAAC,IAAI,IAAI,CAAC;YACd,MAAM,CAAC,CAAC,CAAC;QACb,CAAC;;;OAAA;IACD,8BAAQ,GAAR,UAAS,CAAc;QAAd,kBAAA,EAAA,MAAc;QACnB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IACD,0BAAI,GAAJ,UAAK,CAAS;QACV,IAAI,WAAW,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAChD,WAAW,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC;QAC3B,EAAE,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC;YAClB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;gBACxB,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACxD,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;oBACxB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;oBACjB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACvC,CAAC;YACL,CAAC;QACL,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,8BAAQ,GAAR;QACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IACL,kBAAC;AAAD,CAAC,AAhCD,IAgCC;AAhCY,kCAAW"}
--------------------------------------------------------------------------------
/build/heron-compiler.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var heron_parser_1 = require("./heron-parser");
4 | var heron_package_1 = require("./heron-package");
5 | var heron_types_1 = require("./heron-types");
6 | var g = heron_parser_1.heronGrammar;
7 | var fs = require('fs');
8 | var path = require('path');
9 | // TODO: use or throw out.
10 | //const nodePackage = JSON.parse(fs.readFileSync('package.json','utf8'));
11 | //const ver = nodePackage.version;
12 | //const flavor = 'std';
13 | var ext = '.heron';
14 | // Module resolution
15 | exports.moduleFolder = path.join('.', 'input');
16 | exports.outputFolder = path.join('.', 'output');
17 | exports.intrinsicModules = ['intrinsics'];
18 | exports.modules = [];
19 | //================================================================
20 | // Main functions
21 | function createPackage(moduleNames) {
22 | var pkg = new heron_package_1.Package();
23 | // Load the intrinsic (built-in) modules
24 | for (var _i = 0, intrinsicModules_1 = exports.intrinsicModules; _i < intrinsicModules_1.length; _i++) {
25 | var name_1 = intrinsicModules_1[_i];
26 | addModuleToPackage(name_1, true, pkg);
27 | }
28 | // Load the specified modules (any order)
29 | for (var _a = 0, moduleNames_1 = moduleNames; _a < moduleNames_1.length; _a++) {
30 | var name_2 = moduleNames_1[_a];
31 | addModuleToPackage(name_2, false, pkg);
32 | }
33 | // The package is doing the heavy lifting
34 | pkg.processModules();
35 | // Compute types
36 | for (var _b = 0, _c = pkg.allVarDefs; _b < _c.length; _b++) {
37 | var v = _c[_b];
38 | heron_types_1.computeVarType(v);
39 | }
40 | // Compute types
41 | for (var _d = 0, _e = pkg.allFuncDefs; _d < _e.length; _d++) {
42 | var f = _e[_d];
43 | heron_types_1.computeFuncType(f);
44 | }
45 | return pkg;
46 | }
47 | exports.createPackage = createPackage;
48 | function addModuleToPackage(name, intrinsic, pkg) {
49 | var modulePath = moduleNameToPath(name);
50 | var ast = parseFile(modulePath);
51 | if (ast)
52 | pkg.addFile(ast, intrinsic, modulePath);
53 | }
54 | exports.addModuleToPackage = addModuleToPackage;
55 | function moduleNameToPath(f) {
56 | return path.join(exports.moduleFolder, f + ext);
57 | }
58 | exports.moduleNameToPath = moduleNameToPath;
59 | function parseModule(moduleName) {
60 | var modulePath = moduleNameToPath(moduleName);
61 | return parseFile(modulePath);
62 | }
63 | exports.parseModule = parseModule;
64 | function parseFile(f) {
65 | try {
66 | var code = fs.readFileSync(f, 'utf-8');
67 | var ast = heron_parser_1.parseHeron(code, g.file);
68 | return ast;
69 | }
70 | catch (e) {
71 | console.log("An error occurred while parsing " + f);
72 | console.log(e.message);
73 | return null;
74 | }
75 | }
76 | exports.parseFile = parseFile;
77 | //# sourceMappingURL=heron-compiler.js.map
--------------------------------------------------------------------------------
/build/heron-compiler.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"heron-compiler.js","sourceRoot":"","sources":["../src/heron-compiler.ts"],"names":[],"mappings":"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"}
--------------------------------------------------------------------------------
/build/heron-name-analysis.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"heron-name-analysis.js","sourceRoot":"","sources":["../src/heron-name-analysis.ts"],"names":[],"mappings":"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"}
--------------------------------------------------------------------------------
/build/heron-normal-form.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Heron Normal Form (HNF)
3 | *
4 | * An intermediate compiler representation for optimization, transformation, code-generation,
5 | * analysis, and evaluation.
6 | *
7 | * Expression ::=
8 | * | Non-function (Bool, Int, Float, String, etc.)
9 | * | Function
10 | * | Function Set (Array of possible functions)
11 | * | Closure (Function + Closure record)
12 | * | Free variable (reference to entry in closure record)
13 | * | Parameter (bound variable)
14 | * | Function call (Function + Array of Expressions)
15 | * | Condition ( Expression ? Expression : Expression )
16 | *
17 | * Other intermediate forms to look at:
18 | * * https://en.wikipedia.org/wiki/A-normal_form.
19 | * * https://en.wikipedia.org/wiki/Static_single_assignment_form
20 | * * https://en.wikipedia.org/wiki/Continuation-passing_style
21 | */
22 | //# sourceMappingURL=heron-normal-form.js.map
--------------------------------------------------------------------------------
/build/heron-normal-form.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"heron-normal-form.js","sourceRoot":"","sources":["../src/heron-normal-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
--------------------------------------------------------------------------------
/build/heron-refs.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | // This module provides support for dealing with reference.
3 | // A reference is a name (identifier) that refers to a definition.
4 | // There can be more than one definitions (for examples when dealing with overloaded functions)
5 | var __extends = (this && this.__extends) || (function () {
6 | var extendStatics = Object.setPrototypeOf ||
7 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9 | return function (d, b) {
10 | extendStatics(d, b);
11 | function __() { this.constructor = d; }
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 | };
14 | })();
15 | Object.defineProperty(exports, "__esModule", { value: true });
16 | var heron_ast_rewrite_1 = require("./heron-ast-rewrite");
17 | // A reference to one or more definitions.
18 | var Ref = /** @class */ (function () {
19 | function Ref(node, name, scope, defs) {
20 | this.node = node;
21 | this.name = name;
22 | this.scope = scope;
23 | this.defs = defs;
24 | node.ref = this;
25 | if (defs.length === 0)
26 | heron_ast_rewrite_1.throwError(node, 'No definition found for ' + name);
27 | }
28 | Ref.prototype.toString = function () {
29 | return this.name + '_' + this.node['id'] + ':' + this.node.name + '[' + this.defs.join(', ') + ']';
30 | };
31 | return Ref;
32 | }());
33 | exports.Ref = Ref;
34 | var VarRef = /** @class */ (function (_super) {
35 | __extends(VarRef, _super);
36 | function VarRef(node, name, scope, def) {
37 | var _this = _super.call(this, node, name, scope, [def]) || this;
38 | _this.node = node;
39 | _this.name = name;
40 | _this.scope = scope;
41 | _this.def = def;
42 | return _this;
43 | }
44 | return VarRef;
45 | }(Ref));
46 | exports.VarRef = VarRef;
47 | var ForLoopVarRef = /** @class */ (function (_super) {
48 | __extends(ForLoopVarRef, _super);
49 | function ForLoopVarRef(node, name, scope, def) {
50 | var _this = _super.call(this, node, name, scope, [def]) || this;
51 | _this.node = node;
52 | _this.name = name;
53 | _this.scope = scope;
54 | _this.def = def;
55 | return _this;
56 | }
57 | return ForLoopVarRef;
58 | }(Ref));
59 | exports.ForLoopVarRef = ForLoopVarRef;
60 | var FuncParamRef = /** @class */ (function (_super) {
61 | __extends(FuncParamRef, _super);
62 | function FuncParamRef(node, name, scope, def) {
63 | var _this = _super.call(this, node, name, scope, [def]) || this;
64 | _this.node = node;
65 | _this.name = name;
66 | _this.scope = scope;
67 | _this.def = def;
68 | return _this;
69 | }
70 | return FuncParamRef;
71 | }(Ref));
72 | exports.FuncParamRef = FuncParamRef;
73 | var TypeRef = /** @class */ (function (_super) {
74 | __extends(TypeRef, _super);
75 | function TypeRef(node, name, scope, def) {
76 | var _this = _super.call(this, node, name, scope, [def]) || this;
77 | _this.node = node;
78 | _this.name = name;
79 | _this.scope = scope;
80 | _this.def = def;
81 | return _this;
82 | }
83 | return TypeRef;
84 | }(Ref));
85 | exports.TypeRef = TypeRef;
86 | var TypeParamRef = /** @class */ (function (_super) {
87 | __extends(TypeParamRef, _super);
88 | function TypeParamRef(node, name, scope, def) {
89 | var _this = _super.call(this, node, name, scope, [def]) || this;
90 | _this.node = node;
91 | _this.name = name;
92 | _this.scope = scope;
93 | _this.def = def;
94 | return _this;
95 | }
96 | return TypeParamRef;
97 | }(Ref));
98 | exports.TypeParamRef = TypeParamRef;
99 | var FuncRef = /** @class */ (function (_super) {
100 | __extends(FuncRef, _super);
101 | function FuncRef(node, name, scope, defs) {
102 | var _this = _super.call(this, node, name, scope, defs) || this;
103 | _this.node = node;
104 | _this.name = name;
105 | _this.scope = scope;
106 | _this.defs = defs;
107 | return _this;
108 | }
109 | return FuncRef;
110 | }(Ref));
111 | exports.FuncRef = FuncRef;
112 | //# sourceMappingURL=heron-refs.js.map
--------------------------------------------------------------------------------
/build/heron-refs.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"heron-refs.js","sourceRoot":"","sources":["../src/heron-refs.ts"],"names":[],"mappings":"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"}
--------------------------------------------------------------------------------
/build/heron-type-evaluator.js:
--------------------------------------------------------------------------------
1 | //# sourceMappingURL=heron-type-evaluator.js.map
--------------------------------------------------------------------------------
/build/heron-type-evaluator.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"heron-type-evaluator.js","sourceRoot":"","sources":["../src/heron-type-evaluator.ts"],"names":[],"mappings":""}
--------------------------------------------------------------------------------
/build/js-intrinsics.js:
--------------------------------------------------------------------------------
1 | function arrayFromJavaScript(xs) {
2 | return {
3 | count: xs.length,
4 | array: xs,
5 | at: function (i) { return xs[i]; }
6 | };
7 | }
8 | function toMutable(xs) {
9 | var count = xs.count;
10 | var array = [];
11 | for (var i = 0; i < count; ++i)
12 | array.push(xs.at(i));
13 | return arrayFromJavaScript(array);
14 | }
15 | function int(x) { return Math.round(x); }
16 | function float(x) { return x; }
17 | function float2(x, y) { return ({ x: x, y: y }); }
18 | function float3(x, y, z) { return ({ x: x, y: y, z: z }); }
19 | function float4(x, y, z, w) { return ({ x: x, y: y, z: z, w: w }); }
20 | function x(v) { return v.x; }
21 | function y(v) { return v.y; }
22 | function z(v) { return v.z; }
23 | function w(v) { return v.w; }
24 | function abs(x) { return Math.abs(x); }
25 | function acos(x) { return Math.acos(x); }
26 | function asin(x) { return Math.asin(x); }
27 | function atan(x) { return Math.atan(x); }
28 | function atan2(y, x) { return Math.atan2(y, x); }
29 | function ceil(x) { return Math.ceil(x); }
30 | function cos(x) { return Math.cos(x); }
31 | function exp(x) { return Math.exp(x); }
32 | function floor(x) { return Math.floor(x); }
33 | function log(x) { return Math.log(x); }
34 | function pow(x, y) { return Math.pow(x, y); }
35 | function round(x) { return Math.round(x); }
36 | function sin(x) { return Math.sin(x); }
37 | function sqrt(x) { return Math.sqrt(x); }
38 | function tan(x) { return Math.tan(x); }
39 | function clamp(x, min, max) { return x < min ? min : x > max ? max : x; }
40 | ;
41 | function sign(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; }
42 | ;
43 | function op_add(x, y) { return x + y; }
44 | ;
45 | function op_sub(x, y) { return x - y; }
46 | ;
47 | function op_mul(x, y) { return x * y; }
48 | ;
49 | function op_div(x, y) { return x / y; }
50 | ;
51 | function op_mod(x, y) { return x % y; }
52 | ;
53 | function op_gt(x, y) { return x > y; }
54 | ;
55 | function op_gt_eq(x, y) { return x >= y; }
56 | ;
57 | function op_lt(x, y) { return x < y; }
58 | ;
59 | function op_lt_eq(x, y) { return x <= y; }
60 | ;
61 | function op_not_eq(x, y) { return x !== y; }
62 | ;
63 | function op_eq_eq(x, y) { return x === y; }
64 | ;
65 | function op_amp_amp(x, y) { return x && y; }
66 | ;
67 | function op_bar_bar(x, y) { return x || y; }
68 | ;
69 | function op_hat_hat(x, y) { return !!(x ^ y); }
70 | ;
71 | function op_not(x) { return !x; }
72 | ;
73 | function op_negate(x) { return -x; }
74 | ;
75 | function count(xs) { return xs.count; }
76 | ;
77 | function at(xs, i) { return xs.at(i); }
78 | ;
79 | function array(count, at) { return { count: count, at: at }; }
80 | function mutable(x) { return toMutable(x); }
81 | function immutable(xs) { return array(xs.array.length, xs.at); }
82 | function push(xs, x) { return (xs.array.push(x), xs); }
83 | ;
84 | function set(xs, i, x) { return (xs.array[i] = x, xs); }
85 | ;
86 | function print(x) { return console.log(x); }
87 | function assert(condition) { if (!condition)
88 | throw new Error("assertion failed"); }
89 | ;
90 | function mesh(vertexBuffer, indexBuffer) { return ({ vertexBuffer: vertexBuffer, indexBuffer: indexBuffer }); }
91 | ;
92 | function vertexBuffer(mesh) { return mesh.vertexBuffer; }
93 | ;
94 | function indexBuffer(mesh) { return mesh.indexBuffer; }
95 | ;
96 | //# sourceMappingURL=js-intrinsics.js.map
--------------------------------------------------------------------------------
/build/type-parser.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var type_system_1 = require("./type-system");
4 | var myna_parser_1 = require("myna-parser");
5 | // Defines syntax parsers for type expression, the lambda calculus, and Cat
6 | function registerGrammars() {
7 | // A simple grammar for parsing type expressions
8 | var TypeGrammar = /** @class */ (function () {
9 | function TypeGrammar() {
10 | var _this = this;
11 | this.typeExprRec = myna_parser_1.Myna.delay(function () { return _this.typeExpr; });
12 | this.typeList = myna_parser_1.Myna.guardedSeq('(', myna_parser_1.Myna.ws, this.typeExprRec.ws.zeroOrMore, ')').ast;
13 | this.typeVar = myna_parser_1.Myna.guardedSeq("'", myna_parser_1.Myna.identifier).ast;
14 | this.typeConstant = myna_parser_1.Myna.identifier.or(myna_parser_1.Myna.digits).or("->").or("*").or("[]").ast;
15 | this.typeExpr = myna_parser_1.Myna.choice(this.typeList, this.typeVar, this.typeConstant).ast;
16 | }
17 | return TypeGrammar;
18 | }());
19 | var typeGrammar = new TypeGrammar();
20 | myna_parser_1.Myna.registerGrammar('type', typeGrammar, typeGrammar.typeExpr);
21 | }
22 | registerGrammars();
23 | exports.typeParser = myna_parser_1.Myna.parsers['type'];
24 | function parseType(input) {
25 | var ast = exports.typeParser(input);
26 | if (ast.end != input.length)
27 | throw new Error("Only part of input was consumed");
28 | return astToType(ast);
29 | }
30 | exports.parseType = parseType;
31 | function astToType(ast) {
32 | if (!ast)
33 | return null;
34 | switch (ast.name) {
35 | case "typeVar":
36 | return type_system_1.typeVariable(ast.allText.substr(1));
37 | case "typeConstant":
38 | return type_system_1.typeConstant(ast.allText);
39 | case "typeList":
40 | return type_system_1.polyType(ast.children.map(astToType));
41 | case "typeExpr":
42 | if (ast.children.length != 1)
43 | throw new Error("Expected only one child of node, not " + ast.children.length);
44 | return astToType(ast.children[0]);
45 | default:
46 | throw new Error("Unrecognized type expression: " + ast.name);
47 | }
48 | }
49 | //# sourceMappingURL=type-parser.js.map
--------------------------------------------------------------------------------
/build/type-parser.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"type-parser.js","sourceRoot":"","sources":["../src/type-parser.ts"],"names":[],"mappings":";;AAAA,6CAA2E;AAC3E,2CAAuC;AAEvC,4EAA4E;AAC5E;IAEI,gDAAgD;IAChD;QAAA;YAAA,iBAOC;YALG,gBAAW,GAAM,kBAAC,CAAC,KAAK,CAAC,cAAM,OAAA,KAAI,CAAC,QAAQ,EAAb,CAAa,CAAC,CAAC;YAC9C,aAAQ,GAAS,kBAAC,CAAC,UAAU,CAAC,GAAG,EAAE,kBAAC,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC;YAClF,YAAO,GAAU,kBAAC,CAAC,UAAU,CAAC,GAAG,EAAE,kBAAC,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC;YACrD,iBAAY,GAAK,kBAAC,CAAC,UAAU,CAAC,EAAE,CAAC,kBAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;YACzE,aAAQ,GAAS,kBAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;QAClF,CAAC;QAAD,kBAAC;IAAD,CAAC,AAPD,IAOC;IACD,IAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,kBAAC,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;AAEjE,CAAC;AAED,gBAAgB,EAAE,CAAC;AAEN,QAAA,UAAU,GAAI,kBAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7C,mBAA0B,KAAY;IAClC,IAAI,GAAG,GAAG,kBAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACvD,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AALD,8BAKC;AAED,mBAAmB,GAAQ;IACvB,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACL,MAAM,CAAC,IAAI,CAAC;IAChB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CACjB,CAAC;QACG,KAAK,SAAS;YACV,MAAM,CAAC,0BAAY,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,KAAK,cAAc;YACf,MAAM,CAAC,0BAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,UAAU;YACX,MAAM,CAAC,sBAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QACjD,KAAK,UAAU;YACX,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnF,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC;YACI,MAAM,IAAI,KAAK,CAAC,gCAAgC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;AACL,CAAC"}
--------------------------------------------------------------------------------
/build/utils.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | function trace(label, message) {
4 | //console.log(message);
5 | }
6 | exports.trace = trace;
7 | //# sourceMappingURL=utils.js.map
--------------------------------------------------------------------------------
/build/utils.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAEA,eAAsB,KAAiB,EAAE,OAAe;IACpD,uBAAuB;AAC3B,CAAC;AAFD,sBAEC"}
--------------------------------------------------------------------------------
/comparison.md:
--------------------------------------------------------------------------------
1 | ## Heron Compared to TypeScript / JavaScript
2 |
3 | Heron most closely resembles a subset of the JavaScript language. It has a type system that is more restricted than TypeScript, but the type-inference system is more aggressive. For example Heron function parameter types are inferred based on usage in the function defintion, as opposed to resolving to `any`.
4 |
5 | The biggest standout difference is that Heron has no concept of classes or prototypes.
6 |
7 | Heron is an unordered list of various differences Heron has with TypeScript/JavaScript:
8 |
9 | * only primitive types, generic types (including array and function), and type variables
10 | * no object literals
11 | * no `this` keyword
12 | * functions can be called using dot notation on the first argument
13 | * functions can be ovoverloaded (two functions can have the same name if the inferred types are different)
14 | * operators can be overloaded
15 | * operators can be passed as functions
16 | * `var` statements are equivalent to `let` statements in TypeScript/JavaScript
17 | * no `const` statements
18 | * module level variables cannot be modified
19 | * variable types are inferred
20 | * parameter and return types of functions are inferred
21 | * variables have to always be initialized
22 | * variable binding expression allows variable declarations to be used as expressions
23 | * arrays are immutable
24 | * modifying arrays can only be done with `ArrayBuilder`
25 | * each `ArrayBuilder` modification creates a new array
26 | * only supports a `for..in` loop form which is the same as `for..of` loop in JavaScript
27 | * a built-in range operator `from..to` generates an array of contiguous values (exclusive upper bound)
28 | * arrays do not necessarily allocate memory, e.g. 0..100000000, has O(1) memory consumption
29 | * module names are URN's with the version number encoded in it
30 | * all files specify the version of the language
31 | * all definitions must be in a module
32 | * variables cannot be reassigned to objects of a different type
33 | * no `async` or `await` support
34 | * no operators spread support
35 | * no class or interface definitions
36 | * anonymous functions use a *fat arrow* syntax
37 | * Separation betwen integers (`Int`) and floating point numbers (`Float`)
38 | * Support for two, three, and four dimensional numerical types like in GLSL (`Float2`, `Float3`, `Float4`).
39 | * Semicolons are required as statement terminators.
40 | * No statement labels
41 | * No comma operator
42 | * No switch statement
43 |
--------------------------------------------------------------------------------
/demo/node_test.js:
--------------------------------------------------------------------------------
1 | require('./output.js');
2 | process.exit();
--------------------------------------------------------------------------------
/demo/sandbox/shaders.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
27 |
28 |
29 |
46 |
47 |
--------------------------------------------------------------------------------
/history.md:
--------------------------------------------------------------------------------
1 |
2 | # History of Heron
3 |
4 | ### Why throw away a good name?
5 |
6 | This is technically the third incarnation of the programming language Heron, but only a handful of people will remember the older versions. The last time I announced a programming language named Heron was in 2010. Previous incarnations were intended as general purpose languages whereas Heron is now much more focused in scope and purpose. However, much of the original philosophy and intention is present in the language so I've decided to stick to the name.
7 |
8 | The first large public announcement of the original Heron language was in 2006 https://developers.slashdot.org/story/04/12/08/1944233/introducing-the-heron-programming-language. That implementation was a Heron to C++ translator. It's primary contribution was a more advanced meta-programming system for C++ and a more regular syntax. At that time the another systems language was being developed by Walter Bright called D, which had similar design goals.
9 |
10 | Heron underwent several modifications and extensions and was revived in 2010 http://www.artima.com/weblogs/viewpost.jsp?thread=284558 with many new features. Achilleas Margaritas described the differences as "this new Heron seems to be a very different beast. It seems to be an enterprise-friendly application language like Java and C#, rather than a system/application one like C and C++.". This reflected my new found interest in C#, and the idea of code and diagrams being closely related.
11 |
12 | After finishing a working implementation of the new version of Heron, I realized that I had created a general purpose programming language that had no tool support, no community, and no libraries. Convincing any professional software developer to use Heron as opposed to an entrenched general purpose languages (C++, Java, C#, Scala, etc.) was going to be effectively impossible. I decided at that point to put Heron on ice and focus on other things.
13 |
14 | After spending several years working with 3D and animation software, including designing a visual programming language for 3D processing (Max Creation Graph), I've realized that there is a real need for an easy to use yet efficient programming language, which can target multiple platforms. Therefore I decided to reincarnate Heron as a programming language that specializes in efficient array and numerical processing, but that has the look and feel of JavaScript.
15 |
16 | I've found it to be a very pleasant experience writing libraries in Heron for array, numerical, 2D, and 3D processing. I hope you enjoy it as well, and I'd appreciate your feedback on how I can make it better!
17 |
18 | ## Postscript: May 7th 2023
19 |
20 | It has been five years since I have contributed to Heron. After releasing a v0.1 version of Heron that had
21 | a very powerful type-inference system and a syntax which I found agreeable, I realized that the next steps of
22 | getting people to use the language would be virtually insurmountable.
23 |
24 | How do you convince people to use a new language with extremely limited tooling, no libraries, and
25 | the only advantage is a nicer syntax with less type annotations? People already had enough languages
26 | to choose from, and type-safety with simpler syntax wasn't a strong enough motivator.
27 |
28 | In the last few years I moved back to primarily C# development in the realm of real-time 3D graphics.
29 | I developed numerous libraries and software using a primarily functional style of programming.
30 | Pure functional programming in C# works surprisingly well for real-time 3D graphics processing, it
31 | can produce very robust and relatively efficient code.
32 |
33 | However there were still limitations: the C# compiler still does not do a particularly good job of optimizing
34 | functional code, C# cannot be run efficiently in the browser, and writing numerical code in a pure functional
35 | style requires a ton of boilerplate.
36 |
37 | This inspired me to develop a language that would allow me to write my algorithms and data-structures in a C#
38 | style language while targetting multiple languages and platforms, with less boilerplate, and that could
39 | be easily optimized.
40 |
41 | This [new programming language is called Plato](https://github.com/cdiggins/plato) and it borrows many of the ideas
42 | and design goals of Heron. It is a more ambitious project with more features and is being built with the aim of
43 | bootstrapping itself.
44 |
--------------------------------------------------------------------------------
/img/heron-source-torus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/img/heron-source-torus.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Heron
4 |
5 |
11 |
12 |
13 |
14 |
15 | Heron Language 3D Geometry Demo
16 |
17 |
18 |
19 |
20 | Heron is a new statically typed functional programming
21 | language with a JavaScript-like syntax that specializes in the processing of arrays of numerical data.
22 |
23 |
24 | This demo uses Heron to generate mesh data (vertices, faces, and colors)
25 | and uses Three.JS to display the resulting geometry.
26 | Browse the source code here:
27 |
33 |
34 |
35 | If you are interested in learning more, or collaborating please reach out to me,
36 | Christopher Diggins , via email
37 | LinkedIn , Twitter ,
38 | or GitHub .
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/input/geometry-vector3.heron:
--------------------------------------------------------------------------------
1 | language heron:std:0.1;
2 |
3 | module heron:geometry.vector:0.1
4 | {
5 | // Several algorithms inspired by the following:
6 | // https://referencesource.microsoft.com/#System.Numerics/System/Numerics/Vector3
7 | // https://referencesource.microsoft.com/#System.Numerics/System/Numerics/Vector3_Intrinsics.cs
8 |
9 | // Variables
10 |
11 | var origin = vector(0, 0, 0);
12 | var ones = vector(1, 1, 1);
13 | var xaxis = vector(1, 0, 0);
14 | var yaxis = vector(0, 1, 0);
15 | var zaxis = vector(0, 0, 1);
16 |
17 | // Functions
18 |
19 | function vector(x: Float, y: Float, z: Float)
20 | = float3(x, y, z);
21 |
22 | function vector(x: Float)
23 | = vector(x, x, x);
24 |
25 | /*
26 | function vector(xs)
27 | = vector(xs[0], xs[1], xs[2]);
28 | */
29 |
30 | function array(v)
31 | = [v.x, v.y, v.z];
32 |
33 | function sumComponents(v)
34 | = v.x + v.y + v.z;
35 |
36 | function dot(a, b)
37 | = sumComponents(a * b);
38 |
39 | function length(v)
40 | = sqrt(v.length2);
41 |
42 | function length2(v)
43 | = v.dot(v);
44 |
45 | function distance(a, b)
46 | = (a - b).length;
47 |
48 | function distance2(a, b)
49 | = (a - b).length2;
50 |
51 | function normal(v)
52 | = v / v.length.vector;
53 |
54 | function cross(a, b)
55 | = vector(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
56 |
57 | function reflect(v, n)
58 | = v - (n * dot(v, n) * 2.0);
59 |
60 | function lerp(a, b, x)
61 | = a * (1.0 - x) + b * x;
62 |
63 | function negate(v)
64 | = vector(-v.x, -v.y, -v.z);
65 | }
--------------------------------------------------------------------------------
/input/sandbox/color.heron:
--------------------------------------------------------------------------------
1 | module color
2 | {
3 | function HUEtoRGB(hue) {
4 | var H = mod(hue,1.0);
5 | var R = abs(H * 6.0 - 3.0) - 1.0;
6 | var G = 2.0 - abs(H * 6.0 - 2.0);
7 | var B = 2.0 - abs(H * 6.0 - 4.0);
8 | return clamp(vec(R,G,B),0.0,1.0);
9 | }
10 |
11 | function HSLtoRGB(HSL) {
12 | var RGB = HUEtoRGB(HSL.x);
13 | var C = (1.0 - abs(2.0 * HSL.z - 1.0)) * HSL.y;
14 | return (RGB - 0.5) * C.vector + HSL.z.vector;
15 | }
16 | }
--------------------------------------------------------------------------------
/input/sandbox/experiment-with-interfaces.txt:
--------------------------------------------------------------------------------
1 | language heron:std:0.1;
2 |
3 | // An intrinsic is a function that has an implementation provided by the compiler.
4 |
5 | module heron:intrinsics:0.1
6 | {
7 | // These are core types
8 | type Float;
9 | type Float2;
10 | type Float3;
11 | type Float4;
12 | type Bool;
13 | type String;
14 | type Array;
15 |
16 | // These are interface (aka traits or protocols)
17 | interface INumerical;
18 | interface IOrderable;
19 | interface IComparable;
20 |
21 | var pi = 3.14159265358979323846;
22 | var e = 2.71828182845904523536;
23 |
24 | intrinsic float2(x: Float, y: Float): Float2;
25 | intrinsic x(v: Float2): Float;
26 | intrinsic y(v: Float2): Float;
27 |
28 | intrinsic float3(x: Float, y: Float, z: Float): Float3;
29 | intrinsic x(v: Float3): Float;
30 | intrinsic y(v: Float3): Float;
31 | intrinsic z(v: Float3): Float;
32 |
33 | intrinsic float4(x: Float, y: Float, z: Float, w: Float): Float4;
34 | intrinsic x(v: Float4): Float;
35 | intrinsic y(v: Float4): Float;
36 | intrinsic z(v: Float4): Float;
37 | intrinsic w(v: Float4): Float;
38 |
39 | interface INumerical
{
40 | abs(x: T): T;
41 | acos(x: T): T;
42 | asin(x: T): T;
43 | atan(x: T): T;
44 | atan2(y: T, x: T): T;
45 | ceil(x: T): T;
46 | clamp(x: T, min: T, max: T): T;
47 | cos(x: T): T;
48 | exp(x: T): T;
49 | floor(x: T): T;
50 | log(x: T): T;
51 | max(x: T, y: T): T;
52 | min(x: T, y: T): T;
53 | pow(x: T, y: T): T;
54 | round(x: T): T;
55 | sin(x: T): T;
56 | sign(x: T): T;
57 | sqrt(x: T): T;
58 | tan(x: T): T;
59 |
60 | op+ (x: T, y: T): T;
61 | op- (x: T, y: T): T;
62 | op* (x: T, y: T): T;
63 | op/ (x: T, y: T): T;
64 | op% (x: T, y: T): T;
65 | }
66 |
67 | map(v: Vector2, f)
68 | = vector2(f(v.x), f(v.y));
69 |
70 | map(v: Vector3, f)
71 | = vector3(f(v.x), f(v.y), f(v.z));
72 |
73 | map(v: Vector4, f)
74 | = vector4(f(v.x), f(v.y), f(v.z), f(v.z));
75 |
76 | // Ignores the 'integer'
77 | abs, U: INumerical>(x: T)
78 | = x.map(abs);
79 |
80 | acos(x: T): T;
81 | asin(x: T): T;
82 | atan(x: T): T;
83 | atan2(y: T, x: T): T;
84 | ceil(x: T): T;
85 | clamp(x: T, min: T, max: T): T;
86 | cos(x: T): T;
87 | exp(x: T): T;
88 | floor(x: T): T;
89 | log(x: T): T;
90 | max(x: T, y: T): T;
91 | min(x: T, y: T): T;
92 | pow(x: T, y: T): T;
93 | round(x: T): T;
94 | sin(x: T): T;
95 | sign(x: T): T;
96 | sqrt(x: T): T;
97 | tan(x: T): T;
98 |
99 | op+ (x: T, y: T): T;
100 | op- (x: T, y: T): T;
101 | op* (x: T, y: T): T;
102 | op/ (x: T, y: T): T;
103 | op% (x: T, y: T): T;
104 |
105 | interface IMappable {
106 | map(x: T, f: (U) -> U)): T;
107 | }
108 |
109 | interface IOrderable {
110 | op> (x: T, y: T): Bool;
111 | op>= (x: T, y: T): Bool;
112 | op< (x: T, y: T): Bool;
113 | op<= (x: T, y: T): Bool;
114 | }
115 |
116 | interface IEquatable {
117 | op!= (x: T, y: T): Bool;
118 | op== (x: T, y: T): Bool;
119 | }
120 |
121 | // Special operators that have identifier names
122 | op_at(x: Array, i: Int): Any;
123 | op_range(from: Int, to: Int): Array;
124 | op_not(x: Bool): Bool;
125 | op_negate(x: T): T;
126 |
127 | }
--------------------------------------------------------------------------------
/input/sandbox/geometry-quaternion.heron:
--------------------------------------------------------------------------------
1 | language heron:std:0.1;
2 |
3 | // https://referencesource.microsoft.com/#System.Numerics/System/Numerics/Quaternion.cs
4 | // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm
5 | // https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js
6 |
7 | module heron:geometry.quaternion:0.1
8 | {
9 | function quaternion(v)
10 | = float4(v.x, v.y, v.z, v.w);
11 |
12 | function quaternion(x, y, z, w)
13 | = float4(x, y, z, w);
14 |
15 | function quaternion(x, y, z)
16 | = quaternion(x, y, z, 1);
17 |
18 | function quaternion(v, w)
19 | = quaternion(v.x, v.y, v.z, w);
20 |
21 | var quaternion_identity
22 | = quaternion(0, 0, 0, 1);
23 |
24 | var quaternion_zero
25 | = quaternion(0, 0, 0, 0);
26 |
27 | function length2(q)
28 | = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
29 |
30 | function length(q)
31 | = q.length2.sqrt;
32 |
33 | // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
34 | function quaternion(axis, angle)
35 | = quaternion(
36 | axis.x * sin(angle/2),
37 | axis.y * sin(angle/2),
38 | axis.z * sin(angle/2),
39 | cos(angle/2));
40 |
41 | function quaternion()
42 | = quaternion(0, 0, 0, 0);
43 |
44 | function angle(q)
45 | = 2 * acos(q.w);
46 |
47 | // http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
48 | function quaternion(heading, attitude, bank) {
49 | var c1 = cos(heading / 2);
50 | var c2 = cos(attitude / 2);
51 | var c3 = cos(bank / 2);
52 | var s1 = sin(heading / 2);
53 | var s2 = sin(attitude / 2);
54 | var s3 = sin(bank / 2);
55 | return quaternion(
56 | s1 * s2 * c3 + c1 * c2 * s3
57 | s1 * c2 * c3 + c1 * s2 * s3
58 | c1 * s2 * c3 - s1 * c2 * s3
59 | c1 * c2 * c3 - s1 * s2 * s3);
60 |
61 | // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/
62 | function axis(q)
63 | = vector(
64 | q.x / sqrt(1-q.w*q.w),
65 | q.y / sqrt(1-q.w*q.w),
66 | q.z / sqrt(1-q.w*q.w));
67 |
68 | function normal(q) =
69 | var invLen = 1.0f / q.length in
70 | quaternion(q.X * invLen, q.Y * invLen, q.Z * invLen, q.W * invLen);
71 |
--------------------------------------------------------------------------------
/input/sandbox/geometry-transform.heron:
--------------------------------------------------------------------------------
1 | language heron:std:0.1;
2 |
3 | module heron:geometry.transform:0.1
4 | {
5 | function transform(pos, rot, scl)
6 | = { position=pos; rotation=rot; scale=scl; };
7 |
8 | function translation(pos)
9 | = transform(pos, quaternion_zero, ones);
10 |
11 | function rotation(rot)
12 | = transform(origin, rot, ones);
13 |
14 | function scaling(scl)
15 | = transform(origin, quaternion_zero, scl);
16 |
17 | function matrix(t)
18 | = translation_rotation_scaling_matrix(t.position, t.rotation, t.scale);
19 | }
20 |
--------------------------------------------------------------------------------
/input/sandbox/simple_optimizer.py:
--------------------------------------------------------------------------------
1 | // https://www.codementor.io/zhuojiadai/julia-vs-r-vs-python-simple-optimization-gnqi4njro
2 |
3 | import numpy as np
4 | from scipy.optimize import minimize
5 | from scipy.stats import norm
6 |
7 | # generate the data
8 | odr=[0.10,0.20,0.15,0.22,0.15,0.10,0.08,0.09,0.12]
9 | Q_t = norm.ppf(odr)
10 | maxQ_t = max(Q_t)
11 |
12 | # define a function that will return a return to optimize based on the input data
13 | def neglik_trunc_tn(Q_t):
14 | maxQ_t = max(Q_t)
15 | def neglik_trunc_fn(musigma):
16 | return -sum(norm.logpdf(Q_t, musigma[0], musigma[1])) + len(Q_t)*norm.logcdf(maxQ_t, musigma[0], musigma[1])
17 | return neglik_trunc_fn
18 |
19 | # the likelihood function to optimize
20 | neglik = neglik_trunc_tn(Q_t)
21 |
22 | # optimize!
23 | res = minimize(neglik, [np.mean(Q_t), np.std(Q_t)])
24 | res
--------------------------------------------------------------------------------
/input/sandbox/square-cubes.heron:
--------------------------------------------------------------------------------
1 | // My implementation of some F# code found at:
2 | // https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/active-patterns
3 |
4 | module squarecubes:1.0
5 | {
6 | var err = 1.e-10
7 |
8 | function isInteger(x)
9 | = abs(x - x.round) < err;
10 |
11 | function isSquare(x)
12 | = x.float.sqrt.isInteger;
13 |
14 | function isCube(x)
15 | = x.float.pow(1/3).isInteger;
16 |
17 | function isSquareCube(x)
18 | = x.isSquare || x.isCube;
19 |
20 | var test
21 | = (1 .. 1000000).filter(isSquareCube);
22 | }
--------------------------------------------------------------------------------
/input/sandbox/voronoi-distances.heron:
--------------------------------------------------------------------------------
1 | // http://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
2 | // The MIT License
3 | // Copyright © 2013 Inigo Quilez
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 | // http://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
6 | //
7 |
8 | module voronoi_distances
9 | {
10 | function procedural_white_noise( p )
11 | {
12 | return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
13 | }
14 |
15 | function hash2( p )
16 | {
17 | return procedural_white_noise(p);
18 | }
19 |
20 | function voronoi( x )
21 | {
22 | n = floor(x);
23 | f = fract(x);
24 |
25 | //----------------------------------
26 | // first pass: regular voronoi
27 | //----------------------------------
28 | let mg = vec2;
29 | let mr = vec2;
30 |
31 | let md = 8.0;
32 | for( let j=-1; j<=1; j++ )
33 | for( let i=-1; i<=1; i++ )
34 | {
35 | let g = vec2(float(i),float(j));
36 | let o = hash2( n + g );
37 | let o = 0.5 + 0.5*sin( iGlobalTime + 6.2831*o );
38 | let r = g + o - f;
39 | let d = dot(r,r);
40 |
41 | if( d0.00001 )
62 | md = min( md, dot( 0.5*(mr+r), normalize(r-mr) ) );
63 | }
64 |
65 | return vec3( md, mr );
66 | }
67 |
68 | function mainImage( fragCoord )
69 | {
70 | let p = fragCoord.xy/iResolution.xx;
71 |
72 | let c = voronoi( 8.0*p );
73 |
74 | // isolines
75 | let col = c.x*(0.5 + 0.5*sin(64.0*c.x))*vec3(1.0);
76 | // borders
77 | col = mix( vec3(1.0,0.6,0.0), col, smoothstep( 0.04, 0.07, c.x ) );
78 | // feature points
79 | let dd = length( c.yz );
80 | col = mix( vec3(1.0,0.6,0.1), col, smoothstep( 0.0, 0.12, dd) );
81 | col += vec3(1.0,0.6,0.1)*(1.0-smoothstep( 0.0, 0.04, dd));
82 |
83 | return vec4(col,1.0);
84 | }
85 | }
--------------------------------------------------------------------------------
/input/test.heron:
--------------------------------------------------------------------------------
1 | language heron:std:0.1;
2 |
3 | module heron:tests:0.1
4 | {
5 | import heron:std.array:0.1;
6 | import heron:geometry.mesh:0.1;
7 | import heron:geometry.vector:0.1;
8 |
9 | function main() {
10 | simpleArrayTest();
11 | simpleVectorTest();
12 | }
13 |
14 | function simpleArrayTest() {
15 | var xs = [1, 11, 3];
16 | print('Expect [1, 11, 3]');
17 | print(xs);
18 |
19 | print('Expect 1, 11, 3');
20 | for (var x in xs)
21 | print(x);
22 |
23 | print('Expect 1');
24 | print(xs[0]);
25 |
26 | print('Expect 3');
27 | print(xs.count);
28 |
29 | print('Expect 1');
30 | print(xs.first);
31 |
32 | print('Expect 3');
33 | print(xs.last);
34 |
35 | print('Expect 1');
36 | print(xs.min);
37 |
38 | print('Expect 11');
39 | print(xs.max);
40 |
41 | var ys = xs.mutable;
42 | ys[1] = 5;
43 | print('Expect 5');
44 | print(ys[1]);
45 |
46 | print('Expect 1, 3, 11');
47 | var zs = xs.sort;
48 | for (var z in zs)
49 | print(z);
50 |
51 | print('Expect 3');
52 | print(xs.median);
53 |
54 | print('Expect 15');
55 | print(xs.sum);
56 |
57 | print('Expect 5');
58 | print(xs.average);
59 | }
60 |
61 | function printVector(v) {
62 | var xs = [v.x, v.y, v.z];
63 | print(xs);
64 | }
65 |
66 | function simpleVectorTest() {
67 | var v = vector(4, 3, 0);
68 |
69 | print('Expect 5');
70 | print(v.length);
71 |
72 | print('Expect [4, 3, 0]');
73 | print(v);
74 |
75 | var v1 = vector(1, 0, 0);
76 | var v2 = vector(0, 1, 0);
77 | print('Expect [0,0,1]');
78 | print(v1.cross(v2));
79 |
80 | print('Expect [1,1,0]');
81 | var v3 = v1 + v2;
82 | print(v3);
83 |
84 | print('Expect [1,0,0]');
85 | var v4 = v3 - v2;
86 | print(v4);
87 |
88 | print('Expect [20,15,0]');
89 | var v5 = v * 5.0.vector;
90 | print(v5);
91 |
92 | print('Expect [1,1,0]');
93 | print(v1 + v2);
94 |
95 | print('Expect [0.8, 0.6, 0]');
96 | print(v.normal);
97 | }
98 |
99 | function colorModifier(g, amount: Float)
100 | = g.setVertexColors(g.uvBuffer.map(v => vector(
101 | sin(v.x * pi * 4f) / 2.0 + 0.5,
102 | sin(amount),
103 | cos(v.y * pi * 4f) / 2.0 + 0.5)));
104 |
105 | function pushModifer(g, amount: Float)
106 | = g.translate(g.normalBuffer.map(n => n * amount.vector));
107 |
108 | function scaleModifier(g, amount: Float)
109 | = g.scale(amount.vector);
110 |
111 | function modifiers()
112 | = [
113 | scaleModifier,
114 | pushModifer,
115 | colorModifier
116 | ];
117 |
118 | function primitives()
119 | = [
120 | sphere(),
121 | cylinder(),
122 | torus(),
123 | klein(),
124 | plane(),
125 | mobius(),
126 | tetrahedron,
127 | cube,
128 | octahedron,
129 | dodecahedron,
130 | icosahedron
131 | ];
132 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/.gitattributes:
--------------------------------------------------------------------------------
1 | docs/* linguist-documentation
2 | coverage/* linguist-documentation
3 | *.html linguist-documentation
4 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - "node"
5 | - "6"
6 | - "4"
--------------------------------------------------------------------------------
/node_modules/myna-parser/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible Node.js debug attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch Program",
11 | "program": "${file}",
12 | "cwd": "${workspaceRoot}",
13 | "outFiles": [],
14 | "sourceMaps": true
15 | },
16 | {
17 | "type": "node",
18 | "request": "attach",
19 | "name": "Attach to Process",
20 | "port": 5858,
21 | "outFiles": [],
22 | "timeout": 30000,
23 | "sourceMaps": true
24 | }
25 | ]
26 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.0",
3 |
4 | // The command is tsc.
5 | "command": "tsc",
6 |
7 | // Show the output window only if unrecognized errors occur.
8 | "showOutput": "always",
9 |
10 | // Under windows use tsc.exe. This ensures we don't need a shell.
11 | "windows": {
12 | "command": "tsc",
13 | "args": [
14 | "-w"
15 | ]
16 | },
17 |
18 | // args is the program to compile.
19 | "args": [],
20 |
21 | "isShellCommand": true,
22 |
23 | // use the standard tsc problem matcher to find compile problems
24 | // in the output.
25 | "problemMatcher": "$tsc"
26 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Christopher Diggins
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/Common_Myna.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/Common_Myna.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/Common_Myna_Thumbnail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/Common_Myna_Thumbnail.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-modernist
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/android-chrome-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/android-chrome-192x192.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/apple-touch-icon.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | #da532c
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/favicon-16x16.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/favicon-32x32.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/favicon.ico
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_arithmetic.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Defines a grammar for basic arithmetic
4 | function CreateArithmeticGrammar(myna)
5 | {
6 | // Setup a shorthand for the Myna parsing library object
7 | let m = myna;
8 |
9 | // Construct a grammar
10 | let g = new function()
11 | {
12 | // These are helper rules, they do not create nodes in the parse tree.
13 | this.fraction = m.seq(".", m.digit.zeroOrMore);
14 | this.plusOrMinus = m.char("+-");
15 | this.exponent = m.seq(m.char("eE"), this.plusOrMinus.opt, m.digits);
16 | this.comma = m.text(",").ws;
17 |
18 | // Using a lazy evaluation rule to allow recursive rule definitions
19 | let _this = this;
20 | this.expr = m.delay(function() { return _this.sum; });
21 |
22 | // The following rules create nodes in the abstract syntax tree
23 | this.number = m.seq(m.integer, this.fraction.opt, this.exponent.opt).ast;
24 | this.parenExpr = m.parenthesized(this.expr.ws).ast;
25 | this.leafExpr = m.choice(this.parenExpr, this.number.ws);
26 | this.prefixOp = this.plusOrMinus.ast;
27 | this.prefixExpr = m.seq(this.prefixOp.ws.zeroOrMore, this.leafExpr).ast;
28 | this.divExpr = m.seq(m.char("/").ws, this.prefixExpr).ast;
29 | this.mulExpr = m.seq(m.char("*").ws, this.prefixExpr).ast;
30 | this.product = m.seq(this.prefixExpr.ws, this.mulExpr.or(this.divExpr).zeroOrMore).ast;
31 | this.subExpr = m.seq(m.char("-").ws, this.product).ast;
32 | this.addExpr = m.seq(m.char("+").ws, this.product).ast;
33 | this.sum = m.seq(this.product, this.addExpr.or(this.subExpr).zeroOrMore).ast;
34 | };
35 |
36 | // Register the grammar, providing a name and the default parse rule
37 | return myna.registerGrammar("arithmetic", g, g.expr);
38 | };
39 |
40 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
41 | if (typeof module === "object" && module.exports)
42 | module.exports = CreateArithmeticGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_csv.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a CSV (comma separated values) grammar using the Myna parsing library
4 | // See https://tools.ietf.org/html/rfc4180
5 | // Because this grammar is computed at run-time, it can support tab delimited data by passing in "\t"
6 | // to the constructor as the delimiter.
7 | function CreateCsvGrammar(myna, delimiter)
8 | {
9 | if (delimiter === undefined)
10 | delimiter = ",";
11 |
12 | // Set a shorthand for the Myna parsing library object
13 | let m = myna;
14 |
15 | let g = new function()
16 | {
17 | this.textdata = m.notChar('\n\r"' + delimiter);
18 | this.quoted = m.doubleQuoted(m.notChar('"').or('""').zeroOrMore);
19 | this.field = this.textdata.or(this.quoted).zeroOrMore.ast;
20 | this.record = this.field.delimited(delimiter).ast;
21 | this.file = this.record.delimited(m.newLine).ast;
22 | }
23 |
24 | // Register the grammar, providing a name and the default parse rule
25 | myna.registerGrammar("csv", g, g.file);
26 | }
27 |
28 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
29 | if (typeof module === "object" && module.exports)
30 | module.exports = CreateCsvGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_html_reserved_chars.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Define a grammar for common HTML reserved chars. Those are characters like <, >, and & that should be
4 | // be replaced by an HTML entity to be displayed correctly.
5 | function CreateHtmlReservedCharsGrammar(myna)
6 | {
7 | let m = myna;
8 |
9 | let g = new function()
10 | {
11 | let escapeChars = '&<>"\'';
12 | this.specialChar = m.char(escapeChars).ast;
13 | this.plainText = m.notChar(escapeChars).oneOrMore.ast;
14 | this.text = m.choice(this.specialChar, this.plainText).zeroOrMore;
15 | }
16 |
17 | // Register the grammar, providing a name and the default parse rule
18 | return m.registerGrammar('html_reserved_chars', g, g.text);
19 | }
20 |
21 | // Export the main function for usage by Node.js and CommonJs compatible module loaders
22 | if (typeof module === "object" && module.exports)
23 | module.exports = CreateHtmlReservedCharsGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_json.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a JSON (JavaScript Object Notation) grammar using the Myna parsing library
4 | // See http://www.json.org
5 | function CreateJsonGrammar(myna)
6 | {
7 | // Setup a shorthand for the Myna parsing library object
8 | let m = myna;
9 |
10 | let g = new function()
11 | {
12 | // These are helper rules, they do not create nodes in the parse tree.
13 | this.escapedChar = m.seq('\\', m.advance);
14 | this.quoteChar = m.choice(this.escapedChar, m.notChar('"'));
15 | this.fraction = m.seq(".", m.digit.zeroOrMore);
16 | this.plusOrMinus = m.char("+-");
17 | this.exponent = m.seq(m.char("eE"), this.plusOrMinus.opt, m.digits);
18 | this.comma = m.char(",").ws;
19 |
20 | // The following rules create nodes in the abstract syntax tree
21 | this.string = m.doubleQuoted(this.quoteChar.zeroOrMore).ast;
22 | this.null = m.keyword("null").ast;
23 | this.bool = m.keywords("true", "false").ast;
24 | this.number = m.seq(this.plusOrMinus.opt, m.integer, this.fraction.opt, this.exponent.opt).ast;
25 |
26 | let _this = this;
27 | this.value = m.choice(this.string, this.bool, this.null, this.number,
28 | // Using a lazy evaluation rule to allow recursive rule definitions
29 | m.delay(function() { return m.choice(_this.object, _this.array);
30 | }));
31 |
32 | this.array = m.bracketed(m.delimited(this.value.ws, this.comma)).ast;
33 | this.pair = m.seq(this.string, m.ws, ":", m.ws, this.value.ws).ast;
34 | this.object = m.braced(m.delimited(this.pair.ws, this.comma)).ast;
35 | };
36 |
37 | // Register the grammar, providing a name and the default parse rule
38 | return m.registerGrammar("json", g, g.object);
39 | };
40 |
41 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
42 | if (typeof module === "object" && module.exports)
43 | module.exports = CreateJsonGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_lucene.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This is a grammar for Lucene 4.0 and Solr queries
4 | // http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html
5 | // https://wiki.apache.org/solr/SolrQuerySyntax
6 |
7 | // Additional grammars to be built
8 | // https://cwiki.apache.org/confluence/display/solr/Spatial+Search
9 | // https://wiki.apache.org/solr/SpatialSearch
10 | // http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/util/automaton/RegExp.html?is-external=true
11 |
12 | // Sample grammars
13 | // https://github.com/thoward/lucene-query-parser.js/blob/master/lib/lucene-query.grammar
14 | // https://github.com/lrowe/lucenequery/blob/master/lucenequery/StandardLuceneGrammar.g4
15 | // https://github.com/romanchyla/montysolr/blob/master/contrib/antlrqueryparser/grammars/StandardLuceneGrammar.g
16 |
17 | // TODO: is a&&b a single term? Or two terms?
18 | // TODO: support geo-coordinate parsing
19 | // TODO: support fucntion parsing
20 |
21 | // TODO: support date-time parsing
22 | // http://lucene.apache.org/solr/6_5_1/solr-core/org/apache/solr/util/DateMathParser.html
23 |
24 | function CreateLuceneGrammar(myna)
25 | {
26 | let m = myna;
27 |
28 | let g = new function()
29 | {
30 | let _this = this;
31 | this.delayedQuery = m.delay(function () { return _this.query; });
32 |
33 | this.ws = m.char(' \t\n\r\f').zeroOrMore;
34 | this.escapedChar = m.char('\\').advance;
35 | this.float = m.digit.zeroOrMore.then(m.seq('.', m.digits).opt).ast;
36 |
37 | //
38 | this.boostFactor = this.float.ast;
39 | this.boost = m.text("^").then(this.boostFactor).ast;
40 |
41 | this.fuzzFactor = this.float.ast;
42 | this.fuzz = m.seq('~', this.fuzzFactor.opt).ast;
43 |
44 | this.modifier = m.char("+-").ast;
45 |
46 | this.symbolicOperator = m.choice("||", "&&", "!");
47 | this.operator = m.keywords("OR NOT", "AND NOT", "OR", "AND", "NOT").or(this.symbolicOperator).opt.ast;
48 |
49 | // Represents valid termchars
50 | // NOTE: according to the specification additional characters are not accepted: ':/&|' however, many of these
51 | // interfere with date parsing.
52 | this.termChar = m.seq(this.symbolicOperator.not, m.notChar(' \t\r\n\f{}()"^~[]\\')).or(this.escapedChar);
53 |
54 | this.singleTerm = this.termChar.oneOrMore.ast;
55 | this.fieldName = this.termChar.unless(m.char(':/')).oneOrMore.ast;
56 | this.field = this.fieldName.then(':');
57 |
58 | // TODO: this should be in Myna
59 | this.phrase = m.doubleQuoted(m.notChar('"').zeroOrMore).ast;
60 | this.regex = m.seq('/', m.notChar('/').zeroOrMore, '/').ast;
61 |
62 | // TODO: use the whitespace in the grammar
63 | this.group = m.seq('(', this.delayedQuery, m.assert(')')).ast;
64 |
65 | // TODO: make the ranges a guarded sequence
66 | this.endPoint = m.seq(this.ws, this.singleTerm, this.ws);
67 | this.inclusiveRange = m.seq('[', this.endPoint, m.keyword("TO"), this.endPoint, ']').ast;
68 | this.exclusiveRange = m.seq('{', this.endPoint, m.keyword("TO"), this.endPoint, '}').ast;
69 | this.range = m.choice(this.inclusiveRange, this.exclusiveRange).ast;
70 | this.postOps = m.choice(this.boost.then(this.fuzz.opt), this.fuzz.then(this.boost.opt));
71 | this.term = m.seq(this.field.opt, this.modifier.opt, m.choice(this.group, this.singleTerm, this.phrase, this.regex, this.range), this.postOps.opt).ast;
72 |
73 | // localParams
74 | this.keyChar = m.letter.or(".");
75 | this.escapedChar = m.char('\\').then(m.advance);
76 | this.paramKey = this.keyChar.oneOrMore.ast;
77 | this.singleQuotedValue= m.singleQuotedString(this.escapedChar).ast;
78 | this.doubleQuotedValue= m.doubleQuotedString(this.escapedChar).ast;
79 | this.paramValue = m.choice(this.singleQuotedValue, this.doubleQuotedValue, this.term).ast;
80 | this.param = this.paramKey.then('=').opt.then(this.paramValue).ast;
81 | this.localParams = m.seq('{!', m.delimited(this.param, this.ws), m.assert('}')).ast;
82 |
83 | // Query
84 | this.terms = m.delimited(this.term.then(this.ws), this.operator.then(this.ws)).ast;
85 | this.query = m.seq(this.ws, this.localParams.opt, this.ws, this.terms, this.ws).ast;
86 | };
87 |
88 | // Register the grammar, providing a name and the default parse rule
89 | return m.registerGrammar("lucene", g, g.query);
90 | }
91 |
92 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
93 | if (typeof module === "object" && module.exports)
94 | module.exports = CreateLuceneGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_mustache.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // A Myna grammar for a variant of the Mustache and CTemplate template languages
4 | // This grammar works with any template delimiters defaulting to "{{" and "}}"
5 | // - http://mustache.github.io/mustache.5.html
6 | // - https://github.com/olafvdspek/ctemplate
7 | // According to the mustache documentation:
8 | // - `#` indicates a start section
9 | // - `/` indicates an end section
10 | // - `^` indicates an inverted section
11 | // - `!` indcates a comment
12 | // - `&` or `{` indicate an unescaped variable
13 | // - `>` indicates a *partial* which is effectively a file include with run-time expansion.
14 |
15 | function CreateMustacheGrammar(myna, start, end) {
16 | if (start == undefined)
17 | start = "{{";
18 | if (end == undefined)
19 | end = "}}";
20 |
21 | if (start.length == 0 || end.length == 0)
22 | throw "Missing start and end delimiters";
23 |
24 | let m = myna;
25 |
26 | // Create the grammar object
27 | let g = new function()
28 | {
29 | // Define a rule so that we can refer to content recursively
30 | let _this = this;
31 | this.recursiveContent = m.delay(function() { return _this.content; });
32 |
33 | // Main grammar rules.
34 | // Only those with 'ast' will generate nodes in the parse tree
35 | this.key = m.advanceWhileNot(end).ast;
36 | this.restOfLine = m.char(' \t').zeroOrMore.then(m.opt('\n'));
37 | this.startSection = m.seq(start, "#", this.key, end, this.restOfLine);
38 | this.endSection = m.seq(start, "/", this.key, end);
39 | this.startInvertedSection = m.seq(start, "^", this.key, end, this.restOfLine);
40 | this.escapedVar = m.seq(start, m.notAtChar("#/^!{&<"), this.key, end).ast;
41 | this.unescapedVar = m.seq(start, m.choice(m.seq("{", this.key, "}"), m.seq("&", this.key)), end).ast;
42 | this.var = m.choice(this.escapedVar, this.unescapedVar);
43 | this.partial = m.seq(start, ">", m.ws.opt, this.key, end).ast;
44 | this.comment = m.seq(start, "!", this.key, end).ast;
45 | this.sectionContent = this.recursiveContent.ast;
46 | this.section = m.guardedSeq(this.startSection, this.sectionContent, this.endSection).ast;
47 | this.invertedSection = m.guardedSeq(this.startInvertedSection, this.sectionContent, this.endSection).ast;
48 | this.plainText = m.advanceOneOrMoreWhileNot(start).ast;
49 | this.content = m.choice(this.invertedSection, this.section, this.comment, this.partial, this.var, this.plainText).zeroOrMore;
50 | this.document = this.content.ast;
51 | }
52 |
53 | // Register the grammar, providing a name and the default parse rule
54 | return m.registerGrammar("mustache", g, g.document);
55 | }
56 |
57 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
58 | if (typeof module === "object" && module.exports)
59 | module.exports = CreateMustacheGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/grammars/grammar_template.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // A Myna grammar for a variant of the Mustache and CTemplate template languages
4 | // This grammar works with any template delimiters defaulting to "{{" and "}}"
5 | // - http://mustache.github.io/mustache.5.html
6 | // - https://github.com/olafvdspek/ctemplate
7 | // According to the mustache documentation:
8 | // - `#` indicates a start section
9 | // - `/` indicates an end section
10 | // - `^` indicates an inverted section
11 | // - `!` indcates a comment
12 | // - `&` or `{` indicate an unescaped variable
13 | // - `>` indicates a *partial* which is effectively a file include with run-time expansion.
14 |
15 | function CreateTemplateGrammar(myna, start, end) {
16 | if (start == undefined)
17 | start = "{{";
18 | if (end == undefined)
19 | end = "}}";
20 |
21 | if (start.length == 0 || end.length == 0)
22 | throw "Missing start and end delimiters";
23 |
24 | let m = myna;
25 |
26 | // Create the grammar object
27 | let g = new function()
28 | {
29 | // Define a rule so that we can refer to content recursively
30 | let _this = this;
31 | this.recursiveContent = m.delay(function() { return _this.content; });
32 |
33 | // Main grammar rules.
34 | // Only those with 'ast' will generate nodes in the parse tree
35 | this.key = m.advanceWhileNot(end).ast;
36 | this.restOfLine = m.char(' \t').zeroOrMore.then(m.opt('\n'));
37 | this.startSection = m.seq(start, "#", this.key, end, this.restOfLine);
38 | this.endSection = m.seq(start, "/", this.key, end);
39 | this.startInvertedSection = m.seq(start, "^", this.key, end, this.restOfLine);
40 | this.escapedVar = m.seq(start, m.notAtChar("#/^!{&<"), this.key, end).ast;
41 | this.unescapedVar = m.seq(start, m.choice(m.seq("{", this.key, "}"), m.seq("&", this.key)), end).ast;
42 | this.var = m.choice(this.escapedVar, this.unescapedVar);
43 | this.partial = m.seq(start, ">", m.ws.opt, this.key, end).ast;
44 | this.comment = m.seq(start, "!", this.key, end).ast;
45 | this.sectionContent = this.recursiveContent.ast;
46 | this.section = m.guardedSeq(this.startSection, this.sectionContent, this.endSection).ast;
47 | this.invertedSection = m.guardedSeq(this.startInvertedSection, this.sectionContent, this.endSection).ast;
48 | this.plainText = m.advanceOneOrMoreWhileNot(start).ast;
49 | this.content = m.choice(this.invertedSection, this.section, this.comment, this.partial, this.var, this.plainText).zeroOrMore;
50 | this.document = this.content.ast;
51 | }
52 |
53 | // Register the grammar, providing a name and the default parse rule
54 | return m.registerGrammar("template", g, g.document);
55 | }
56 |
57 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
58 | if (typeof module === "object" && module.exports)
59 | module.exports = CreateTemplateGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/js/ie10-viewport-bug-workaround.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * IE10 viewport hack for Surface/desktop Windows 8 bug
3 | * Copyright 2014-2015 Twitter, Inc.
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5 | */
6 |
7 | // See the Getting Started docs for more information:
8 | // http://getbootstrap.com/getting-started/#support-ie10-width
9 |
10 | (function () {
11 | 'use strict';
12 |
13 | if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
14 | var msViewportStyle = document.createElement('style')
15 | msViewportStyle.appendChild(
16 | document.createTextNode(
17 | '@-ms-viewport{width:auto!important}'
18 | )
19 | )
20 | document.querySelector('head').appendChild(msViewportStyle)
21 | }
22 |
23 | })();
24 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "icons": [
4 | {
5 | "src": "/android-chrome-192x192.png",
6 | "sizes": "192x192",
7 | "type": "image/png"
8 | }
9 | ],
10 | "theme_color": "#ffffff",
11 | "background_color": "#ffffff",
12 | "display": "standalone"
13 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/mstile-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cdiggins/heron-language/f7c4da9f50b3c5b3cf0e78944cda463d60eb4ae5/node_modules/myna-parser/docs/mstile-150x150.png
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/safari-pinned-tab.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 | Created by potrace 1.11, written by Peter Selinger 2001-2013
9 |
10 |
12 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/heron_tools.js:
--------------------------------------------------------------------------------
1 | // 1) Input Myna
2 |
3 | 'use strict';
4 |
5 | let myna = require('../myna');
6 | let g = require('../grammars/grammar_heron')(myna);
7 | let fs = require('fs');
8 |
9 | function processType(ast) {
10 | if (ast.name != "typeExpr") throw new Error("expected a type expression");
11 | return ast.allText;
12 | }
13 |
14 | function processPrimitive(ast, prims) {
15 | var name = ast.children[0].allText;
16 | var type = processType(ast.children[1]);
17 | prims[name] = type;
18 | }
19 |
20 | var heronTools = new function() {
21 | this.parsePrimitives = function(fileName) {
22 | var text = fs.readFileSync(fileName, 'utf-8');
23 | var ast = myna.parse(g.primitiveFile, text);
24 | var prims = {};
25 | for (var p of ast.children)
26 | processPrimitive(p, prims);
27 | return prims;
28 | }
29 | }
30 |
31 | // Export the function for use use with Node.js
32 | if (typeof module === "object" && module.exports)
33 | module.exports = heronTools;
34 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/mocha_runner.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Load Myna and all the grammars
4 | var m = require('../tools/myna_all');
5 | var inputs = require('../tests/rule_test_inputs')(m);
6 | var ruleTester = require('../tests/rule_tester');
7 | var assert = require('assert');
8 |
9 | // Set up the unit tests with Mocha
10 | describe("Parser tests", function() {
11 | function tester(name, testFxn) {
12 | //console.log("Running test: " + name);
13 | it(name, function() { testFxn(assert); });
14 | }
15 | ruleTester(m, inputs, tester);
16 | });
17 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/myna_augment_ast.js:
--------------------------------------------------------------------------------
1 | // Adds additional information to an AST once it has been constructed.
2 | // This information is expensive to add at parse time.
3 | // It adds a parent pointer, a unique index, a row number, and a column number.
4 | // All of the nodes are then placed in an array.
5 | function augmentAstTree(ast) {
6 | return augmentAstNode(ast, null, 0, 0, 0, []);
7 | }
8 |
9 | function augmentAstNode(node, parent, index, rowNum, colNum, nodes) {
10 | var lineCount1 = 0;
11 | var lineCount2 = 0;
12 | for (;index < node.start; ++index) {
13 | if (node.input.charCodeAt(index) == 10) {
14 | lineCount1++;
15 | colNum = 0;
16 | }
17 | else if (node.input.charCodeAt(index) == 13) {
18 | lineCount2++;
19 | colNum = 0;
20 | }
21 | else {
22 | colNum++;
23 | }
24 | }
25 | if (lineCount1 >= lineCount2) {
26 | rowNum += lineCount1;
27 | }
28 | else {
29 | rowNum += lineCount2;
30 | }
31 | node.parent = parent;
32 | node.rowNum = rowNum;
33 | node.colNum = colNum;
34 | node.index = nodes.length;
35 | nodes.push(node);
36 | for (var child of node.children)
37 | augmentAstNode(child, node, index, rowNum, colNum, nodes);
38 | return nodes;
39 | }
40 |
41 | // Export the function for use use with Node.js
42 | if (typeof module === "object" && module.exports)
43 | module.exports = augmentAstTree;
44 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/output_grammars.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This project outputs the grammars and the schemas of the AST trees
4 |
5 | var myna = require('../tools/myna_all');
6 |
7 | for (let g of myna.grammarNames())
8 | {
9 | console.log("==============================");
10 | console.log("Grammar: " + g);
11 | console.log("==============================");
12 | console.log(myna.grammarToString(g));
13 |
14 | console.log("==============================");
15 | console.log("AST Schema: " + g);
16 | console.log("==============================");
17 | console.log(myna.astSchemaToString(g));
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/performance.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Performance Test
4 |
5 |
6 |
7 |
17 |
18 |
19 | A Performance Test for Myna in the Browser
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QUnit Tests for the Myna Parsing Library
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
55 |
56 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/readme.md:
--------------------------------------------------------------------------------
1 | # Myna Tests
2 |
3 | There are two types of tests with Myna
4 |
5 | 1. **Parser tests** - Effectively these are unit tests run using QUnit or Mochas which test the core parsers, the various combinarors, and the sample grammars.
6 | 2. **Tool tests** - These are integration tests, which test simples tools built using the sample grammars.
7 |
8 | The tool tests demonstrate how to use Myna in an actual tool.
9 |
10 | ## Using Myna in a Browser
11 |
12 | Look at `tests\test_browser_unpkg.html` for an example of using Myna in the browser. Notice that instead of using a module loader we need to define a global variable called exports before including the Myna JavaScript file which will add a new variable called `Myna` to the global namespace.
13 |
14 | ## Parser Tests
15 |
16 | To run the Parse tests open the `QUnit.html` file in your browser. You do not have to be using a server, you can just point your browser to the local file.
17 |
18 | ## Tool Tests
19 |
20 | To run the local tests you will need to use node from the root folder of the Myna distribution as follows:
21 |
22 | ```
23 | node tests\test_tools.js
24 | ```
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/rule_tester.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This class tests parser rules given an array of inputs.
4 | // Each input is an array [rule, [passing inputs], [failing inputs]]
5 | // The TestRunner is a function like QUnit.test
6 | function RuleTester(myna, inputs, testRunner)
7 | {
8 | if (!myna)
9 | throw new Error("Missing Myna module");
10 | if (!inputs)
11 | throw new Error("Missing inputs");
12 | if (!testRunner)
13 | throw new Error("Missing test runner")
14 |
15 | // Tests parsing an individual rule against the input input text, and returns an object
16 | // representing the result of running the test
17 | function testParse(rule, assert, text, shouldPass) {
18 | if (shouldPass == undefined) shouldPass = true;
19 | let result = myna.failed;
20 | let err = undefined;
21 | try {
22 | let node = myna.parse(rule, text);
23 | if (node)
24 | result = node.end;
25 | }
26 | catch (e) {
27 | if (e.type !== 'ParserError') {
28 | throw e;
29 | }
30 | err = e;
31 | }
32 |
33 | let testResult = {
34 | name : rule.toString() + ' with input "' + text + '"',
35 | description : result + "/" + text.length,
36 | negative : !shouldPass,
37 | success : (result == text.length) ^ !shouldPass,
38 | error : err,
39 | ruleDescr : rule.type + ": " + rule.toString(),
40 | rule : rule
41 | };
42 |
43 | if (!testResult.success)
44 | console.log(testResult);
45 |
46 | assert.ok(testResult.success, testResult.name + (shouldPass ? "" : " should fail"));
47 | }
48 |
49 | // Tests parsing an individual rule against using an array of inputs string that should pass
50 | // and an array of inputs strings that should fail.
51 | function testRule(rule, assert, passStrings, failStrings) {
52 | for (let input of passStrings)
53 | testParse(rule, assert, input, true);
54 |
55 | for (let input of failStrings)
56 | testParse(rule, assert, input, false);
57 | }
58 |
59 | //===============================================
60 | // Body of the function
61 |
62 | for (let i=0; i < inputs.length; ++i)
63 | {
64 | let t = inputs[i];
65 | if (!t || t.length < 2 || !t[0])
66 | throw new Error("Each test must have a rule, an array of passing strings, and an array of failing strings");
67 |
68 | testRunner(t[0].toString(), function(assert) {
69 | testRule(t[0], assert, t[1], t[2]);
70 | });
71 | }
72 | }
73 |
74 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
75 | if (typeof module === "object" && module.exports)
76 | module.exports = RuleTester;
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_all_tools.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | console.log("");
4 | console.log("Testing HTML character escaping");
5 | let test_escape_html_chars = require('../tests/test_escape_html_chars');
6 |
7 | console.log("");
8 | console.log("Testing Mustaches style template expander");
9 | let test_mustache_expander = require('../tests/test_mustache_expander');
10 |
11 | console.log("");
12 | console.log("Testing Lucene parser");
13 | let test_lucene = require('../tests/test_lucene');
14 |
15 | process.exit();
16 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_arithmetic.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let myna = require('../myna');
4 | let grammar = require('../grammars/grammar_arithmetic')(myna);
5 | let evaluator = require('../tools/myna_arithmetic_evaluator.js')(myna);
6 |
7 | let arithmeticTestInputs = [
8 | ["(42)", 42],
9 | ["6 * 7", 42],
10 | ["42", 42],
11 | ["0", 0],
12 | ["-42", -42],
13 | ["- 5", -5],
14 | ["-\t- 5", 5],
15 | ["-(42)", -42],
16 | ["+42", +42],
17 | ["+(42)", +42],
18 | ["2 * 3 * 7", 42],
19 | ["5 * 8 + 2", 42],
20 | ["2 + 5 * 8", 42],
21 | ["(5 * 8) + 2", 42],
22 | ["2 + (5 * 8)", 42],
23 | ["((5 * 8) + 2)", 42],
24 | ["(2 + (5 * 8))", 42],
25 | ["6 * (9 - 2)", 42],
26 | ["(9 - 2) * 6", 42],
27 | ["5 * 9 - 3", 42],
28 | ["-5 * 9", -45],
29 | ["3 - -5", 8],
30 | ["-3 - -5 * 9", 42]];
31 |
32 | for (let test of arithmeticTestInputs) {
33 | let input = test[0];
34 | let expected = test[1];
35 | let result = evaluator(input);
36 | if (result !== expected)
37 | console.log("test failed: " + test + ", instead was: " + result);
38 | else
39 | console.log("test passed: " + test)
40 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_browser_unpkg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_escape_html_chars.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let fs = require("fs");
4 | let myna = require("../myna");
5 | let escapeHtmlChars = require('../tools/myna_escape_html_chars');
6 |
7 | function testEscape(text, expected) {
8 | console.log("Input: " + text);
9 | console.log("Expected: " + expected);
10 | let result = escapeHtmlChars(text);
11 | console.log("Output: " + result);
12 | console.log(result == expected ? "Success" : "Failure");
13 | }
14 |
15 | testEscape("123", "123");
16 | testEscape("'", "'");
17 | testEscape("< >", "< >");
18 | testEscape(" && ", " && ");
19 | testEscape('"', """);
20 | testEscape("", "");
21 |
22 | function timeIt(f) {
23 | let t = process.hrtime();
24 | f();
25 | t = process.hrtime(t);
26 | // https://blog.tompawlak.org/measure-execution-time-nodejs-javascript
27 | let msec = Math.floor(t[0] * 1000 + t[1] / (1000 * 1000));
28 | console.log('benchmark took %d msec', msec);
29 | }
30 |
31 | function naiveEscapeChars(s) {
32 | // http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript
33 | return s.replace(/&/g, "&").replace(/>/g, ">").replace(/=0) {
23 | results.push(fileName);
24 | };
25 | };
26 | return results;
27 | };
28 |
29 | // TODO: uncomment only when you want to recreate a visitor file.
30 | /*
31 | var visitorCode = genVisitor(myna, "glsl");
32 | fs.writeFileSync("./tests/output/glsl_visitor.js", visitorCode);
33 | */
34 |
35 | var prims = heronTools.parsePrimitives('./tests/input/primitives.heron');
36 | console.log(prims);
37 |
38 | function testParseFile(file) {
39 | try
40 | {
41 | console.log("Test parsing: " + file);
42 | var contents = fs.readFileSync(file, 'utf-8');
43 | var ast = myna.parse(g.program, contents);
44 | var state = glslPrinter(ast, prims, false);
45 | for (var u in state.undefined) {
46 | console.log("Undefined variable : " + u);
47 | }
48 | var text = state.text.join("");
49 | var outputFile = file.replace("input", "output");
50 | fs.writeFileSync(outputFile, text);
51 | var state = glslPrinter(ast, prims, true);
52 | text = state.text.join("");
53 | outputFile = outputFile.replace(".glsl", ".heron");
54 | fs.writeFileSync(outputFile, text);
55 | if (ast.end != contents.length) {
56 | console.log("Only parsed " + ast.end
57 | + " characters out of " + contents.length);
58 | }
59 | console.log("Succeeded parse");
60 | }
61 | catch (e)
62 | {
63 | console.log("Failure: ");
64 | console.log(e);
65 | }
66 | }
67 |
68 | function parseFiles() {
69 | var files = fromDir('./tests/input/glsl','.glsl', []);
70 | for (var i=0; i < files.length; ++i) {
71 | var f = files[i];
72 | testParseFile(f);
73 | }
74 | }
75 |
76 | parseFiles();
77 | process.exit();
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_lucene.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let myna = require('../myna');
4 | require('../grammars/grammar_lucene')(myna);
5 |
6 | function testQuery(q)
7 | {
8 | console.log("Input query = " + q);
9 | let ast = myna.parsers.lucene(q);
10 | console.log(ast.toString());
11 | }
12 |
13 | let qs = [
14 | 'title:"The Right Way" AND text:go',
15 | 'title:"Do it right" AND right',
16 | 'timestamp:[* TO NOW]',
17 | 'createdate:[1976-03-06T23:59:59.999Z TO *]',
18 | '+popularity:[10 TO *] +section:0',
19 | '{!func}popularity',
20 | '{!q.op=AND df=title}solr rocks',
21 | "{!type=dismax qf='myfield yourfield'}solr rocks",
22 | '{!type=dismax qf="myfield yourfield"}solr rocks',
23 | '{!dismax qf=myfield}solr rocks',
24 | '{!type=dismax qf=myfield}solr rocks',
25 | "{!type=dismax qf=myfield v='solr rocks'}",
26 | '{!lucene q.op=AND df=text}myfield:foo +bar -baz',
27 | '(jakarta OR apache) AND website',
28 | '"jakarta apache" -"Apache Lucene"',
29 | 'NOT "jakarta apache"',
30 | '"jakarta apache" NOT "Apache Lucene"',
31 | '+jakarta lucene',
32 | '"jakarta apache" AND "Apache Lucene"',
33 | '"jakarta apache" OR jakarta',
34 | '"jakarta apache" jakarta',
35 | '"jakarta apache"^4 "Apache Lucene"',
36 | 'jakarta^4 apache',
37 | 'jakarta apache',
38 | 'title:{Aida TO Carmen}',
39 | '"jakarta apache"~10',
40 | 'roam~0.8',
41 | 'roam~',
42 | 'foo:{bar TO baz}',
43 | 'foo:[bar TO baz]',
44 | 'fizz AND (buzz OR baz)',
45 | 'fizz (buzz baz)',
46 | 'fizz || buzz',
47 | 'fizz && buzz',
48 | 'foo:+"fizz buzz"',
49 | 'foo:-"fizz buzz"',
50 | 'foo:+bar',
51 | 'foo:-bar',
52 | 'foo:"fizz buzz"',
53 | 'sub.foo:bar',
54 | 'foo:2015-01-01',
55 | 'foo:bar',
56 | '+"fizz buzz"',
57 | '-"fizz buzz"',
58 | 'published_at:>now+5d',
59 | 'created_at:>now-5d',
60 | ' Test:Foo',
61 | ' \r\n'
62 | ]
63 |
64 | for (let q of qs) {
65 | testQuery(q);
66 | }
67 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_markdown_to_html.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var fs = require('fs');
4 | var mdToHtml = require('../tools/myna_markdown_to_html');
5 |
6 | // This is a recently failing test.
7 | var testUrlList =
8 | `## Themes
9 |
10 | * https://github.com/mixu/markdown-styles
11 | * https://themes.gohugo.io
12 | * https://jekyllthemes.org
13 | * https://en-ca.wordpress.org/themes
14 | * https://colorlib.com/wp/free-wordpress-themes
15 | * https://hexo.io/themes`;
16 |
17 | var html = mdToHtml(testUrlList);
18 | console.log(html);
19 |
20 | // This creates an HTML file from the readme
21 | var md = fs.readFileSync('readme.md', 'utf-8');
22 | var content = mdToHtml(md);
23 | fs.writeFileSync('tests/output/readme.html', content, { encoding:'utf-8' });
24 |
25 | process.exit();
26 |
27 |
28 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_mustache_expander.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let myna = require('../myna');
4 | let expand = require('../tools/myna_mustache_expander');
5 |
6 | function testExpand(template, data, expected) {
7 | console.log("Expanding template: ", template);
8 | console.log(" Data: ", data);
9 | let result = expand(template, data);
10 | console.log(" Result: ", result);
11 | console.log(" Expected: ", expected);
12 | console.log(result == expected ? "Passed" : "Failed");
13 | }
14 |
15 | console.log("==========");
16 | console.log("Basic expansion tests");
17 | console.log("==========");
18 | testExpand("{{a}}", { a:42 }, "42");
19 | testExpand("{{a}}", null, "");
20 | testExpand("a b c", null, "a b c");
21 | testExpand("a {b} c", { b: 42 }, "a {b} c");
22 | testExpand("a {{b}} c", { b: 42 }, "a 42 c");
23 | testExpand("{{a}}", { }, "");
24 | testExpand("{{a}}", { a:"<>"}, "<>");
25 | testExpand("{{{a}}}", { a:"<>"}, "<>");
26 | testExpand("{{&a}}", { a:"<>"}, "<>");
27 | testExpand("{{a}} {{b}} {{c}} {{d}}", { a:10, b:"hello", d:true}, "10 hello true");
28 | testExpand("{{a}}{{b}}{{c}},{{#test}}{{a}}{{b}}{{c}}{{/test}}", { a:"A", b:"X", test:{ b:"B", c:"C" }}, "AX,ABC");
29 |
30 | console.log("Example 1");
31 | {
32 | let t = [
33 | "Hello {{name}}",
34 | "You have just won {{value}} dollars!",
35 | "{{#in_ca}}",
36 | "Well, {{taxed_value}} dollars, after taxes.",
37 | "{{/in_ca}}",
38 | ].join('\n');
39 |
40 | let h = {
41 | "name": "Chris",
42 | "value": 10000,
43 | "taxed_value": 10000 - (10000 * 0.4),
44 | "in_ca": true
45 | };
46 |
47 | console.log(expand(t, h));
48 | }
49 |
50 | console.log("Example 3");
51 | {
52 | let t = [
53 | "* {{name}}",
54 | "* {{age}}",
55 | "* {{company}}",
56 | "* {{{company}}}",
57 | ].join('\n');
58 |
59 | let h = {
60 | "name": "Chris",
61 | "company": "GitHub "
62 | };
63 |
64 | console.log(expand(t, h));
65 | }
66 |
67 | console.log("Example 4");
68 | {
69 | let t = [
70 | "Shown.",
71 | "{{#person}}",
72 | "Never shown!",
73 | "{{/person}}",
74 | ].join('\n');
75 |
76 | let h = {
77 | "person" : false
78 | };
79 |
80 | console.log(expand(t, h));
81 | }
82 |
83 | console.log("Example 5");
84 | {
85 | let t = [
86 | "{{#repo}}",
87 | "{{name}} ",
88 | "{{/repo}}",
89 | ].join('\n');
90 |
91 | let h = {
92 | "repo": [
93 | { "name": "resque" },
94 | { "name": "hub" },
95 | { "name": "rip" }
96 | ]
97 | };
98 |
99 | console.log(expand(t, h));
100 | }
101 |
102 | console.log("Example 6");
103 | {
104 | let t = [
105 | "{{#person?}}",
106 | " Hi {{name}}!",
107 | "{{/person?}}",
108 | ].join('\n');
109 |
110 | let h =
111 | {
112 | "person?": { "name": "Jon" }
113 | };
114 |
115 | console.log(expand(t, h));
116 | }
117 |
118 | console.log("Example 7");
119 | {
120 | let t = [
121 | "{{#repo}}",
122 | "{{name}} ",
123 | "{{/repo}}",
124 | "{{^repo}}",
125 | "No repos :(",
126 | "{{/repo}}",
127 | ].join('\n');
128 |
129 | let h = {
130 | "repo": []
131 | }
132 |
133 | console.log(expand(t, h));
134 | }
135 |
136 | console.log("Example 8");
137 | {
138 | console.log(expand("Today{{! ignore me }}. ", {}));
139 | }
140 |
141 | console.log("Example 9");
142 | {
143 | console.log(expand("{{text}}", { today : "Tuesday", text : "Today is {{today}}" }));
144 | }
145 |
146 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_node.js:
--------------------------------------------------------------------------------
1 | let m = require('../myna');
2 |
3 | for (let r of m.allGrammarRules())
4 | console.log(r.toString());
5 |
6 | process.exit();
7 |
8 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_node_example-1.js:
--------------------------------------------------------------------------------
1 | // Load the Myna module and all grammars
2 | var m = require('myna-parser');
3 |
4 | // Load the JSON grammar
5 | require('myna-parser/grammars/grammar_json')(m);
6 |
7 | // Get the JSON parser
8 | var parser = m.parsers.json;
9 |
10 | // Define some input
11 | var input = '{ "integer":42, "greeting":"hello", "truth":false, "array":[1,2,3] }';
12 |
13 | // Output the generated AST
14 | console.log(parser(input).toString());
15 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_node_example-2.js:
--------------------------------------------------------------------------------
1 | // Reference the Myna module
2 | var m = require('myna-parser');
3 |
4 | // Construct a grammar object
5 | var g = new function()
6 | {
7 | this.textdata = m.notChar('\n\r"' + delimiter);
8 | this.quoted = m.doubleQuoted(m.notChar('"').or('""').zeroOrMore);
9 | this.field = this.textdata.or(this.quoted).zeroOrMore.ast;
10 | this.record = this.field.delimited(delimiter).ast;
11 | this.file = this.record.delimited(m.newLine).ast;
12 | }
13 |
14 | // Let consumers of the Myna module access
15 | m.registerGrammar("csv", g, g.file);
16 |
17 | // Get the parser
18 | var parser = m.parsers.csv;
19 | var input = 'a,1,"hello"\nb,2,"goodbye"';
20 | console.log(parser(input).toString());
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_parser_failure.js:
--------------------------------------------------------------------------------
1 | var myna = require('../myna');
2 | var g = require('../grammars/grammar_json')(myna);
3 | var parse = myna.parsers.json;
4 |
5 | try
6 | {
7 | var ast = parse(
8 | `{
9 | "number" : 42,
10 | "array" : [1, 2, 3 }
11 | }`);
12 |
13 | console.log(ast);
14 | }
15 | catch (e)
16 | {
17 | console.log("Error occured:");
18 | console.log(e.toString());
19 | }
20 |
21 | process.exit();
22 |
23 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_pithy.js:
--------------------------------------------------------------------------------
1 | var myna = require('../myna');
2 | var g = require('../grammars/grammar_pithy')(myna);
3 |
4 | console.log("Pithy Grammar");
5 | console.log(myna.grammarToString("pithy"));
6 |
7 | console.log("Pithy AST Schema");
8 | console.log(myna.astSchemaToString("pithy"));
9 |
10 | process.exit();
11 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_tools.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | console.log("");
4 | console.log("Testing HTML character escaping");
5 | let test_escape_html_chars = require('../tests/test_escape_html_chars');
6 |
7 | console.log("");
8 | console.log("Testing Mustaches style template expander");
9 | let test_mustache_expander = require('../tests/test_mustache_expander');
10 |
11 | console.log("");
12 | console.log("Testing arithmetic evaluator");
13 | let test_arithmetic = require('../tests/test_arithmetic');
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_typescript_import.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | // This file demonstrates how to use Myna from a TypeScript project
3 | var myna_1 = require("../myna");
4 | for (var _i = 0, _a = myna_1.Myna.allGrammarRules(); _i < _a.length; _i++) {
5 | var r = _a[_i];
6 | console.log(r.toString());
7 | }
8 | process.exit();
9 | //# sourceMappingURL=test_typescript_import.js.map
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_typescript_import.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"test_typescript_import.js","sourceRoot":"","sources":["test_typescript_import.ts"],"names":[],"mappings":";AAAA,oEAAoE;AACpE,qBAA0B,SAAS,CAAC,CAAA;AACpC,GAAG,CAAC,CAAU,UAAmB,EAAnB,KAAA,WAAC,CAAC,eAAe,EAAE,EAAnB,cAAmB,EAAnB,IAAmB,CAAC;IAA7B,IAAI,CAAC,SAAA;IACN,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;CAAA;AAG9B,OAAO,CAAC,IAAI,EAAE,CAAC"}
--------------------------------------------------------------------------------
/node_modules/myna-parser/docs/tests/test_typescript_import.ts:
--------------------------------------------------------------------------------
1 | // This file demonstrates how to use Myna from a TypeScript project
2 | import { Myna as m } from "../myna";
3 | for (let r of m.allGrammarRules())
4 | console.log(r.toString());
5 |
6 | declare var process : any;
7 | process.exit();
8 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_arithmetic.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Defines a grammar for basic arithmetic
4 | function CreateArithmeticGrammar(myna)
5 | {
6 | // Setup a shorthand for the Myna parsing library object
7 | let m = myna;
8 |
9 | // Construct a grammar
10 | let g = new function()
11 | {
12 | // These are helper rules, they do not create nodes in the parse tree.
13 | this.fraction = m.seq(".", m.digit.zeroOrMore);
14 | this.plusOrMinus = m.char("+-");
15 | this.exponent = m.seq(m.char("eE"), this.plusOrMinus.opt, m.digits);
16 | this.comma = m.text(",").ws;
17 |
18 | // Using a lazy evaluation rule to allow recursive rule definitions
19 | let _this = this;
20 | this.expr = m.delay(function() { return _this.sum; });
21 |
22 | // The following rules create nodes in the abstract syntax tree
23 | this.number = m.seq(m.integer, this.fraction.opt, this.exponent.opt).ast;
24 | this.parenExpr = m.parenthesized(this.expr.ws).ast;
25 | this.leafExpr = m.choice(this.parenExpr, this.number.ws);
26 | this.prefixOp = this.plusOrMinus.ast;
27 | this.prefixExpr = m.seq(this.prefixOp.ws.zeroOrMore, this.leafExpr).ast;
28 | this.divExpr = m.seq(m.char("/").ws, this.prefixExpr).ast;
29 | this.mulExpr = m.seq(m.char("*").ws, this.prefixExpr).ast;
30 | this.product = m.seq(this.prefixExpr.ws, this.mulExpr.or(this.divExpr).zeroOrMore).ast;
31 | this.subExpr = m.seq(m.char("-").ws, this.product).ast;
32 | this.addExpr = m.seq(m.char("+").ws, this.product).ast;
33 | this.sum = m.seq(this.product, this.addExpr.or(this.subExpr).zeroOrMore).ast;
34 | };
35 |
36 | // Register the grammar, providing a name and the default parse rule
37 | return myna.registerGrammar("arithmetic", g, g.expr);
38 | };
39 |
40 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
41 | if (typeof module === "object" && module.exports)
42 | module.exports = CreateArithmeticGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_csv.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a CSV (comma separated values) grammar using the Myna parsing library
4 | // See https://tools.ietf.org/html/rfc4180
5 | // Because this grammar is computed at run-time, it can support tab delimited data by passing in "\t"
6 | // to the constructor as the delimiter.
7 | function CreateCsvGrammar(myna, delimiter)
8 | {
9 | if (delimiter === undefined)
10 | delimiter = ",";
11 |
12 | // Set a shorthand for the Myna parsing library object
13 | let m = myna;
14 |
15 | let g = new function()
16 | {
17 | this.textdata = m.notChar('\n\r"' + delimiter);
18 | this.quoted = m.doubleQuoted(m.notChar('"').or('""').zeroOrMore);
19 | this.field = this.textdata.or(this.quoted).zeroOrMore.ast;
20 | this.record = this.field.delimited(delimiter).ast;
21 | this.file = this.record.delimited(m.newLine).ast;
22 | }
23 |
24 | // Register the grammar, providing a name and the default parse rule
25 | myna.registerGrammar("csv", g, g.file);
26 | }
27 |
28 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
29 | if (typeof module === "object" && module.exports)
30 | module.exports = CreateCsvGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_html_reserved_chars.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Define a grammar for common HTML reserved chars. Those are characters like <, >, and & that should be
4 | // be replaced by an HTML entity to be displayed correctly.
5 | function CreateHtmlReservedCharsGrammar(myna)
6 | {
7 | let m = myna;
8 |
9 | let g = new function()
10 | {
11 | let escapeChars = '&<>"\'';
12 | this.specialChar = m.char(escapeChars).ast;
13 | this.plainText = m.notChar(escapeChars).oneOrMore.ast;
14 | this.text = m.choice(this.specialChar, this.plainText).zeroOrMore;
15 | }
16 |
17 | // Register the grammar, providing a name and the default parse rule
18 | return m.registerGrammar('html_reserved_chars', g, g.text);
19 | }
20 |
21 | // Export the main function for usage by Node.js and CommonJs compatible module loaders
22 | if (typeof module === "object" && module.exports)
23 | module.exports = CreateHtmlReservedCharsGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_json.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a JSON (JavaScript Object Notation) grammar using the Myna parsing library
4 | // See http://www.json.org
5 | function CreateJsonGrammar(myna)
6 | {
7 | // Setup a shorthand for the Myna parsing library object
8 | let m = myna;
9 |
10 | let g = new function()
11 | {
12 | // These are helper rules, they do not create nodes in the parse tree.
13 | this.escapedChar = m.seq('\\', m.advance);
14 | this.quoteChar = m.choice(this.escapedChar, m.notChar('"'));
15 | this.fraction = m.seq(".", m.digit.zeroOrMore);
16 | this.plusOrMinus = m.char("+-");
17 | this.exponent = m.seq(m.char("eE"), this.plusOrMinus.opt, m.digits);
18 | this.comma = m.char(",").ws;
19 |
20 | // The following rules create nodes in the abstract syntax tree
21 | this.string = m.doubleQuoted(this.quoteChar.zeroOrMore).ast;
22 | this.null = m.keyword("null").ast;
23 | this.bool = m.keywords("true", "false").ast;
24 | this.number = m.seq(this.plusOrMinus.opt, m.integer, this.fraction.opt, this.exponent.opt).ast;
25 |
26 | let _this = this;
27 | this.value = m.choice(this.string, this.bool, this.null, this.number,
28 | // Using a lazy evaluation rule to allow recursive rule definitions
29 | m.delay(function() { return m.choice(_this.object, _this.array);
30 | }));
31 |
32 | this.array = m.bracketed(m.delimited(this.value.ws, this.comma)).ast;
33 | this.pair = m.seq(this.string, m.ws, ":", m.ws, this.value.ws).ast;
34 | this.object = m.braced(m.delimited(this.pair.ws, this.comma)).ast;
35 | };
36 |
37 | // Register the grammar, providing a name and the default parse rule
38 | return m.registerGrammar("json", g, g.object);
39 | };
40 |
41 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
42 | if (typeof module === "object" && module.exports)
43 | module.exports = CreateJsonGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_lucene.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This is a grammar for Lucene 4.0 and Solr queries
4 | // http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html
5 | // https://wiki.apache.org/solr/SolrQuerySyntax
6 |
7 | // Additional grammars to be built
8 | // https://cwiki.apache.org/confluence/display/solr/Spatial+Search
9 | // https://wiki.apache.org/solr/SpatialSearch
10 | // http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/util/automaton/RegExp.html?is-external=true
11 |
12 | // Sample grammars
13 | // https://github.com/thoward/lucene-query-parser.js/blob/master/lib/lucene-query.grammar
14 | // https://github.com/lrowe/lucenequery/blob/master/lucenequery/StandardLuceneGrammar.g4
15 | // https://github.com/romanchyla/montysolr/blob/master/contrib/antlrqueryparser/grammars/StandardLuceneGrammar.g
16 |
17 | // TODO: is a&&b a single term? Or two terms?
18 | // TODO: support geo-coordinate parsing
19 | // TODO: support fucntion parsing
20 |
21 | // TODO: support date-time parsing
22 | // http://lucene.apache.org/solr/6_5_1/solr-core/org/apache/solr/util/DateMathParser.html
23 |
24 | function CreateLuceneGrammar(myna)
25 | {
26 | let m = myna;
27 |
28 | let g = new function()
29 | {
30 | let _this = this;
31 | this.delayedQuery = m.delay(function () { return _this.query; });
32 |
33 | this.ws = m.char(' \t\n\r\f').zeroOrMore;
34 | this.escapedChar = m.char('\\').advance;
35 | this.float = m.digit.zeroOrMore.then(m.seq('.', m.digits).opt).ast;
36 |
37 | //
38 | this.boostFactor = this.float.ast;
39 | this.boost = m.text("^").then(this.boostFactor).ast;
40 |
41 | this.fuzzFactor = this.float.ast;
42 | this.fuzz = m.seq('~', this.fuzzFactor.opt).ast;
43 |
44 | this.modifier = m.char("+-").ast;
45 |
46 | this.symbolicOperator = m.choice("||", "&&", "!");
47 | this.operator = m.keywords("OR NOT", "AND NOT", "OR", "AND", "NOT").or(this.symbolicOperator).opt.ast;
48 |
49 | // Represents valid termchars
50 | // NOTE: according to the specification additional characters are not accepted: ':/&|' however, many of these
51 | // interfere with date parsing.
52 | this.termChar = m.seq(this.symbolicOperator.not, m.notChar(' \t\r\n\f{}()"^~[]\\')).or(this.escapedChar);
53 |
54 | this.singleTerm = this.termChar.oneOrMore.ast;
55 | this.fieldName = this.termChar.unless(m.char(':/')).oneOrMore.ast;
56 | this.field = this.fieldName.then(':');
57 |
58 | // TODO: this should be in Myna
59 | this.phrase = m.doubleQuoted(m.notChar('"').zeroOrMore).ast;
60 | this.regex = m.seq('/', m.notChar('/').zeroOrMore, '/').ast;
61 |
62 | // TODO: use the whitespace in the grammar
63 | this.group = m.seq('(', this.delayedQuery, m.assert(')')).ast;
64 |
65 | // TODO: make the ranges a guarded sequence
66 | this.endPoint = m.seq(this.ws, this.singleTerm, this.ws);
67 | this.inclusiveRange = m.seq('[', this.endPoint, m.keyword("TO"), this.endPoint, ']').ast;
68 | this.exclusiveRange = m.seq('{', this.endPoint, m.keyword("TO"), this.endPoint, '}').ast;
69 | this.range = m.choice(this.inclusiveRange, this.exclusiveRange).ast;
70 | this.postOps = m.choice(this.boost.then(this.fuzz.opt), this.fuzz.then(this.boost.opt));
71 | this.term = m.seq(this.field.opt, this.modifier.opt, m.choice(this.group, this.singleTerm, this.phrase, this.regex, this.range), this.postOps.opt).ast;
72 |
73 | // localParams
74 | this.keyChar = m.letter.or(".");
75 | this.escapedChar = m.char('\\').then(m.advance);
76 | this.paramKey = this.keyChar.oneOrMore.ast;
77 | this.singleQuotedValue= m.singleQuotedString(this.escapedChar).ast;
78 | this.doubleQuotedValue= m.doubleQuotedString(this.escapedChar).ast;
79 | this.paramValue = m.choice(this.singleQuotedValue, this.doubleQuotedValue, this.term).ast;
80 | this.param = this.paramKey.then('=').opt.then(this.paramValue).ast;
81 | this.localParams = m.seq('{!', m.delimited(this.param, this.ws), m.assert('}')).ast;
82 |
83 | // Query
84 | this.terms = m.delimited(this.term.then(this.ws), this.operator.then(this.ws)).ast;
85 | this.query = m.seq(this.ws, this.localParams.opt, this.ws, this.terms, this.ws).ast;
86 | };
87 |
88 | // Register the grammar, providing a name and the default parse rule
89 | return m.registerGrammar("lucene", g, g.query);
90 | }
91 |
92 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
93 | if (typeof module === "object" && module.exports)
94 | module.exports = CreateLuceneGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/grammar_mustache.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // A Myna grammar for a variant of the Mustache and CTemplate template languages
4 | // This grammar works with any template delimiters defaulting to "{{" and "}}"
5 | // - http://mustache.github.io/mustache.5.html
6 | // - https://github.com/olafvdspek/ctemplate
7 | // According to the mustache documentation:
8 | // - `#` indicates a start section
9 | // - `/` indicates an end section
10 | // - `^` indicates an inverted section
11 | // - `!` indcates a comment
12 | // - `&` or `{` indicate an unescaped variable
13 | // - `>` indicates a *partial* which is effectively a file include with run-time expansion.
14 |
15 | function CreateMustacheGrammar(myna, start, end) {
16 | if (start == undefined)
17 | start = "{{";
18 | if (end == undefined)
19 | end = "}}";
20 |
21 | if (start.length == 0 || end.length == 0)
22 | throw "Missing start and end delimiters";
23 |
24 | let m = myna;
25 |
26 | // Create the grammar object
27 | let g = new function()
28 | {
29 | // Define a rule so that we can refer to content recursively
30 | let _this = this;
31 | this.recursiveContent = m.delay(function() { return _this.content; });
32 |
33 | // Main grammar rules.
34 | // Only those with 'ast' will generate nodes in the parse tree
35 | this.key = m.advanceWhileNot(end).ast;
36 | this.restOfLine = m.char(' \t').zeroOrMore.then(m.opt('\n'));
37 | this.startSection = m.seq(start, "#", this.key, end, this.restOfLine);
38 | this.endSection = m.seq(start, "/", this.key, end);
39 | this.startInvertedSection = m.seq(start, "^", this.key, end, this.restOfLine);
40 | this.escapedVar = m.seq(start, m.notAtChar("#/^!{&<"), this.key, end).ast;
41 | this.unescapedVar = m.seq(start, m.choice(m.seq("{", this.key, "}"), m.seq("&", this.key)), end).ast;
42 | this.var = m.choice(this.escapedVar, this.unescapedVar);
43 | this.partial = m.seq(start, ">", m.ws.opt, this.key, end).ast;
44 | this.comment = m.seq(start, "!", this.key, end).ast;
45 | this.sectionContent = this.recursiveContent.ast;
46 | this.section = m.guardedSeq(this.startSection, this.sectionContent, this.endSection).ast;
47 | this.invertedSection = m.guardedSeq(this.startInvertedSection, this.sectionContent, this.endSection).ast;
48 | this.plainText = m.advanceOneOrMoreWhileNot(start).ast;
49 | this.content = m.choice(this.invertedSection, this.section, this.comment, this.partial, this.var, this.plainText).zeroOrMore;
50 | this.document = this.content.ast;
51 | }
52 |
53 | // Register the grammar, providing a name and the default parse rule
54 | return m.registerGrammar("mustache", g, g.document);
55 | }
56 |
57 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
58 | if (typeof module === "object" && module.exports)
59 | module.exports = CreateMustacheGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/grammars/readme.md:
--------------------------------------------------------------------------------
1 | # Myna Grammars
2 |
3 | A Myna grammar is any JavaScript object that has Myna parsing rules as fields. A Myna parsing rule
4 | is an object derived from `Myna.Rule`.
5 |
6 | Typically a grammar constructor will register itself with Myna, using the `Myna.registerGrammar()`
7 | function. Registering a grammar, provides a name to each rule, and makes the rules of the grammar
8 | accesible to other consumers of the Myna module.
9 |
10 | The convention used in this library is that each grammar has its own source file which can
11 | be included in a JavaScript file. The grammar constructor is exported in such a way to be
12 | usable from Node.js.
13 |
14 | ## Grammar Utility Functions
15 |
16 | - `Myna.registerGrammar` - applies the name to each rule in the grammar and stores in Myna.
17 | - `Myna.allGrammarRules` - lists all of the rules for all registered grammars
18 | - `Myna.grammarNames` - lists the names of all the registered grammar
19 | - `Myna.grammarRules` - this the rules associated with a particular grammar
20 | - `Myna.grammarToString` - returns a string representation of a grammar in a pseduo-PEG notation
21 | - `Myna.astSchemaToString` - returns a string representation of the schema of AST nodes generated by a grammar
22 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "_from": "myna-parser",
3 | "_id": "myna-parser@2.5.1",
4 | "_inBundle": false,
5 | "_integrity": "sha512-eQBQpP91k1WiusCw2XPziVgUK+D8ISWyEKtJqmEWv28V+KYmEn9p+sm5l9502fIbzM8eVFH2PIx3JnptmQ1hGA==",
6 | "_location": "/myna-parser",
7 | "_phantomChildren": {},
8 | "_requested": {
9 | "type": "tag",
10 | "registry": true,
11 | "raw": "myna-parser",
12 | "name": "myna-parser",
13 | "escapedName": "myna-parser",
14 | "rawSpec": "",
15 | "saveSpec": null,
16 | "fetchSpec": "latest"
17 | },
18 | "_requiredBy": [
19 | "#USER",
20 | "/"
21 | ],
22 | "_resolved": "https://registry.npmjs.org/myna-parser/-/myna-parser-2.5.1.tgz",
23 | "_shasum": "e5d1d4be87993e66d3f8f88a5ff467d95ab54bcb",
24 | "_spec": "myna-parser",
25 | "_where": "C:\\Users\\Christopher\\Documents\\GitHub\\heron-language",
26 | "author": {
27 | "name": "Christopher Diggins",
28 | "email": "cdiggins@gmail.com"
29 | },
30 | "bugs": {
31 | "url": "https://github.com/cdiggins/myna-parser/issues"
32 | },
33 | "bundleDependencies": false,
34 | "deprecated": false,
35 | "description": "A text parsing (syntactic analysis) library written in TypeScript.",
36 | "devDependencies": {
37 | "cpx": "~1.5",
38 | "mocha": "~3.4",
39 | "typescript": "~2.0",
40 | "uglify-js": "~2.7"
41 | },
42 | "homepage": "https://cdiggins.github.io/myna-parser",
43 | "license": "MIT",
44 | "main": "myna.js",
45 | "name": "myna-parser",
46 | "repository": {
47 | "type": "git",
48 | "url": "git+https://github.com/cdiggins/myna-parser.git"
49 | },
50 | "runkitExampleFilename": "tests/test_node_example-1.js",
51 | "scripts": {
52 | "build": "tsc",
53 | "copyfiles": "cpx {myna.ts,myna.js,examples/*.*,tests/*.*,grammars/*.js} docs",
54 | "full": "npm run build && npm test && npm run testBrowser && npm run makesite && npm run copyfiles && npm run makedist",
55 | "makedist": "uglifyjs myna.js -o dist/myna.min.js",
56 | "makesite": "node tools/myna_build_site.js",
57 | "test": "mocha tests/mocha_runner.js",
58 | "testBrowser": ".\\tests\\qunit.html",
59 | "testTools": "node .\\tests\\test_all_tools"
60 | },
61 | "version": "2.5.1"
62 | }
63 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/packages/myna_markdown_to_html/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "myna-markdown-to-html",
3 | "version": "1.0.0",
4 | "description": "A Node.JS JavaScript module for converting git-flavored Markdown to HTML.",
5 | "main": "../../tools/myna.js",
6 | "scripts": {
7 | "test": "../../tests/test_markdown_to_html.js"
8 | },
9 | "homepage": "https://github.com/cdiggins/myna-parser",
10 | "bugs": "https://github.com/cdiggins/myna-parser/issues",
11 | "license": "MIT",
12 | "author": {
13 | "name": "Christopher Diggins",
14 | "email": "cdiggins@gmail.com"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "https://github.com/cdiggins/myna-parser.git"
19 | },
20 | "dependencies": {
21 | "myna-parser" : "^2.2.4"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/sandbox/grammars_in_progress/comments.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a parser for common programming language comments
4 | // C++, Java, C#, JavaScript, TypeScript, etc.
5 | function CommentsGrammar(myna)
6 | {
7 | // Setup a shorthand for the Myna parsing library object
8 | let m = myna;
9 |
10 | this.ws = m.space.or(m.tab).zeroOrMore;
11 | this.newLine = this.newLine.copy.ast;
12 | this.lineCommentContents = m.advanceWhileNot(this.newLine).ast;
13 | this.lineComment = m.seq("//", m.zeroOrMore("/").ws, this.lineCommentContents, this.newLine);
14 | this.lineComments = this.lineComment.oneOrMore.ast;
15 |
16 | this.blockCommentLineContents = m.advanceWhileNot(m.choice("*/"), this.newLine).ast;
17 | this.blockCommentLine = m.seq(this.ws, m.star("*").ws, this.blockCommentLineComments);
18 | this.blockComment = m.seq("/*", this.blockCommentLine.then(this.newLine).zeroOrMore, "*/").ast;
19 |
20 | this.code = m.seq(m.advanceWhileNot(m.or(this.newLine, m.blockComment, m.lineComment))).ast;
21 | this.element = m.choice(this.ws, this.code, this.blockComment, this.lineComment, this.newLine);
22 |
23 | this.file = this.element.star;
24 | };
25 |
26 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
27 | if (typeof module === "object" && module.exports)
28 | module.exports = CommentsGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/sandbox/grammars_in_progress/javascript_tokens.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Implements a grammar for parsing JavaScript code into tokens
4 | // See:
5 | // - https://tc39.github.io/ecma262/#sec-ecmascript-language-lexical-grammar
6 | // - https://github.com/jquery/esprima/blob/master/src/scanner.ts
7 | // - https://github.com/jquery/esprima/blob/master/src/token.ts
8 |
9 | function JavaScriptTokenGrammar(myna)
10 | {
11 | let m = myna;
12 | this.whiteSpace = m.ws.copy.ast;
13 | this.lf = m.char("\u000a");
14 | this.cr = m.char("\u000D");
15 | this.ls = m.char("\u2028");
16 | this.ps = m.char("\u2029");
17 | this.lineTerminator = m.choice(this.lf, this.cr, this.ls, this.ps).ast;
18 | this.lineTerminatorSequence = m.choice(this.lf, this.cr.thenNot(this.lf), this.ls, this.ps, this.cr.then(this.lf));
19 |
20 | // TODO: find a way to signal that the input is invalid.
21 | this.multiLineComment = m.seq("/*", m.advanceUntil(m.choice("*/", m.end))).ast;
22 | this.singleLineComment = m.seq("//", m.advanceUntil(this.lineTerminator.or(m.end))).ast;
23 | this.comment = this.multiLineComment.or(this.singleLineComment);
24 |
25 | this.keyword = m.keywords("break do in typeof case else instanceof var catch export new void class extends return while"
26 | + "const finally super with continue for switch yield debugger function this default if throw delete import try await".split(" ")).ast;
27 |
28 | this.futureKeywords = m.keywords("enum await implements package protected interface private public".split(" "));
29 |
30 | this.punctuator = m.choice("{ ( ) [ ] . ... ; , < > <= >= == != === !== + - * % ++ -- << >> >>> & | ^ ! ~ && || ? : = += -= *= %= <<= >>= >>>= &= |= ^= => ** **=".split(" "));
31 |
32 | this.divPunctuator = m.seq("/", "/=");
33 | this.rightBrace = m.text("}");
34 |
35 | this.nullLiteral = m.text("null").ast;
36 |
37 | this.fraction = m.seq(".", m.digit.zeroOrMore);
38 | this.plusOrMinus = m.char("+-");
39 | this.exponent = m.seq(m.char("eE"), this.plusOrMinus.opt, m.digit.plus);
40 |
41 | this.decimalLiteral = m.seq(this.plusOrMinus.opt, m.integer, this.fraction.opt, this.exponent.opt).ast
42 |
43 | this.binaryDigits = m.binaryDigit.plus.ast;
44 | this.octalDigits = m.octalDigit.plus.ast;
45 | this.hexDigits = m.hexDigit.plus.ast;
46 |
47 | this.octalLiteral = m.seq("0", m.char("oO"), this.octalDigits).ast;
48 | this.binaryLiteral = m.seq("0", m.char("bB"), this.binaryDigits).ast;
49 | this.hexLiteral = m.seq("0", m.char("xF"), this.hexDigits).ast;
50 |
51 | this.numericLiteral = m.choice(this.decimalLiteral, this.binaryLiteral, this.octalLiteral, this.hexLiteral).thenNot(m.IdentifierFirst.or(m.digit));
52 |
53 | this.unicodeHexDigits = m.hexDigit.repeat(4).ast;
54 | this.unicodeEscapeSeq = m.seq('u', this.unicodeHexDigits.or(m.seq('{', this.unicodeHexDigits, '}')));
55 | this.hexEscapeDigits = m.seq(m.hexDigit, m.hexDigit).ast;
56 | this.hexEscapeSeq = m.seq('x', this.hexEscapeDigits).ast;
57 | this.escapeChar = m.char('\'"\\bfnrtv');
58 |
59 | this.escapeSeq = this.charEscapeSeq().or('0').
60 |
61 | this.lineContinuation = m.seq('\\', this.lineTerminatorSequence).ast;
62 | this.escapedLiteralChar = m.char('\\').then('')
63 |
64 | this.stringLiteralChar = m.notChar("\u005C\u000D\u2028\u2029\u000A\\").or(this.escapedLiteralChar).or(this.lineContinuation).ast;
65 |
66 | this.doubleQuotedStringContents = m.not('"').then(stringLiteralChar).zeroOrMore.ast;
67 | this.singleQuotedStringContents = m.not("'").then(stringLiteralChar).zeroOrMore.ast;
68 | this.doubleQuote = m.seq('"', this.doubleQuotedStringContents, '"');
69 | this.singleQuote = m.seq("'", this.singleQuotedStringContents, "'");
70 | this.stringLiteral = this.doubleQuote.or(this.singleQuote);
71 |
72 | this.regexNonTerminator = m.notChar(lineTerminator);
73 | this.regexBackslashSeq = m.seq('\\', this.regexNonTerminator);
74 |
75 | this.regexClassChar = this.not(']', '\\').then(regexNonTerminator).or(regexBackslashSeq).ast;
76 | this.regexClass = m.seq('[', this.regexClassChar.zeroOrMore, ']').ast;
77 | this.regexIllegalChar = m.char('\\/[');
78 | this.regexChar = this.regexNonTerminator.butNot(regexIllegalChar);
79 | this.regexLiteral = m.seq('/', this.regexBody, '/', this.regexFlags).ast;
80 |
81 | this.token = m.choice(this.nullLiteral, this.regexLiteral, this.identifierName, this.numericLiteral, this.stringLiteral, this.punctuator,
82 | this.templateLiteral);
83 | }
84 |
85 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
86 | if (typeof module === "object" && module.exports)
87 | module.exports = JavaScriptTokenGrammar;
--------------------------------------------------------------------------------
/node_modules/myna-parser/sandbox/heron.md:
--------------------------------------------------------------------------------
1 | # Heron Notes
2 |
3 | 1. I need to generate a shader web-page.
4 | 1. I need to generate very basic procedural objects.
5 | 1. How to compose those little guys together.
6 | 1. Draw the thing.
7 |
8 | ## Shader Inputs
9 |
10 | ```
11 | uniform vec3 iResolution; // viewport resolution (in pixels)
12 | uniform float iTime; // shader playback time (in seconds)
13 | uniform float iTimeDelta; // render time (in seconds)
14 | uniform int iFrame; // shader playback frame
15 | uniform float iChannelTime[4]; // channel playback time (in seconds)
16 | uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
17 | uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click
18 | uniform samplerXX iChannel0..3; // input channel. XX = 2D/Cube
19 | uniform vec4 iDate; // (year, month, day, time in seconds)
20 | uniform float iSampleRate; // sound sample rate (i.e., 44100)
21 | ```
22 |
23 | 1. The type system will be key.
24 |
25 | //
26 | // TODO:
27 | // * Add rich set of examples from Scheme (and Cat and Python and JavaScript) using Myna.
28 | // * Should I have a separate system for this? Or just stick it in? Probably just sticking it in is fine.
29 | // * Handle circular type references. That is going to be freaking awesome.
30 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/test_arithmetic.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let myna = require('../myna');
4 | let grammar = require('../grammars/grammar_arithmetic')(myna);
5 | let evaluator = require('../tools/myna_arithmetic_evaluator.js')(myna);
6 |
7 | let arithmeticTestInputs = [
8 | ["(42)", 42],
9 | ["6 * 7", 42],
10 | ["42", 42],
11 | ["0", 0],
12 | ["-42", -42],
13 | ["- 5", -5],
14 | ["-\t- 5", 5],
15 | ["-(42)", -42],
16 | ["+42", +42],
17 | ["+(42)", +42],
18 | ["2 * 3 * 7", 42],
19 | ["5 * 8 + 2", 42],
20 | ["2 + 5 * 8", 42],
21 | ["(5 * 8) + 2", 42],
22 | ["2 + (5 * 8)", 42],
23 | ["((5 * 8) + 2)", 42],
24 | ["(2 + (5 * 8))", 42],
25 | ["6 * (9 - 2)", 42],
26 | ["(9 - 2) * 6", 42],
27 | ["5 * 9 - 3", 42],
28 | ["-5 * 9", -45],
29 | ["3 - -5", 8],
30 | ["-3 - -5 * 9", 42]];
31 |
32 | for (let test of arithmeticTestInputs) {
33 | let input = test[0];
34 | let expected = test[1];
35 | let result = evaluator(input);
36 | if (result !== expected)
37 | console.log("test failed: " + test + ", instead was: " + result);
38 | else
39 | console.log("test passed: " + test)
40 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/heron_tools.js:
--------------------------------------------------------------------------------
1 | // 1) Input Myna
2 |
3 | 'use strict';
4 |
5 | let myna = require('../myna');
6 | let g = require('../grammars/grammar_heron')(myna);
7 | let fs = require('fs');
8 |
9 | function processType(ast) {
10 | if (ast.name != "typeExpr") throw new Error("expected a type expression");
11 | return ast.allText;
12 | }
13 |
14 | function processPrimitive(ast, prims) {
15 | var name = ast.children[0].allText;
16 | var type = processType(ast.children[1]);
17 | prims[name] = type;
18 | }
19 |
20 | var heronTools = new function() {
21 | this.parsePrimitives = function(fileName) {
22 | var text = fs.readFileSync(fileName, 'utf-8');
23 | var ast = myna.parse(g.primitiveFile, text);
24 | var prims = {};
25 | for (var p of ast.children)
26 | processPrimitive(p, prims);
27 | return prims;
28 | }
29 | }
30 |
31 | // Export the function for use use with Node.js
32 | if (typeof module === "object" && module.exports)
33 | module.exports = heronTools;
34 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/mocha_runner.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Load Myna and all the grammars
4 | var m = require('../tools/myna_all');
5 | var inputs = require('../tests/rule_test_inputs')(m);
6 | var ruleTester = require('../tests/rule_tester');
7 | var assert = require('assert');
8 |
9 | // Set up the unit tests with Mocha
10 | describe("Parser tests", function() {
11 | function tester(name, testFxn) {
12 | //console.log("Running test: " + name);
13 | it(name, function() { testFxn(assert); });
14 | }
15 | ruleTester(m, inputs, tester);
16 | });
17 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/output_grammars.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This project outputs the grammars and the schemas of the AST trees
4 |
5 | var myna = require('../tools/myna_all');
6 |
7 | for (let g of myna.grammarNames())
8 | {
9 | console.log("==============================");
10 | console.log("Grammar: " + g);
11 | console.log("==============================");
12 | console.log(myna.grammarToString(g));
13 |
14 | console.log("==============================");
15 | console.log("AST Schema: " + g);
16 | console.log("==============================");
17 | console.log(myna.astSchemaToString(g));
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/performance.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Performance Test
4 |
5 |
6 |
7 |
17 |
18 |
19 | A Performance Test for Myna in the Browser
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/qunit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | QUnit Tests for the Myna Parsing Library
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
55 |
56 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/readme.md:
--------------------------------------------------------------------------------
1 | # Myna Tests
2 |
3 | There are two types of tests with Myna
4 |
5 | 1. **Parser tests** - Effectively these are unit tests run using QUnit or Mochas which test the core parsers, the various combinarors, and the sample grammars.
6 | 2. **Tool tests** - These are integration tests, which test simples tools built using the sample grammars.
7 |
8 | The tool tests demonstrate how to use Myna in an actual tool.
9 |
10 | ## Using Myna in a Browser
11 |
12 | Look at `tests\test_browser_unpkg.html` for an example of using Myna in the browser. Notice that instead of using a module loader we need to define a global variable called exports before including the Myna JavaScript file which will add a new variable called `Myna` to the global namespace.
13 |
14 | ## Parser Tests
15 |
16 | To run the Parse tests open the `QUnit.html` file in your browser. You do not have to be using a server, you can just point your browser to the local file.
17 |
18 | ## Tool Tests
19 |
20 | To run the local tests you will need to use node from the root folder of the Myna distribution as follows:
21 |
22 | ```
23 | node tests\test_tools.js
24 | ```
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/rule_tester.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // This class tests parser rules given an array of inputs.
4 | // Each input is an array [rule, [passing inputs], [failing inputs]]
5 | // The TestRunner is a function like QUnit.test
6 | function RuleTester(myna, inputs, testRunner)
7 | {
8 | if (!myna)
9 | throw new Error("Missing Myna module");
10 | if (!inputs)
11 | throw new Error("Missing inputs");
12 | if (!testRunner)
13 | throw new Error("Missing test runner")
14 |
15 | // Tests parsing an individual rule against the input input text, and returns an object
16 | // representing the result of running the test
17 | function testParse(rule, assert, text, shouldPass) {
18 | if (shouldPass == undefined) shouldPass = true;
19 | let result = myna.failed;
20 | let err = undefined;
21 | try {
22 | let node = myna.parse(rule, text);
23 | if (node)
24 | result = node.end;
25 | }
26 | catch (e) {
27 | if (e.type !== 'ParserError') {
28 | throw e;
29 | }
30 | err = e;
31 | }
32 |
33 | let testResult = {
34 | name : rule.toString() + ' with input "' + text + '"',
35 | description : result + "/" + text.length,
36 | negative : !shouldPass,
37 | success : (result == text.length) ^ !shouldPass,
38 | error : err,
39 | ruleDescr : rule.type + ": " + rule.toString(),
40 | rule : rule
41 | };
42 |
43 | if (!testResult.success)
44 | console.log(testResult);
45 |
46 | assert.ok(testResult.success, testResult.name + (shouldPass ? "" : " should fail"));
47 | }
48 |
49 | // Tests parsing an individual rule against using an array of inputs string that should pass
50 | // and an array of inputs strings that should fail.
51 | function testRule(rule, assert, passStrings, failStrings) {
52 | for (let input of passStrings)
53 | testParse(rule, assert, input, true);
54 |
55 | for (let input of failStrings)
56 | testParse(rule, assert, input, false);
57 | }
58 |
59 | //===============================================
60 | // Body of the function
61 |
62 | for (let i=0; i < inputs.length; ++i)
63 | {
64 | let t = inputs[i];
65 | if (!t || t.length < 2 || !t[0])
66 | throw new Error("Each test must have a rule, an array of passing strings, and an array of failing strings");
67 |
68 | testRunner(t[0].toString(), function(assert) {
69 | testRule(t[0], assert, t[1], t[2]);
70 | });
71 | }
72 | }
73 |
74 | // Export the grammar for usage by Node.js and CommonJs compatible module loaders
75 | if (typeof module === "object" && module.exports)
76 | module.exports = RuleTester;
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_all_tools.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | console.log("");
4 | console.log("Testing HTML character escaping");
5 | let test_escape_html_chars = require('../tests/test_escape_html_chars');
6 |
7 | console.log("");
8 | console.log("Testing Mustaches style template expander");
9 | let test_mustache_expander = require('../tests/test_mustache_expander');
10 |
11 | console.log("");
12 | console.log("Testing Lucene parser");
13 | let test_lucene = require('../tests/test_lucene');
14 |
15 | process.exit();
16 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_browser_unpkg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_escape_html_chars.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let fs = require("fs");
4 | let myna = require("../myna");
5 | let escapeHtmlChars = require('../tools/myna_escape_html_chars');
6 |
7 | function testEscape(text, expected) {
8 | console.log("Input: " + text);
9 | console.log("Expected: " + expected);
10 | let result = escapeHtmlChars(text);
11 | console.log("Output: " + result);
12 | console.log(result == expected ? "Success" : "Failure");
13 | }
14 |
15 | testEscape("123", "123");
16 | testEscape("'", "'");
17 | testEscape("< >", "< >");
18 | testEscape(" && ", " && ");
19 | testEscape('"', """);
20 | testEscape("", "");
21 |
22 | function timeIt(f) {
23 | let t = process.hrtime();
24 | f();
25 | t = process.hrtime(t);
26 | // https://blog.tompawlak.org/measure-execution-time-nodejs-javascript
27 | let msec = Math.floor(t[0] * 1000 + t[1] / (1000 * 1000));
28 | console.log('benchmark took %d msec', msec);
29 | }
30 |
31 | function naiveEscapeChars(s) {
32 | // http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript
33 | return s.replace(/&/g, "&").replace(/>/g, ">").replace(/now+5d',
59 | 'created_at:>now-5d',
60 | ' Test:Foo',
61 | ' \r\n'
62 | ]
63 |
64 | for (let q of qs) {
65 | testQuery(q);
66 | }
67 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_markdown_to_html.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | var fs = require('fs');
4 | var mdToHtml = require('../tools/myna_markdown_to_html');
5 |
6 | // This is a recently failing test.
7 | var testUrlList =
8 | `## Themes
9 |
10 | * https://github.com/mixu/markdown-styles
11 | * https://themes.gohugo.io
12 | * https://jekyllthemes.org
13 | * https://en-ca.wordpress.org/themes
14 | * https://colorlib.com/wp/free-wordpress-themes
15 | * https://hexo.io/themes`;
16 |
17 | var html = mdToHtml(testUrlList);
18 | console.log(html);
19 |
20 | // This creates an HTML file from the readme
21 | var md = fs.readFileSync('readme.md', 'utf-8');
22 | var content = mdToHtml(md);
23 | fs.writeFileSync('tests/output/readme.html', content, { encoding:'utf-8' });
24 |
25 | process.exit();
26 |
27 |
28 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_mustache_expander.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let myna = require('../myna');
4 | let expand = require('../tools/myna_mustache_expander');
5 |
6 | function testExpand(template, data, expected) {
7 | console.log("Expanding template: ", template);
8 | console.log(" Data: ", data);
9 | let result = expand(template, data);
10 | console.log(" Result: ", result);
11 | console.log(" Expected: ", expected);
12 | console.log(result == expected ? "Passed" : "Failed");
13 | }
14 |
15 | console.log("==========");
16 | console.log("Basic expansion tests");
17 | console.log("==========");
18 | testExpand("{{a}}", { a:42 }, "42");
19 | testExpand("{{a}}", null, "");
20 | testExpand("a b c", null, "a b c");
21 | testExpand("a {b} c", { b: 42 }, "a {b} c");
22 | testExpand("a {{b}} c", { b: 42 }, "a 42 c");
23 | testExpand("{{a}}", { }, "");
24 | testExpand("{{a}}", { a:"<>"}, "<>");
25 | testExpand("{{{a}}}", { a:"<>"}, "<>");
26 | testExpand("{{&a}}", { a:"<>"}, "<>");
27 | testExpand("{{a}} {{b}} {{c}} {{d}}", { a:10, b:"hello", d:true}, "10 hello true");
28 | testExpand("{{a}}{{b}}{{c}},{{#test}}{{a}}{{b}}{{c}}{{/test}}", { a:"A", b:"X", test:{ b:"B", c:"C" }}, "AX,ABC");
29 |
30 | console.log("Example 1");
31 | {
32 | let t = [
33 | "Hello {{name}}",
34 | "You have just won {{value}} dollars!",
35 | "{{#in_ca}}",
36 | "Well, {{taxed_value}} dollars, after taxes.",
37 | "{{/in_ca}}",
38 | ].join('\n');
39 |
40 | let h = {
41 | "name": "Chris",
42 | "value": 10000,
43 | "taxed_value": 10000 - (10000 * 0.4),
44 | "in_ca": true
45 | };
46 |
47 | console.log(expand(t, h));
48 | }
49 |
50 | console.log("Example 3");
51 | {
52 | let t = [
53 | "* {{name}}",
54 | "* {{age}}",
55 | "* {{company}}",
56 | "* {{{company}}}",
57 | ].join('\n');
58 |
59 | let h = {
60 | "name": "Chris",
61 | "company": "GitHub "
62 | };
63 |
64 | console.log(expand(t, h));
65 | }
66 |
67 | console.log("Example 4");
68 | {
69 | let t = [
70 | "Shown.",
71 | "{{#person}}",
72 | "Never shown!",
73 | "{{/person}}",
74 | ].join('\n');
75 |
76 | let h = {
77 | "person" : false
78 | };
79 |
80 | console.log(expand(t, h));
81 | }
82 |
83 | console.log("Example 5");
84 | {
85 | let t = [
86 | "{{#repo}}",
87 | "{{name}} ",
88 | "{{/repo}}",
89 | ].join('\n');
90 |
91 | let h = {
92 | "repo": [
93 | { "name": "resque" },
94 | { "name": "hub" },
95 | { "name": "rip" }
96 | ]
97 | };
98 |
99 | console.log(expand(t, h));
100 | }
101 |
102 | console.log("Example 6");
103 | {
104 | let t = [
105 | "{{#person?}}",
106 | " Hi {{name}}!",
107 | "{{/person?}}",
108 | ].join('\n');
109 |
110 | let h =
111 | {
112 | "person?": { "name": "Jon" }
113 | };
114 |
115 | console.log(expand(t, h));
116 | }
117 |
118 | console.log("Example 7");
119 | {
120 | let t = [
121 | "{{#repo}}",
122 | "{{name}} ",
123 | "{{/repo}}",
124 | "{{^repo}}",
125 | "No repos :(",
126 | "{{/repo}}",
127 | ].join('\n');
128 |
129 | let h = {
130 | "repo": []
131 | }
132 |
133 | console.log(expand(t, h));
134 | }
135 |
136 | console.log("Example 8");
137 | {
138 | console.log(expand("Today{{! ignore me }}. ", {}));
139 | }
140 |
141 | console.log("Example 9");
142 | {
143 | console.log(expand("{{text}}", { today : "Tuesday", text : "Today is {{today}}" }));
144 | }
145 |
146 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_node.js:
--------------------------------------------------------------------------------
1 | let m = require('../myna');
2 |
3 | for (let r of m.allGrammarRules())
4 | console.log(r.toString());
5 |
6 | process.exit();
7 |
8 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_parser_failure.js:
--------------------------------------------------------------------------------
1 | var myna = require('../myna');
2 | var g = require('../grammars/grammar_json')(myna);
3 | var parse = myna.parsers.json;
4 |
5 | try
6 | {
7 | var ast = parse(
8 | `{
9 | "number" : 42,
10 | "array" : [1, 2, 3 }
11 | }`);
12 |
13 | console.log(ast);
14 | }
15 | catch (e)
16 | {
17 | console.log("Error occured:");
18 | console.log(e.toString());
19 | }
20 |
21 | process.exit();
22 |
23 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_pithy.js:
--------------------------------------------------------------------------------
1 | var myna = require('../myna');
2 | var g = require('../grammars/grammar_pithy')(myna);
3 |
4 | console.log("Pithy Grammar");
5 | console.log(myna.grammarToString("pithy"));
6 |
7 | console.log("Pithy AST Schema");
8 | console.log(myna.astSchemaToString("pithy"));
9 |
10 | process.exit();
11 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_typescript_import.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | // This file demonstrates how to use Myna from a TypeScript project
3 | var myna_1 = require("../myna");
4 | for (var _i = 0, _a = myna_1.Myna.allGrammarRules(); _i < _a.length; _i++) {
5 | var r = _a[_i];
6 | console.log(r.toString());
7 | }
8 | process.exit();
9 | //# sourceMappingURL=test_typescript_import.js.map
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_typescript_import.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"test_typescript_import.js","sourceRoot":"","sources":["test_typescript_import.ts"],"names":[],"mappings":";AAAA,oEAAoE;AACpE,qBAA0B,SAAS,CAAC,CAAA;AACpC,GAAG,CAAC,CAAU,UAAmB,EAAnB,KAAA,WAAC,CAAC,eAAe,EAAE,EAAnB,cAAmB,EAAnB,IAAmB,CAAC;IAA7B,IAAI,CAAC,SAAA;IACN,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;CAAA;AAG9B,OAAO,CAAC,IAAI,EAAE,CAAC"}
--------------------------------------------------------------------------------
/node_modules/myna-parser/tests/test_typescript_import.ts:
--------------------------------------------------------------------------------
1 | // This file demonstrates how to use Myna from a TypeScript project
2 | import { Myna as m } from "../myna";
3 | for (let r of m.allGrammarRules())
4 | console.log(r.toString());
5 |
6 | declare var process : any;
7 | process.exit();
8 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_all.js:
--------------------------------------------------------------------------------
1 | // Loads the Myna module and all grammars
2 | "use strict";
3 |
4 | var myna = require('../myna');
5 | require('../grammars/grammar_arithmetic')(myna);
6 | require('../grammars/grammar_csv')(myna);
7 | require('../grammars/grammar_html_reserved_chars')(myna);
8 | require('../grammars/grammar_json')(myna);
9 | require('../grammars/grammar_lucene')(myna);
10 | require('../grammars/grammar_markdown')(myna);
11 | require('../grammars/grammar_mustache')(myna);
12 | require('../grammars/grammar_glsl')(myna);
13 |
14 | module.exports = myna;
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_arithmetic_evaluator.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function EvalArithmetic(exprNode)
4 | {
5 | switch (exprNode.rule.name)
6 | {
7 | case "expr":
8 | {
9 | return EvalArithmetic(exprNode.children[0]);
10 | }
11 | case "sum":
12 | {
13 | let v = EvalArithmetic(exprNode.children[0]);
14 | for (let i=1; i < exprNode.children.length; ++i) {
15 | let child = exprNode.children[i];
16 | switch (child.rule.name) {
17 | case("addExpr"): v += EvalArithmetic(child); break;
18 | case("subExpr"): v -= EvalArithmetic(child); break;
19 | default: throw "Unexpected expression " + child.rule.name;
20 | }
21 | }
22 | return v;
23 | }
24 | case "product":
25 | {
26 | let v = EvalArithmetic(exprNode.children[0]);
27 | for (let i=1; i < exprNode.children.length; ++i) {
28 | let child = exprNode.children[i];
29 | switch (child.rule.name) {
30 | case("mulExpr"): v *= EvalArithmetic(child); break;
31 | case("divExpr"): v /= EvalArithmetic(child); break;
32 | default: throw "Unexpected expression " + child.rule.name;
33 | }
34 | }
35 | return v;
36 | }
37 | case "prefixExpr":
38 | {
39 | let v = EvalArithmetic(exprNode.children[exprNode.children.length-1]);
40 | for (let i=exprNode.children.length-2; i >= 0; --i)
41 | if (exprNode.children[i].allText == "-")
42 | v = -v;
43 | return v;
44 | }
45 | case "parenExpr" : return EvalArithmetic(exprNode.children[0]);
46 | case "number": return Number(exprNode.allText);
47 | case "addExpr": return EvalArithmetic(exprNode.children[0]);
48 | case "subExpr": return EvalArithmetic(exprNode.children[0]);
49 | case "mulExpr": return EvalArithmetic(exprNode.children[0]);
50 | case "divExpr": return EvalArithmetic(exprNode.children[0]);
51 | default: throw "Unrecognized expression " + exprNode.rule.name;
52 | }
53 | }
54 |
55 | function CreateEvaluator(myna) {
56 | return function (expr) {
57 | let ast = myna.parsers.arithmetic(expr);
58 | return EvalArithmetic(ast);
59 | }
60 | }
61 |
62 | // Export the function for use with Node.js
63 | if (typeof module === "object" && module.exports)
64 | module.exports = CreateEvaluator;
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_augment_ast.js:
--------------------------------------------------------------------------------
1 | // Adds additional information to an AST once it has been constructed.
2 | // This information is expensive to add at parse time.
3 | // It adds a parent pointer, a unique index, a row number, and a column number.
4 | // All of the nodes are then placed in an array.
5 | function augmentAstTree(ast) {
6 | return augmentAstNode(ast, null, 0, 0, 0, []);
7 | }
8 |
9 | function augmentAstNode(node, parent, index, rowNum, colNum, nodes) {
10 | var lineCount1 = 0;
11 | var lineCount2 = 0;
12 | for (;index < node.start; ++index) {
13 | if (node.input.charCodeAt(index) == 10) {
14 | lineCount1++;
15 | colNum = 0;
16 | }
17 | else if (node.input.charCodeAt(index) == 13) {
18 | lineCount2++;
19 | colNum = 0;
20 | }
21 | else {
22 | colNum++;
23 | }
24 | }
25 | if (lineCount1 >= lineCount2) {
26 | rowNum += lineCount1;
27 | }
28 | else {
29 | rowNum += lineCount2;
30 | }
31 | node.parent = parent;
32 | node.rowNum = rowNum;
33 | node.colNum = colNum;
34 | node.index = nodes.length;
35 | nodes.push(node);
36 | for (var child of node.children)
37 | augmentAstNode(child, node, index, rowNum, colNum, nodes);
38 | return nodes;
39 | }
40 |
41 | // Export the function for use use with Node.js
42 | if (typeof module === "object" && module.exports)
43 | module.exports = augmentAstTree;
44 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_build_site.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Modules
4 | var fs = require("fs");
5 | var path = require('path');
6 | var mdToHtml = require('../tools/myna_markdown_to_html');
7 | var expand = require('../tools/myna_mustache_expander');
8 |
9 | // File paths
10 | var templateFilePath = 'website/index.template.html';
11 | var markdownFilePath = 'website/index.md';
12 | var indexFilePath = 'docs/index.html';
13 |
14 | // logic
15 | var template = fs.readFileSync(templateFilePath, 'utf-8');
16 | var markdown = fs.readFileSync(markdownFilePath, 'utf-8');
17 | var content = mdToHtml(markdown);
18 | var index = expand(template, { content: content });
19 | fs.writeFileSync(indexFilePath, index, 'utf-8');
20 |
21 | // Complete
22 | process.exit();
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_escape_html_chars.js:
--------------------------------------------------------------------------------
1 | // This module replaces HTML reserved characters in text
2 | // with the appropriate entities using the Myna module.
3 | // The concept is to scan text creating AST nodes for reserved
4 | // characters or "plain text" which are strings of characters
5 | // containing none of the reserved text.
6 |
7 | 'use strict';
8 |
9 | // Load the Myna module
10 | let myna = require('../myna');
11 |
12 | // Get the HTML reserved characters grammar
13 | require('../grammars/grammar_html_reserved_chars')(myna);
14 |
15 | // Given a character that belongs to one of the reserved HTML characters
16 | // returns the entity representation. For all other text, returns the text
17 | function charToEntity(text) {
18 | if (text.length != 1)
19 | return text;
20 | switch (text) {
21 | case '&': return "&";
22 | case '<': return "<";
23 | case '>': return ">";
24 | case '"': return """;
25 | case "'": return "'";
26 | };
27 | return text;
28 | }
29 |
30 | // Given an ast node that represents either an HTML reserved char or
31 | // text without any special entity returns a sanitized version
32 | function astNodeToHtmlText(ast) {
33 | return charToEntity(ast.allText);
34 | }
35 |
36 | // Returns a string, replacing all of the reserved characters with entities
37 | function escapeHtmlChars(text)
38 | {
39 | let ast = myna.parsers.html_reserved_chars(text);
40 | if (!ast.children)
41 | return "";
42 | return ast.children.map(astNodeToHtmlText).join('');
43 | }
44 |
45 | // Export the main function for usage by Node.js and CommonJs compatible module loaders
46 | if (typeof module === "object" && module.exports)
47 | module.exports = escapeHtmlChars;
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_generate_ast_visitor.js:
--------------------------------------------------------------------------------
1 | // The createAstVisitor function creates a file of code that contains a Visitor object specialized
2 | // for walking the parse tree created from a grammar.
3 | //
4 | // This can be useful when constructing code for parsing special types of grammars
5 |
6 | function createAstVisitorFunction(rule, lines) {
7 | lines.push(" this.visit_" + rule.name + " = function(ast, stack, state) {");
8 | lines.push(" // " + rule.astRuleDefn());
9 | lines.push(" // TODO: add custom implementation")
10 | lines.push(" this.visitChildren(ast, stack, state);");
11 | lines.push(" }")
12 | }
13 |
14 | function createAstVisitor(myna, grammarName) {
15 | var lines = [
16 | "var " + grammarName + "Visitor = new function()",
17 | "{",
18 | " this.visitNode = function(ast, state) {",
19 | " this['visit_' + child.name](child, state);",
20 | " }",
21 | " this.visitChildren = function(ast, state) {",
22 | " for (var child of ast.children)",
23 | " this.visitNode(child, state);",
24 | " }"
25 | ];
26 | var rules = myna.grammarAstRules(grammarName);
27 | for (var r of rules)
28 | createAstVisitorFunction(r, lines);
29 | lines.push("}");
30 |
31 | return lines.join("\n");
32 | }
33 |
34 | // Export the function for use use with Node.js
35 | if (typeof module === "object" && module.exports)
36 | module.exports = createAstVisitor;
37 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_markdown_to_html.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var myna = require('../myna');
4 | var mdGrammar = require('../grammars/grammar_markdown')(myna);
5 |
6 | // Returns the HTML for a start tag
7 | function startTag(tag, attr) {
8 | let attrStr = "";
9 | if (attr) {
10 | attrStr = " " + Object.keys(attr).map(function(k) {
11 | return k + ' = "' + attr[k] + '"';
12 | }).join(" ");
13 | }
14 | return "<" + tag + attrStr + ">";
15 | }
16 |
17 | // Returns the HTML for an end tag
18 | function endTag(tag) {
19 | return "" + tag + ">";
20 | }
21 |
22 | // Returns HTML from a MarkDown AST
23 | function mdAstToHtml(ast, lines) {
24 | if (lines == undefined)
25 | lines = [];
26 |
27 | // Adds each element of the array as markdown
28 | function addArray(ast) {
29 | for (let child of ast)
30 | mdAstToHtml(child, lines);
31 | return lines;
32 | }
33 |
34 | // Adds tagged content
35 | function addTag(tag, ast, newLine) {
36 | lines.push(startTag(tag));
37 | if (ast instanceof Array)
38 | addArray(ast);
39 | else
40 | mdAstToHtml(ast, lines);
41 | lines.push(endTag(tag));
42 | if (newLine)
43 | lines.push('\r\n');
44 | return lines;
45 | }
46 |
47 | function addLink(url, astOrText) {
48 | lines.push(startTag('a', { href:url }));
49 | if (astOrText) {
50 | if (astOrText.children)
51 | addArray(astOrText.children);
52 | else
53 | lines.push(astOrText);
54 | }
55 |
56 | lines.push(endTag('a')) ;
57 | return lines;
58 | }
59 |
60 | function addImg(url) {
61 | lines.push(startTag('img', { src:url }));
62 | lines.push(endTag('img')) ;
63 | return lines;
64 | }
65 |
66 | switch (ast.name)
67 | {
68 | case "heading":
69 | {
70 | let headingLevel = ast.children[0];
71 | let restOfLine = ast.children[1];
72 | let h = headingLevel.allText.length;
73 | switch (h)
74 | {
75 | case 1: return addTag("h1", restOfLine, true);
76 | case 2: return addTag("h2", restOfLine, true);
77 | case 3: return addTag("h3", restOfLine, true);
78 | case 4: return addTag("h4", restOfLine, true);
79 | case 5: return addTag("h5", restOfLine, true);
80 | case 6: return addTag("h6", restOfLine, true);
81 | default: throw "Heading level must be from 1 to 6"
82 | }
83 | }
84 | case "paragraph":
85 | return addTag("p", ast.children, true);
86 | case "unorderedList":
87 | return addTag("ul", ast.children, true);
88 | case "orderedList":
89 | return addTag("ol", ast.children, true);
90 | case "unorderedListItem":
91 | return addTag("li", ast.children, true);
92 | case "orderedListItem":
93 | return addTag("li", ast.children, true);
94 | case "inlineUrl":
95 | return addLink(ast.allText, ast.allText);
96 | case "bold":
97 | return addTag("b", ast.children);
98 | case "italic":
99 | return addTag("i", ast.children);
100 | case "code":
101 | return addTag("code", ast.children);
102 | case "codeBlock":
103 | return addTag("pre", ast.children);
104 | case "quote":
105 | return addTag("blockquote", ast.children, true);
106 | case "link":
107 | return addLink(ast.children[1].allText, ast.children[0]);
108 | case "image":
109 | return addImg(ast.children[0]);
110 | default:
111 | if (ast.isLeaf)
112 | lines.push(ast.allText);
113 | else
114 | ast.children.forEach(function(c) { mdAstToHtml(c, lines); });
115 | }
116 | return lines;
117 | }
118 |
119 | // Converts Markdown text to HTML
120 | function mdToHtml(input) {
121 | let rule = myna.allRules['markdown.document'];
122 | let ast = myna.parse(rule, input);
123 | return mdAstToHtml(ast, []).join("");
124 | }
125 |
126 | // Export the function for use with Node.js
127 | if (typeof module === "object" && module.exports)
128 | module.exports = mdToHtml;
129 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/myna_mustache_expander.js:
--------------------------------------------------------------------------------
1 | // Exposes a function for expanding mustache and CTemplate style templates.
2 | // http://mustache.github.io/mustache.5.html
3 | //
4 | // Difference with Mustache:
5 | // * Partials are not supported,
6 | // * Changing the delimiter is not supported
7 | // * Variable expansion continues recursively until all variables are expanded.
8 |
9 | 'use strict';
10 |
11 | // Load the Myna module
12 | let myna = require('../myna');
13 |
14 | // Create the template grammar and give it Myna
15 | let grammar = require('../grammars/grammar_mustache')(myna);
16 |
17 | // Escape HTML characters into their special representations
18 | let escapeHtmlChars = require('../tools/myna_escape_html_chars');
19 |
20 | // Get the document parsing rules
21 | let templateRule = grammar.document;
22 |
23 | // Creates a new object containing the properties of the first object and the second object.
24 | // If any value has the same key in both values, the second object overrides the first.
25 | function mergeObjects(a, b) {
26 | var r = { };
27 | for (var k in a)
28 | r[k] = a[k];
29 | for (var k in b)
30 | r[k] = b[k];
31 | return r;
32 | }
33 |
34 | // Given an AST node, a data object, and an optional array of string, converts the nodes
35 | // expanding the reserved characters.
36 | function expandAst(ast, data, lines) {
37 | if (lines == undefined)
38 | lines = [];
39 |
40 | // If there is a child "key" get the value associated with it.
41 | let keyNode = ast.child("key");
42 | let key = keyNode ? keyNode.allText : "";
43 | let val = data ? (key in data ? data[key] : "") : "";
44 |
45 | // Functions are not supported
46 | if (typeof(val) == 'function')
47 | throw new Exception('Functions are not supported');
48 |
49 | switch (ast.rule.name)
50 | {
51 | case "document":
52 | case "sectionContent":
53 | ast.children.forEach(function(c) {
54 | expandAst(c, data, lines); });
55 | return lines;
56 |
57 | case "comment":
58 | return lines;
59 |
60 | case "plainText":
61 | lines.push(ast.allText);
62 | return lines;
63 |
64 | case "section":
65 | let content = ast.child("sectionContent");
66 | if (typeof val === "boolean" || typeof val === "number" || typeof val === "string") {
67 | if (val)
68 | expandAst(content, data, lines);
69 | }
70 | else if (val instanceof Array) {
71 | for (let x of val)
72 | expandAst(content, mergeObjects(data, x), lines);
73 | }
74 | else {
75 | expandAst(content, mergeObjects(data, val), lines);
76 | }
77 | return lines;
78 |
79 | case "invertedSection":
80 | if (!val || ((val instanceof Array) && val.length == 0))
81 | expandAst(ast.child("sectionContent"), data, lines);
82 | return lines;
83 |
84 | case "escapedVar":
85 | if (val)
86 | lines.push(
87 | expand(escapeHtmlChars(String(val)), data));
88 | return lines;
89 |
90 | case "unescapedVar":
91 | if (val)
92 | lines.push(
93 | expand(String(val), data));
94 | return lines;
95 | }
96 |
97 | throw "Unrecognized AST node " + ast.rule.name;
98 | }
99 |
100 | // Expands text containing CTemplate delimiters "{{" using the data object
101 | function expand(template, data) {
102 | if (template.indexOf("{{") >= 0) {
103 | let ast = myna.parsers.mustache(template);
104 | let lines = expandAst(ast, data);
105 | return lines.join("");
106 | }
107 | else {
108 | return template;
109 | }
110 | }
111 |
112 | // Export the function for use with Node.js
113 | if (typeof module === "object" && module.exports)
114 | module.exports = expand;
--------------------------------------------------------------------------------
/node_modules/myna-parser/tools/readme.md:
--------------------------------------------------------------------------------
1 | # Sample Tools
2 |
3 | This folder contains a number of JavaScript tools built using Myna parsers.
4 |
5 | - `myna_arithmetic_evaluator` - Demonstrates how to write an evalator for arithmetic expressions
6 | - `myna_blog_generator` - This is a work in progress for a static markdown to HTML static blog generator
7 | - `myna_escape_html_chars` - This is a sample tool that converts reserved characters to the appropriate HTML entities
8 | - `myna_markdown_to_html` - Converts Git-flavored markdown documents to HTML.
9 | - `myna_mustache_expander` - A simple [mustache](http://mustache.github.io/) clone that expands CTemplate/mustache style templates.
10 |
11 | To see examples of how to use these tools, see the [tests](https://github.com/cdiggins/myna-parser/tree/master/tests).
12 |
13 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": true,
3 | "compilerOptions": {
4 | "target": "ES5",
5 | "module": "commonjs",
6 | "sourceMap": true,
7 | "noUnusedLocals": true
8 | },
9 | "include": [
10 | "*.ts",
11 | "tests/*.ts"
12 | ]
13 | }
--------------------------------------------------------------------------------
/node_modules/myna-parser/website/index.md:
--------------------------------------------------------------------------------
1 | # Myna - Recursive Descent Parsing Library for JavaScript
2 |
3 | Myna is an easy to use recursive-descent parsing library for JavaScript (EcmaScript 5.1) written in TypeScript.
4 |
5 | This web-site was [made using Myna tools](https://github.com/cdiggins/myna-parser/blob/master/tools/myna_build_site.js) to:
6 |
7 | 1. [Parse and convert Markdown into HTML](https://github.com/cdiggins/myna-parser/blob/master/tools/myna_markdown_to_html.js)
8 | 1. [Parse and expand Mustache style templates](https://github.com/cdiggins/myna-parser/blob/master/tools/myna_mustache_expander.js)
9 | 1. [Convert HTML characters into escape codes](https://github.com/cdiggins/myna-parser/blob/master/tools/myna_escape_html_chars.js)
10 |
11 | Myna features:
12 |
13 | * Myna is a JavaScript library not a code generator
14 | * Parsing automatically creates an abstract syntax tree (AST)
15 | * No separate tokenization phase
16 | * [Competitive performance](https://sap.github.io/chevrotain/performance/) with other libraries
17 | * Many [sample grammars](https://github.com/cdiggins/myna-parser/tree/master/grammars) and [example tools](https://github.com/cdiggins/myna-parser/tree/master/tools).
18 | * Functions for generating a PEG representation of the grammar, or the AST schema
19 |
20 | ## Using Myna
21 |
22 | Below is an example of how to use Myna from Node.JS in a single self-contained example:
23 |
24 | ```
25 | // Load the Myna module and all grammars
26 | var m = require('myna-parser');
27 |
28 | // Load the JSON grammar
29 | require('myna-parser/grammars/grammar_json')(m);
30 |
31 | // Get the JSON parser
32 | var parser = m.parsers.json;
33 |
34 | // Define some input
35 | var input = '{ "integer":42, "greeting":"hello", "truth":false, "array":[1,2,3] }';
36 |
37 | // Output the generated AST
38 | console.log(parser(input).toString());
39 | ```
40 |
41 | ## Writing a Grammar
42 |
43 | The following example shows how to use Myna with a custom Grammar:
44 |
45 | ```
46 | // Reference the Myna module
47 | var m = require('myna-parser');
48 |
49 | // Construct a grammar object
50 | var g = new function()
51 | {
52 | this.textdata = m.notChar('\n\r"' + delimiter);
53 | this.quoted = m.doubleQuoted(m.notChar('"').or('""').zeroOrMore);
54 | this.field = this.textdata.or(this.quoted).zeroOrMore.ast;
55 | this.record = this.field.delimited(delimiter).ast;
56 | this.file = this.record.delimited(m.newLine).ast;
57 | }
58 |
59 | // Let consumers of the Myna module access
60 | m.registerGrammar("csv", g, g.file);
61 |
62 | // Get the parser
63 | var parser = m.parsers.csv;
64 | var input = 'a,1,"hello"\nb,2,"goodbye"';
65 | console.log(parser(input).toString());
66 | ```
67 |
68 | Only rules that are defined with the `.ast` property will create nodes in the output parse tree. This saves the work of having to convert from a Concrete Syntax Tree (CST) to an Abstract Syntax Tree (AST).
69 |
--------------------------------------------------------------------------------
/node_modules/myna-parser/website/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | Myna Parsing Library
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
44 |
45 |
46 |
47 |
48 |
49 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
77 |
78 | {{{content}}}
79 |
80 |
81 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "heron-lang",
3 | "version": "0.3.0",
4 | "description": "A cross-platform programming language inspired by JavaScript that emphasizes simplicity, safety, and code reuse.",
5 | "main": "src/heron.js",
6 | "homepage": "https://github.com/cdiggins/heron-language",
7 | "bugs": "https://github.com/cdiggins/heron-language/issues",
8 | "license": "MIT",
9 | "author": {
10 | "name": "Christopher Diggins",
11 | "email": "cdiggins@gmail.com"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "https://github.com/cdiggins/heron-language.git"
16 | },
17 | "scripts": {
18 | "build": "tsc",
19 | "watch": "tsc --watch",
20 | "lint": "tslint --project ."
21 | },
22 | "dependencies": {
23 | "myna-parser": "^2.5.1"
24 | },
25 | "devDependencies": {
26 | "tslint": "^5.9.1"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/source-browser/styles.css:
--------------------------------------------------------------------------------
1 | .code {
2 | background-color: #202020;
3 | white-space: pre;
4 | font-family: 'Inconsolata', 'Courier New', monospace;
5 | font-size: 14;
6 | color: white;
7 | padding: 10px;
8 | }
9 | .string {
10 | color: rosybrown;
11 | }
12 | .number {
13 | color: #f099bb;
14 | }
15 | .bool {
16 | color: #f099bb;
17 | }
18 | .fullComment, .lineComment {
19 | color: royalblue;
20 | font-style: italic;
21 | }
22 | .varName {
23 | color: goldenrod;
24 | }
25 | /*
26 | .langVer, .moduleName, .urn {
27 | color: darkgreen;
28 | }
29 | */
30 | .keyword {
31 | color: #8aabfd;
32 | }
33 | .operator {
34 | color: #9497a2;
35 | }
36 | .funcName {
37 | color: white;
38 | }
39 | .funcParamName {
40 | color: #f2be3b;
41 | }
42 | .varNameDecl {
43 | color: #f2be3b;
44 | }
45 | .functionDef {
46 | position: relative;
47 | }
48 | .functionType {
49 | color: white;
50 | background-color: #333;
51 | opacity: 0.8;
52 | display: none;
53 | position: absolute;
54 | font-size: 0.8em;
55 | top: -1em;
56 | }
57 | .hideTypes .functionDef:hover > .functionType {
58 | display: inline-block;
59 | position: absolute;
60 | }
61 | .showTypes .functionType {
62 | display: inline-block;
63 | position: absolute;
64 | }
65 | .gitHubLink {
66 | position: fixed;
67 | left: 50%;
68 | top: 10px;
69 | transform: translateX(-50%);
70 | }
71 | .gitHubLink a {
72 | color: pink;
73 | }
74 | .button {
75 | position: fixed;
76 | right: 20;
77 | background-color: steelblue;
78 | border: none;
79 | color: white;
80 | text-align: center;
81 | text-decoration: none;
82 | padding: 15px;
83 | opacity: 0.8;
84 | }
85 | .button > a {
86 | color: black;
87 | }
--------------------------------------------------------------------------------
/src/code-builder.ts:
--------------------------------------------------------------------------------
1 | //=====================================
2 | // Helper class for constructing pretty printerd code
3 | // this is passed as a "state" object to visitors
4 |
5 | function count(s: string, sub: string) {
6 | return s.split(sub).length - 1;
7 | }
8 |
9 | export class CodeBuilder
10 | {
11 | lines: string[] = [];
12 | indent: number = 0;
13 | get indentString() {
14 | let r = '';
15 | for (let i=0; i < this.indent; ++i)
16 | r += ' ';
17 | return r;
18 | }
19 | pushLine(s: string = '') {
20 | this.push(s + '\n');
21 | this.lines.push(this.indentString);
22 | }
23 | push(s: string) {
24 | let indentDelta = count(s, '{') - count(s, '}');
25 | indentDelta += count(s, '(') - count(s, ')');
26 | this.indent += indentDelta;
27 | if (indentDelta < 0) {
28 | if (this.lines.length > 0) {
29 | const lastLine = this.lines[this.lines.length-1].trim();
30 | if (lastLine.length === 0) {
31 | this.lines.pop();
32 | this.lines.push(this.indentString);
33 | }
34 | }
35 | }
36 | this.lines.push(s);
37 | }
38 | toString(): string {
39 | return this.lines.join('');
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/heron-compiler.ts:
--------------------------------------------------------------------------------
1 | import {HeronAstNode } from "./heron-ast-rewrite";
2 | import { parseHeron, heronGrammar } from "./heron-parser";
3 | import { Package } from "./heron-package";
4 | import { computeFuncType, computeVarType } from "./heron-types";
5 |
6 | const g = heronGrammar;
7 |
8 | // Get some details about the language implementation environment
9 | declare var require: any;
10 | const fs = require('fs');
11 | const path = require('path');
12 |
13 | // TODO: use or throw out.
14 | //const nodePackage = JSON.parse(fs.readFileSync('package.json','utf8'));
15 | //const ver = nodePackage.version;
16 | //const flavor = 'std';
17 |
18 | const ext = '.heron';
19 |
20 | // Module resolution
21 | export const moduleFolder = path.join('.', 'input');
22 | export const outputFolder = path.join('.', 'output');
23 | export const intrinsicModules = ['intrinsics'];
24 | export const modules: HeronAstNode[] = [];
25 |
26 | //================================================================
27 | // Main functions
28 |
29 | export function createPackage(moduleNames: string[]): Package {
30 | const pkg = new Package();
31 |
32 | // Load the intrinsic (built-in) modules
33 | for (const name of intrinsicModules)
34 | addModuleToPackage(name, true, pkg);
35 |
36 | // Load the specified modules (any order)
37 | for (const name of moduleNames)
38 | addModuleToPackage(name, false, pkg);
39 |
40 | // The package is doing the heavy lifting
41 | pkg.processModules();
42 |
43 | // Compute types
44 | for (const v of pkg.allVarDefs) {
45 | computeVarType(v);
46 | }
47 |
48 | // Compute types
49 | for (const f of pkg.allFuncDefs) {
50 | computeFuncType(f);
51 | }
52 |
53 | return pkg;
54 | }
55 |
56 | export function addModuleToPackage(name: string, intrinsic: boolean, pkg: Package) {
57 | const modulePath = moduleNameToPath(name);
58 | const ast = parseFile(modulePath);
59 | if (ast)
60 | pkg.addFile(ast, intrinsic, modulePath);
61 | }
62 |
63 | export function moduleNameToPath(f: string): string {
64 | return path.join(moduleFolder, f + ext);
65 | }
66 |
67 | export function parseModule(moduleName: string): HeronAstNode|null {
68 | const modulePath = moduleNameToPath(moduleName);
69 | return parseFile(modulePath);
70 | }
71 |
72 | export function parseFile(f: string): HeronAstNode|null {
73 | try
74 | {
75 | const code = fs.readFileSync(f, 'utf-8');
76 | const ast = parseHeron(code, g.file);
77 | return ast;
78 | }
79 | catch (e)
80 | {
81 | console.log("An error occurred while parsing " + f);
82 | console.log(e.message);
83 | return null;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/heron-name-analysis.ts:
--------------------------------------------------------------------------------
1 | import { HeronAstNode } from "./heron-ast-rewrite";
2 | import { Def } from "./heron-defs";
3 | import { Ref } from "./heron-refs";
4 | import { Package } from "./heron-package";
5 |
6 | /**
7 | * Scope used for the purpose of name analysis creating ref/def chains.
8 | * A scope contains unique name declarations. Scopes are arranaged in a tree.
9 | */
10 | export class Scope
11 | {
12 | id: number = 0;
13 | refs: Ref[] = [];
14 | defs: Def[] = [];
15 | children: Scope[] = [];
16 | parent: Scope|null = null;
17 |
18 | constructor(public readonly node: HeronAstNode) {
19 | if (node)
20 | node['scope'] = this;
21 | }
22 |
23 | // We can find multiple defs at the same level (e.g. functions)
24 | findDefs(name: string): Def[] {
25 | let r = [];
26 | for (var d of this.defs)
27 | if (d.name === name)
28 | r.push(d);
29 | if (r.length > 0)
30 | return r;
31 | return this.parent
32 | ? this.parent.findDefs(name)
33 | : [];
34 | }
35 |
36 | allDefs(r: Def[] = []): Def[] {
37 | r.push(...this.defs);
38 | this.children.forEach(c => c.allDefs(r));
39 | return r;
40 | }
41 |
42 | allRefs(r: Ref[] = []): Ref[] {
43 | r.push(...this.refs);
44 | this.children.forEach(c => c.allRefs(r));
45 | return r;
46 | }
47 |
48 | allScopes(r: Scope[] = []): Scope[] {
49 | r.push(this);
50 | this.children.forEach(c => c.allScopes(r));
51 | return r;
52 | }
53 |
54 | toString(): string {
55 | if (!this.node)
56 | return "__global__";
57 | return nodeId(this.node);
58 | }
59 | }
60 |
61 | export function nodeId(node: HeronAstNode): string {
62 | return node ? node.name + '_' + node['id'] : '';
63 | }
64 |
65 | export const scopeType = ['funcDef', 'instrinsicDef', 'module', 'varExpr', 'compoundStatement'];
66 |
67 |
68 | // Used for visiting nodes in the Heron node looking for name defintions, usages, and scopes.
69 | export class NameAnalyzer
70 | {
71 | // Visitor helper functions
72 | visitNode(node: HeronAstNode, state: Package) {
73 | if (node.def)
74 | state.addDef(node.def);
75 | const fnName = 'visit_' + node.name;
76 | if (fnName in this)
77 | ((this as any)[fnName])(node, state);
78 | else
79 | this.visitChildren(node, state);
80 | }
81 | visitChildren(node: HeronAstNode, state: Package) {
82 | for (let child of node.children)
83 | this.visitNode(child, state);
84 | }
85 |
86 | // Particular node visitors
87 | visit_compoundStatement(node: HeronAstNode, state: Package) {
88 | state.pushScope(node);
89 | this.visitChildren(node, state);
90 | state.popScope();
91 | }
92 | visit_forLoop(node: HeronAstNode, state: Package) {
93 | state.pushScope(node);
94 | this.visitChildren(node, state);
95 | state.popScope();
96 | }
97 | visit_funcDef(node: HeronAstNode, state: Package) {
98 | state.pushScope(node);
99 | this.visitChildren(node, state);
100 | state.popScope();
101 | }
102 | visit_intrinsicDef(node: HeronAstNode, state: Package) {
103 | state.pushScope(node);
104 | this.visitChildren(node, state);
105 | state.popScope();
106 | }
107 | visit_typeName(node: HeronAstNode, state: Package) {
108 | state.addRef(node.allText, node);
109 | }
110 | visit_lambdaBody(node: HeronAstNode, state: Package) {
111 | state.pushScope(node);
112 | this.visitChildren(node, state);
113 | state.popScope();
114 | }
115 | visit_lambdaExpr(node: HeronAstNode, state: Package) {
116 | state.pushScope(node);
117 | this.visitChildren(node, state);
118 | state.popScope();
119 | }
120 | visit_varExpr(node: HeronAstNode, state: Package) {
121 | state.pushScope(node);
122 | this.visitChildren(node, state);
123 | state.popScope();
124 | }
125 | visit_varName(node: HeronAstNode, state: Package) {
126 | state.addRef(node.allText, node);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/heron-normal-form.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Heron Normal Form (HNF)
3 | *
4 | * An intermediate compiler representation for optimization, transformation, code-generation,
5 | * analysis, and evaluation.
6 | *
7 | * Expression ::=
8 | * | Non-function (Bool, Int, Float, String, etc.)
9 | * | Function
10 | * | Function Set (Array of possible functions)
11 | * | Closure (Function + Closure record)
12 | * | Free variable (reference to entry in closure record)
13 | * | Parameter (bound variable)
14 | * | Function call (Function + Array of Expressions)
15 | * | Condition ( Expression ? Expression : Expression )
16 | *
17 | * Other intermediate forms to look at:
18 | * * https://en.wikipedia.org/wiki/A-normal_form.
19 | * * https://en.wikipedia.org/wiki/Static_single_assignment_form
20 | * * https://en.wikipedia.org/wiki/Continuation-passing_style
21 | */
22 |
23 |
--------------------------------------------------------------------------------
/src/heron-refs.ts:
--------------------------------------------------------------------------------
1 | // This module provides support for dealing with reference.
2 | // A reference is a name (identifier) that refers to a definition.
3 | // There can be more than one definitions (for examples when dealing with overloaded functions)
4 |
5 | import { Def, VarDef, ForLoopVarDef, TypeDef, TypeParamDef, FuncDef, FuncParamDef } from "./heron-defs";
6 | import { throwError, HeronAstNode } from "./heron-ast-rewrite";
7 | import { Scope } from "./heron-name-analysis";
8 |
9 | // A reference to one or more definitions.
10 | export class Ref
11 | {
12 | constructor(
13 | public readonly node: HeronAstNode,
14 | public readonly name: string,
15 | public readonly scope: Scope,
16 | public readonly defs: Def[])
17 | {
18 | node.ref = this;
19 | if (defs.length === 0)
20 | throwError(node, 'No definition found for ' + name);
21 | }
22 |
23 | toString(): string {
24 | return this.name + '_' + this.node['id'] + ':' + this.node.name + '[' + this.defs.join(', ') + ']';
25 | }
26 | }
27 |
28 | export class VarRef extends Ref {
29 | constructor(
30 | public readonly node: HeronAstNode,
31 | public readonly name: string,
32 | public readonly scope: Scope,
33 | public readonly def: VarDef)
34 | {
35 | super(node, name, scope, [def]);
36 | }
37 | }
38 |
39 | export class ForLoopVarRef extends Ref {
40 | constructor(
41 | public readonly node: HeronAstNode,
42 | public readonly name: string,
43 | public readonly scope: Scope,
44 | public readonly def: ForLoopVarDef)
45 | {
46 | super(node, name, scope, [def]);
47 | }
48 | }
49 |
50 | export class FuncParamRef extends Ref {
51 | constructor(
52 | public readonly node: HeronAstNode,
53 | public readonly name: string,
54 | public readonly scope: Scope,
55 | public readonly def: FuncParamDef)
56 | {
57 | super(node, name, scope, [def]);
58 | }
59 | }
60 |
61 | export class TypeRef extends Ref {
62 | constructor(
63 | public readonly node: HeronAstNode,
64 | public readonly name: string,
65 | public readonly scope: Scope,
66 | public readonly def: TypeDef)
67 | {
68 | super(node, name, scope, [def]);
69 | }
70 | }
71 |
72 | export class TypeParamRef extends Ref {
73 | constructor(
74 | public readonly node: HeronAstNode,
75 | public readonly name: string,
76 | public readonly scope: Scope,
77 | public readonly def: TypeParamDef)
78 | {
79 | super(node, name, scope, [def]);
80 | }
81 | }
82 |
83 | export class FuncRef extends Ref {
84 | constructor(
85 | public readonly node: HeronAstNode,
86 | public readonly name: string,
87 | public readonly scope: Scope,
88 | public readonly defs: FuncDef[])
89 | {
90 | super(node, name, scope, defs);
91 | }
92 | }
--------------------------------------------------------------------------------
/src/js-intrinsics.js:
--------------------------------------------------------------------------------
1 | function op_dot_dot(from, to) { const r=[]; for (let i=from; i < to; ++i) r.push(i); return r; }
2 | function int(x) { return Math.round(x); }
3 | function float(x) { return x; }
4 | function float2(u, v) { return ({ u: u, v: v }); }
5 | function float3(x, y, z) { return ({ x: x, y: y, z: z }); }
6 | function float4(x, y, z, w) { return ({ x: x, y: y, z: z, w: w }); }
7 | function u(v) { return v.u; }
8 | function v(v) { return v.v; }
9 | function x(v) { return v.x; }
10 | function y(v) { return v.y; }
11 | function z(v) { return v.z; }
12 | function w(v) { return v.w; }
13 | function xyz(v) { return float3(v.x, v.y, v.z); }
14 | function abs(x) { return Math.abs(x); }
15 | function acos(x) { return Math.acos(x); }
16 | function asin(x) { return Math.asin(x); }
17 | function atan(x) { return Math.atan(x); }
18 | function atan2(y, x) { return Math.atan2(y, x); }
19 | function ceil(x) { return Math.ceil(x); }
20 | function cos(x) { return Math.cos(x); }
21 | function exp(x) { return Math.exp(x); }
22 | function floor(x) { return Math.floor(x); }
23 | function log(x) { return Math.log(x); }
24 | function pow(x, y) { return Math.pow(x, y); }
25 | function round(x) { return Math.round(x); }
26 | function sin(x) { return Math.sin(x); }
27 | function sqrt(x) { return Math.sqrt(x); }
28 | function tan(x) { return Math.tan(x); }
29 | function clamp(x, min, max) { return x < min ? min : x > max ? max : x; };
30 | function sign(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
31 | function op_add(x, y) { return x + y; };
32 | function op_sub(x, y) { return x - y; };
33 | function op_mul(x, y) { return x * y; };
34 | function op_div(x, y) { return x / y; };
35 | function op_mod(x, y) { return x % y; };
36 | function op_gt(x, y) { return x > y; };
37 | function op_gt_eq(x, y) { return x >= y; };
38 | function op_lt(x, y) { return x < y; };
39 | function op_lt_eq(x, y) { return x <= y; };
40 | function op_not_eq(x, y) { return x !== y; };
41 | function op_eq_eq(x, y) { return x === y; };
42 | function op_amp_amp(x, y) { return x && y; };
43 | function op_bar_bar(x, y) { return x || y; };
44 | function op_hat_hat(x, y) { return !!(x ^ y); };
45 | function op_not(x) { return !x; };
46 | function op_negate(x) { return -x; };
47 | function count(xs) { return xs.length; };
48 | function at(xs, i) { return xs[i]; };
49 | function array(count, at) { const r=[]; for (let i=0; i < count; ++i) r.push(at(i)); return r; }
50 | function mutable(xs) { return xs; }
51 | function immutable(xs) { return xs; }
52 | function push(xs, x) { return (xs.push(x), xs); };
53 | function pushMany(xs, ys) { return (xs.push(...ys), xs); };
54 | function set(xs, i, x) { return (xs[i] = x, xs); };
55 | function print(x) { return console.log(x); }
56 | function assert(condition) { if (!condition) throw new Error("assertion failed"); };
57 | function mesh(vertexBuffer, indexBuffer, uvBuffer, colorBuffer, normalBuffer) { return ({ vertexBuffer, indexBuffer, uvBuffer, colorBuffer, normalBuffer }); };
58 | function vertexBuffer(mesh) { return mesh.vertexBuffer; };
59 | function indexBuffer(mesh) { return mesh.indexBuffer; };
60 | function colorBuffer(mesh) { return mesh.colorBuffer; };
61 | function uvBuffer(mesh) { return mesh.uvBuffer; };
62 | function normalBuffer(mesh) { return mesh.normalBuffer; }
--------------------------------------------------------------------------------
/src/type-parser.ts:
--------------------------------------------------------------------------------
1 | import { Type, typeConstant, typeVariable, polyType } from "./type-system";
2 | import { Myna as m } from "myna-parser"
3 |
4 | // Defines syntax parsers for type expression, the lambda calculus, and Cat
5 | function registerGrammars()
6 | {
7 | // A simple grammar for parsing type expressions
8 | class TypeGrammar
9 | {
10 | typeExprRec = m.delay(() => this.typeExpr);
11 | typeList = m.guardedSeq('(', m.ws, this.typeExprRec.ws.zeroOrMore, ')').ast;
12 | typeVar = m.guardedSeq("'", m.identifier).ast;
13 | typeConstant = m.identifier.or(m.digits).or("->").or("*").or("[]").ast;
14 | typeExpr = m.choice(this.typeList, this.typeVar, this.typeConstant).ast;
15 | }
16 | const typeGrammar = new TypeGrammar();
17 | m.registerGrammar('type', typeGrammar, typeGrammar.typeExpr);
18 |
19 | }
20 |
21 | registerGrammars();
22 |
23 | export const typeParser = m.parsers['type'];
24 |
25 | export function parseType(input:string) : Type|null {
26 | var ast = typeParser(input);
27 | if (ast.end != input.length)
28 | throw new Error("Only part of input was consumed");
29 | return astToType(ast);
30 | }
31 |
32 | function astToType(ast: any) : Type|null {
33 | if (!ast)
34 | return null;
35 | switch (ast.name)
36 | {
37 | case "typeVar":
38 | return typeVariable(ast.allText.substr(1));
39 | case "typeConstant":
40 | return typeConstant(ast.allText);
41 | case "typeList":
42 | return polyType(ast.children.map(astToType));
43 | case "typeExpr":
44 | if (ast.children.length != 1)
45 | throw new Error("Expected only one child of node, not " + ast.children.length);
46 | return astToType(ast.children[0]);
47 | default:
48 | throw new Error("Unrecognized type expression: " + ast.name);
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/src/utils.ts:
--------------------------------------------------------------------------------
1 | export type LabelTypes = 'chooseFunc'|'funcType';
2 |
3 | export function trace(label: LabelTypes, message: string) {
4 | //console.log(message);
5 | }
--------------------------------------------------------------------------------
/tools/gen-spec.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | const Myna = require("myna-parser");
4 | const g = require('../build/heron-parser').heronGrammar;
5 | const fs = require('fs');
6 |
7 | const m = Myna.Myna;
8 | const pkg = JSON.parse(fs.readFileSync('./package.json', "utf8"));
9 | const version = pkg.version;
10 | const schema = m.astSchemaToString('heron');
11 | const grammar = m.grammarToString('heron');
12 |
13 | const contents =
14 | [
15 | '# Heron Specification ' + version,
16 | '',
17 | '## AST Schema',
18 | '',
19 | 'This is the schema of the abstract syntax tree (AST) created when',
20 | 'when parsing Heron with the [Myna parser](https://github.com/cdiggins/myna-parser)',
21 | 'prior to any transformations',
22 | '',
23 | '```',
24 | schema,
25 | '```',
26 | '',
27 | '## PEG Grammar',
28 | '',
29 | 'This is the full grammar for Heron in PEG form. ',
30 | 'Alternatively you can view the [source code for the parser](https://github.com/cdiggins/heron-language/blob/master/src/heron-parser.ts)',
31 | '',
32 | '```',
33 | grammar,
34 | '```'
35 | ].join('\n');
36 |
37 | fs.writeFileSync('./spec.md', contents);
38 |
39 | process.exit();
40 |
--------------------------------------------------------------------------------
/tools/gen-visitor.js:
--------------------------------------------------------------------------------
1 | // Variable usage
2 | // - Declaration
3 | // - Usage
4 | // - function calls
5 |
6 | const m = require("myna-parser");
7 | const g = require('../build/heron-parser').heronGrammar;
8 | const grammarName = "heron";
9 |
10 | function createAstVisitorFunction(rule, lines) {
11 | lines.push(" visit_" + rule.name + "(ast, state) {");
12 | lines.push(" // " + rule.astRuleDefn());
13 | lines.push(" this.visitChildren(ast, state);");
14 | lines.push(" }")
15 | }
16 |
17 | function createCaseStatement(rule, lines) {
18 | lines.push(" case '" + rule.name + "': ");
19 | lines.push(" // " + rule.astRuleDefn());
20 | lines.push(" ast['property'] = somevalue;");
21 | lines.push(" break;")
22 | }
23 |
24 | function createAstVisitor() {
25 | var lines = [
26 | "class " + grammarName + "Visitor",
27 | "{",
28 | " visitNode(ast, state) {",
29 | " const fnName = 'visit_' + ast.name;",
30 | " if (fnName in this)",
31 | " this[fnName](ast, state);",
32 | " else",
33 | " this.visitChildren(ast, state);",
34 | " }",
35 | " visitChildren(ast, state) {",
36 | " for (let child of ast.children)",
37 | " this.visitNode(child, state);",
38 | " }"
39 | ];
40 | var rules = m.grammarAstRules(grammarName);
41 | for (var r of rules)
42 | createAstVisitorFunction(r, lines);
43 | lines.push("}");
44 |
45 | return lines.join("\n");
46 | }
47 |
48 | function createAstSwitch() {
49 | var lines = [
50 | "switch (ast.name) {"
51 | ];
52 | var rules = m.grammarAstRules(grammarName);
53 | for (var r of rules)
54 | createCaseStatement(r, lines);
55 | lines.push(' default:');
56 | lines.push("}");
57 |
58 | return lines.join("\n");
59 | }
60 |
61 | //const output = createAstVisitor();
62 | const output = createAstSwitch();
63 | console.log(output);
64 |
65 | process.exit();
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": true,
3 | "compilerOptions": {
4 | "target": "ES5",
5 | "module": "commonjs",
6 | "sourceMap": true,
7 | "outDir": "build",
8 | "noUnusedLocals": true,
9 | "strict": false,
10 | //"noUnusedParameters": true,
11 | },
12 | "include": [
13 | "src/*.ts"
14 | ],
15 | "exclude": [
16 | "node_modules"
17 | ]
18 | }
--------------------------------------------------------------------------------