Erster Docker-Stand
This commit is contained in:
202
_node_modules/@chevrotain/cst-dts-gen/LICENSE.txt
generated
Normal file
202
_node_modules/@chevrotain/cst-dts-gen/LICENSE.txt
generated
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
2
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.d.ts
generated
vendored
Normal file
2
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Rule, GenerateDtsOptions } from "@chevrotain/types";
|
||||
export declare function generateCstDts(productions: Record<string, Rule>, options?: GenerateDtsOptions): string;
|
||||
27
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.js
generated
Normal file
27
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.js
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateCstDts = void 0;
|
||||
var model_1 = require("./model");
|
||||
var generate_1 = require("./generate");
|
||||
var defaultOptions = {
|
||||
includeVisitorInterface: true,
|
||||
visitorInterfaceName: "ICstNodeVisitor"
|
||||
};
|
||||
function generateCstDts(productions, options) {
|
||||
var effectiveOptions = __assign(__assign({}, defaultOptions), options);
|
||||
var model = (0, model_1.buildModel)(productions);
|
||||
return (0, generate_1.genDts)(model, effectiveOptions);
|
||||
}
|
||||
exports.generateCstDts = generateCstDts;
|
||||
//# sourceMappingURL=api.js.map
|
||||
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.js.map
generated
Normal file
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/api.js.map
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,iCAAoC;AACpC,uCAAmC;AAEnC,IAAM,cAAc,GAAiC;IACnD,uBAAuB,EAAE,IAAI;IAC7B,oBAAoB,EAAE,iBAAiB;CACxC,CAAA;AAED,SAAgB,cAAc,CAC5B,WAAiC,EACjC,OAA4B;IAE5B,IAAM,gBAAgB,yBACjB,cAAc,GACd,OAAO,CACX,CAAA;IAED,IAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAA;IAErC,OAAO,IAAA,iBAAM,EAAC,KAAK,EAAE,gBAAgB,CAAC,CAAA;AACxC,CAAC;AAZD,wCAYC"}
|
||||
3
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.d.ts
generated
vendored
Normal file
3
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { GenerateDtsOptions } from "@chevrotain/types";
|
||||
import { CstNodeTypeDefinition } from "./model";
|
||||
export declare function genDts(model: CstNodeTypeDefinition[], options: Required<GenerateDtsOptions>): string;
|
||||
70
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.js
generated
Normal file
70
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.js
generated
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.genDts = void 0;
|
||||
var flatten_1 = __importDefault(require("lodash/flatten"));
|
||||
var isArray_1 = __importDefault(require("lodash/isArray"));
|
||||
var map_1 = __importDefault(require("lodash/map"));
|
||||
var reduce_1 = __importDefault(require("lodash/reduce"));
|
||||
var uniq_1 = __importDefault(require("lodash/uniq"));
|
||||
var upperFirst_1 = __importDefault(require("lodash/upperFirst"));
|
||||
function genDts(model, options) {
|
||||
var contentParts = [];
|
||||
contentParts = contentParts.concat("import type { CstNode, ICstVisitor, IToken } from \"chevrotain\";");
|
||||
contentParts = contentParts.concat((0, flatten_1.default)((0, map_1.default)(model, function (node) { return genCstNodeTypes(node); })));
|
||||
if (options.includeVisitorInterface) {
|
||||
contentParts = contentParts.concat(genVisitor(options.visitorInterfaceName, model));
|
||||
}
|
||||
return contentParts.join("\n\n") + "\n";
|
||||
}
|
||||
exports.genDts = genDts;
|
||||
function genCstNodeTypes(node) {
|
||||
var nodeCstInterface = genNodeInterface(node);
|
||||
var nodeChildrenInterface = genNodeChildrenType(node);
|
||||
return [nodeCstInterface, nodeChildrenInterface];
|
||||
}
|
||||
function genNodeInterface(node) {
|
||||
var nodeInterfaceName = getNodeInterfaceName(node.name);
|
||||
var childrenTypeName = getNodeChildrenTypeName(node.name);
|
||||
return "export interface ".concat(nodeInterfaceName, " extends CstNode {\n name: \"").concat(node.name, "\";\n children: ").concat(childrenTypeName, ";\n}");
|
||||
}
|
||||
function genNodeChildrenType(node) {
|
||||
var typeName = getNodeChildrenTypeName(node.name);
|
||||
return "export type ".concat(typeName, " = {\n ").concat((0, map_1.default)(node.properties, function (property) { return genChildProperty(property); }).join("\n "), "\n};");
|
||||
}
|
||||
function genChildProperty(prop) {
|
||||
var typeName = buildTypeString(prop.type);
|
||||
return "".concat(prop.name).concat(prop.optional ? "?" : "", ": ").concat(typeName, "[];");
|
||||
}
|
||||
function genVisitor(name, nodes) {
|
||||
return "export interface ".concat(name, "<IN, OUT> extends ICstVisitor<IN, OUT> {\n ").concat((0, map_1.default)(nodes, function (node) { return genVisitorFunction(node); }).join("\n "), "\n}");
|
||||
}
|
||||
function genVisitorFunction(node) {
|
||||
var childrenTypeName = getNodeChildrenTypeName(node.name);
|
||||
return "".concat(node.name, "(children: ").concat(childrenTypeName, ", param?: IN): OUT;");
|
||||
}
|
||||
function buildTypeString(type) {
|
||||
if ((0, isArray_1.default)(type)) {
|
||||
var typeNames = (0, uniq_1.default)((0, map_1.default)(type, function (t) { return getTypeString(t); }));
|
||||
var typeString = (0, reduce_1.default)(typeNames, function (sum, t) { return sum + " | " + t; });
|
||||
return "(" + typeString + ")";
|
||||
}
|
||||
else {
|
||||
return getTypeString(type);
|
||||
}
|
||||
}
|
||||
function getTypeString(type) {
|
||||
if (type.kind === "token") {
|
||||
return "IToken";
|
||||
}
|
||||
return getNodeInterfaceName(type.name);
|
||||
}
|
||||
function getNodeInterfaceName(ruleName) {
|
||||
return (0, upperFirst_1.default)(ruleName) + "CstNode";
|
||||
}
|
||||
function getNodeChildrenTypeName(ruleName) {
|
||||
return (0, upperFirst_1.default)(ruleName) + "CstChildren";
|
||||
}
|
||||
//# sourceMappingURL=generate.js.map
|
||||
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.js.map
generated
Normal file
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/generate.js.map
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/generate.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAoC;AACpC,2DAAoC;AACpC,mDAA4B;AAC5B,yDAAkC;AAClC,qDAA8B;AAC9B,iEAA0C;AAU1C,SAAgB,MAAM,CACpB,KAA8B,EAC9B,OAAqC;IAErC,IAAI,YAAY,GAAa,EAAE,CAAA;IAE/B,YAAY,GAAG,YAAY,CAAC,MAAM,CAChC,mEAAiE,CAClE,CAAA;IAED,YAAY,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AChB;IACD,OAAO,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,OAAO,IAAA,oBAAU,EAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;AACzC,CAAC;AAED,SAAS,uBAAuB,CAAC,QAAgB;IAC/C,OAAO,IAAA,oBAAU,EAAC,QAAQ,CAAC,GAAG,aAAa,CAAA;AAC7C,CAAC"}
|
||||
19
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.d.ts
generated
vendored
Normal file
19
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { Rule } from "@chevrotain/types";
|
||||
export declare function buildModel(productions: Record<string, Rule>): CstNodeTypeDefinition[];
|
||||
export type CstNodeTypeDefinition = {
|
||||
name: string;
|
||||
properties: PropertyTypeDefinition[];
|
||||
};
|
||||
export type PropertyTypeDefinition = {
|
||||
name: string;
|
||||
type: PropertyArrayType;
|
||||
optional: boolean;
|
||||
};
|
||||
export type PropertyArrayType = TokenArrayType | RuleArrayType | (TokenArrayType | RuleArrayType)[];
|
||||
export type TokenArrayType = {
|
||||
kind: "token";
|
||||
};
|
||||
export type RuleArrayType = {
|
||||
kind: "rule";
|
||||
name: string;
|
||||
};
|
||||
129
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.js
generated
Normal file
129
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.js
generated
Normal file
@@ -0,0 +1,129 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildModel = void 0;
|
||||
var gast_1 = require("@chevrotain/gast");
|
||||
var map_1 = __importDefault(require("lodash/map"));
|
||||
var flatten_1 = __importDefault(require("lodash/flatten"));
|
||||
var values_1 = __importDefault(require("lodash/values"));
|
||||
var some_1 = __importDefault(require("lodash/some"));
|
||||
var groupBy_1 = __importDefault(require("lodash/groupBy"));
|
||||
var assign_1 = __importDefault(require("lodash/assign"));
|
||||
function buildModel(productions) {
|
||||
var generator = new CstNodeDefinitionGenerator();
|
||||
var allRules = (0, values_1.default)(productions);
|
||||
return (0, map_1.default)(allRules, function (rule) { return generator.visitRule(rule); });
|
||||
}
|
||||
exports.buildModel = buildModel;
|
||||
var CstNodeDefinitionGenerator = /** @class */ (function (_super) {
|
||||
__extends(CstNodeDefinitionGenerator, _super);
|
||||
function CstNodeDefinitionGenerator() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
CstNodeDefinitionGenerator.prototype.visitRule = function (node) {
|
||||
var rawElements = this.visitEach(node.definition);
|
||||
var grouped = (0, groupBy_1.default)(rawElements, function (el) { return el.propertyName; });
|
||||
var properties = (0, map_1.default)(grouped, function (group, propertyName) {
|
||||
var allNullable = !(0, some_1.default)(group, function (el) { return !el.canBeNull; });
|
||||
// In an alternation with a label a property name can have
|
||||
// multiple types.
|
||||
var propertyType = group[0].type;
|
||||
if (group.length > 1) {
|
||||
propertyType = (0, map_1.default)(group, function (g) { return g.type; });
|
||||
}
|
||||
return {
|
||||
name: propertyName,
|
||||
type: propertyType,
|
||||
optional: allNullable
|
||||
};
|
||||
});
|
||||
return {
|
||||
name: node.name,
|
||||
properties: properties
|
||||
};
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitAlternative = function (node) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true });
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitOption = function (node) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true });
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitRepetition = function (node) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true });
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitRepetitionMandatory = function (node) {
|
||||
return this.visitEach(node.definition);
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitRepetitionMandatoryWithSeparator = function (node) {
|
||||
return this.visitEach(node.definition).concat({
|
||||
propertyName: node.separator.name,
|
||||
canBeNull: true,
|
||||
type: getType(node.separator)
|
||||
});
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitRepetitionWithSeparator = function (node) {
|
||||
return this.visitEachAndOverrideWith(node.definition, {
|
||||
canBeNull: true
|
||||
}).concat({
|
||||
propertyName: node.separator.name,
|
||||
canBeNull: true,
|
||||
type: getType(node.separator)
|
||||
});
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitAlternation = function (node) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true });
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitTerminal = function (node) {
|
||||
return [
|
||||
{
|
||||
propertyName: node.label || node.terminalType.name,
|
||||
canBeNull: false,
|
||||
type: getType(node)
|
||||
}
|
||||
];
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitNonTerminal = function (node) {
|
||||
return [
|
||||
{
|
||||
propertyName: node.label || node.nonTerminalName,
|
||||
canBeNull: false,
|
||||
type: getType(node)
|
||||
}
|
||||
];
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitEachAndOverrideWith = function (definition, override) {
|
||||
return (0, map_1.default)(this.visitEach(definition), function (definition) { return (0, assign_1.default)({}, definition, override); });
|
||||
};
|
||||
CstNodeDefinitionGenerator.prototype.visitEach = function (definition) {
|
||||
var _this = this;
|
||||
return (0, flatten_1.default)((0, map_1.default)(definition, function (definition) { return _this.visit(definition); }));
|
||||
};
|
||||
return CstNodeDefinitionGenerator;
|
||||
}(gast_1.GAstVisitor));
|
||||
function getType(production) {
|
||||
if (production instanceof gast_1.NonTerminal) {
|
||||
return {
|
||||
kind: "rule",
|
||||
name: production.referencedRule.name
|
||||
};
|
||||
}
|
||||
return { kind: "token" };
|
||||
}
|
||||
//# sourceMappingURL=model.js.map
|
||||
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.js.map
generated
Normal file
1
_node_modules/@chevrotain/cst-dts-gen/lib/src/model.js.map
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,yCAA2D;AAC3D,mDAA4B;AAC5B,2DAAoC;AACpC,yDAAkC;AAClC,qDAA8B;AAC9B,2DAAoC;AACpC,yDAAkC;AAElC,SAAgB,UAAU,CACxB,WAAiC;IAEjC,IAAM,SAAS,GAAG,IAAI,0BAA0B,EAAE,CAAA;IAClD,IAAM,QAAQ,GAAG,IAAA,gBAAM,EAAC,WAAW,CAAC,CAAA;IACpC,OAAO,IAAA,aAAG,EAAC,QAAQ,EAAE,UAAC,IAAI,IAAK,OAAA,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAzB,CAAyB,CAAC,CAAA;AAC3D,CAAC;AAND,gCAMC;AAwBD;IAAyC,8CAAW;IAApD;;IA0GA,CAAC;IAzGC,8CAAS,GAAT,UAAU,IAAU;QAClB,IAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAEnD,IAAM,OAAO,G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OAAO,CAAC,IAAI,CAAC;aACpB;SACF,CAAA;IACH,CAAC;IAEO,6DAAwB,GAAhC,UACE,UAAyB,EACzB,QAAuC;QAEvC,OAAO,IAAA,aAAG,EACR,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAC1B,UAAC,UAAU,IAAK,OAAA,IAAA,gBAAM,EAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAyB,EAAxD,CAAwD,CACzE,CAAA;IACH,CAAC;IAEO,8CAAS,GAAjB,UAAkB,UAAyB;QAA3C,iBAOC;QANC,OAAO,IAAA,iBAAO,EACZ,IAAA,aAAG,EACD,UAAU,EACV,UAAC,UAAU,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,UAAU,CAA2B,EAAhD,CAAgD,CACjE,CACF,CAAA;IACH,CAAC;IACH,iCAAC;AAAD,CAAC,AA1GD,CAAyC,kBAAW,GA0GnD;AAQD,SAAS,OAAO,CACd,UAA8C;IAE9C,IAAI,UAAU,YAAY,kBAAW,EAAE;QACrC,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,IAAI;SACrC,CAAA;KACF;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC1B,CAAC"}
|
||||
44
_node_modules/@chevrotain/cst-dts-gen/package.json
generated
Normal file
44
_node_modules/@chevrotain/cst-dts-gen/package.json
generated
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@chevrotain/cst-dts-gen",
|
||||
"version": "10.5.0",
|
||||
"description": "Generates type definitions for chevrotain CST nodes",
|
||||
"keywords": [],
|
||||
"bugs": {
|
||||
"url": "https://github.com/Chevrotain/chevrotain/issues"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"typings": "lib/src/api.d.ts",
|
||||
"main": "lib/src/api.js",
|
||||
"files": [
|
||||
"src/**/*.ts",
|
||||
"lib/src/**/*.js",
|
||||
"lib/src/**/*.d.ts",
|
||||
"lib/src/**/*.js.map"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Chevrotain/chevrotain.git"
|
||||
},
|
||||
"scripts": {
|
||||
"---------- CI FLOWS --------": "",
|
||||
"ci": "pnpm run build test",
|
||||
"build": "npm-run-all clean compile",
|
||||
"test": "echo \"tests are in a different package\"",
|
||||
"---------- BUILD STEPS --------": "",
|
||||
"clean": "shx rm -rf lib",
|
||||
"compile:watch": "tsc -w",
|
||||
"compile": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chevrotain/gast": "10.5.0",
|
||||
"@chevrotain/types": "10.5.0",
|
||||
"lodash": "4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "4.14.191"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "f5fdf95b8da570c702753252b0a3f7aa34d64f3b"
|
||||
}
|
||||
22
_node_modules/@chevrotain/cst-dts-gen/src/api.ts
generated
Normal file
22
_node_modules/@chevrotain/cst-dts-gen/src/api.ts
generated
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Rule, GenerateDtsOptions } from "@chevrotain/types"
|
||||
import { buildModel } from "./model"
|
||||
import { genDts } from "./generate"
|
||||
|
||||
const defaultOptions: Required<GenerateDtsOptions> = {
|
||||
includeVisitorInterface: true,
|
||||
visitorInterfaceName: "ICstNodeVisitor"
|
||||
}
|
||||
|
||||
export function generateCstDts(
|
||||
productions: Record<string, Rule>,
|
||||
options?: GenerateDtsOptions
|
||||
): string {
|
||||
const effectiveOptions = {
|
||||
...defaultOptions,
|
||||
...options
|
||||
}
|
||||
|
||||
const model = buildModel(productions)
|
||||
|
||||
return genDts(model, effectiveOptions)
|
||||
}
|
||||
103
_node_modules/@chevrotain/cst-dts-gen/src/generate.ts
generated
Normal file
103
_node_modules/@chevrotain/cst-dts-gen/src/generate.ts
generated
Normal file
@@ -0,0 +1,103 @@
|
||||
import flatten from "lodash/flatten"
|
||||
import isArray from "lodash/isArray"
|
||||
import map from "lodash/map"
|
||||
import reduce from "lodash/reduce"
|
||||
import uniq from "lodash/uniq"
|
||||
import upperFirst from "lodash/upperFirst"
|
||||
import { GenerateDtsOptions } from "@chevrotain/types"
|
||||
import {
|
||||
CstNodeTypeDefinition,
|
||||
PropertyTypeDefinition,
|
||||
PropertyArrayType,
|
||||
TokenArrayType,
|
||||
RuleArrayType
|
||||
} from "./model"
|
||||
|
||||
export function genDts(
|
||||
model: CstNodeTypeDefinition[],
|
||||
options: Required<GenerateDtsOptions>
|
||||
): string {
|
||||
let contentParts: string[] = []
|
||||
|
||||
contentParts = contentParts.concat(
|
||||
`import type { CstNode, ICstVisitor, IToken } from "chevrotain";`
|
||||
)
|
||||
|
||||
contentParts = contentParts.concat(
|
||||
flatten(map(model, (node) => genCstNodeTypes(node)))
|
||||
)
|
||||
|
||||
if (options.includeVisitorInterface) {
|
||||
contentParts = contentParts.concat(
|
||||
genVisitor(options.visitorInterfaceName, model)
|
||||
)
|
||||
}
|
||||
|
||||
return contentParts.join("\n\n") + "\n"
|
||||
}
|
||||
|
||||
function genCstNodeTypes(node: CstNodeTypeDefinition) {
|
||||
const nodeCstInterface = genNodeInterface(node)
|
||||
const nodeChildrenInterface = genNodeChildrenType(node)
|
||||
|
||||
return [nodeCstInterface, nodeChildrenInterface]
|
||||
}
|
||||
|
||||
function genNodeInterface(node: CstNodeTypeDefinition) {
|
||||
const nodeInterfaceName = getNodeInterfaceName(node.name)
|
||||
const childrenTypeName = getNodeChildrenTypeName(node.name)
|
||||
|
||||
return `export interface ${nodeInterfaceName} extends CstNode {
|
||||
name: "${node.name}";
|
||||
children: ${childrenTypeName};
|
||||
}`
|
||||
}
|
||||
|
||||
function genNodeChildrenType(node: CstNodeTypeDefinition) {
|
||||
const typeName = getNodeChildrenTypeName(node.name)
|
||||
|
||||
return `export type ${typeName} = {
|
||||
${map(node.properties, (property) => genChildProperty(property)).join("\n ")}
|
||||
};`
|
||||
}
|
||||
|
||||
function genChildProperty(prop: PropertyTypeDefinition) {
|
||||
const typeName = buildTypeString(prop.type)
|
||||
return `${prop.name}${prop.optional ? "?" : ""}: ${typeName}[];`
|
||||
}
|
||||
|
||||
function genVisitor(name: string, nodes: CstNodeTypeDefinition[]) {
|
||||
return `export interface ${name}<IN, OUT> extends ICstVisitor<IN, OUT> {
|
||||
${map(nodes, (node) => genVisitorFunction(node)).join("\n ")}
|
||||
}`
|
||||
}
|
||||
|
||||
function genVisitorFunction(node: CstNodeTypeDefinition) {
|
||||
const childrenTypeName = getNodeChildrenTypeName(node.name)
|
||||
return `${node.name}(children: ${childrenTypeName}, param?: IN): OUT;`
|
||||
}
|
||||
|
||||
function buildTypeString(type: PropertyArrayType) {
|
||||
if (isArray(type)) {
|
||||
const typeNames = uniq(map(type, (t) => getTypeString(t)))
|
||||
const typeString = reduce(typeNames, (sum, t) => sum + " | " + t)
|
||||
return "(" + typeString + ")"
|
||||
} else {
|
||||
return getTypeString(type)
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeString(type: TokenArrayType | RuleArrayType) {
|
||||
if (type.kind === "token") {
|
||||
return "IToken"
|
||||
}
|
||||
return getNodeInterfaceName(type.name)
|
||||
}
|
||||
|
||||
function getNodeInterfaceName(ruleName: string) {
|
||||
return upperFirst(ruleName) + "CstNode"
|
||||
}
|
||||
|
||||
function getNodeChildrenTypeName(ruleName: string) {
|
||||
return upperFirst(ruleName) + "CstChildren"
|
||||
}
|
||||
177
_node_modules/@chevrotain/cst-dts-gen/src/model.ts
generated
Normal file
177
_node_modules/@chevrotain/cst-dts-gen/src/model.ts
generated
Normal file
@@ -0,0 +1,177 @@
|
||||
import type {
|
||||
Alternation,
|
||||
Alternative,
|
||||
IProduction,
|
||||
Option,
|
||||
Repetition,
|
||||
RepetitionMandatory,
|
||||
RepetitionMandatoryWithSeparator,
|
||||
RepetitionWithSeparator,
|
||||
Rule,
|
||||
Terminal,
|
||||
TokenType
|
||||
} from "@chevrotain/types"
|
||||
import { NonTerminal, GAstVisitor } from "@chevrotain/gast"
|
||||
import map from "lodash/map"
|
||||
import flatten from "lodash/flatten"
|
||||
import values from "lodash/values"
|
||||
import some from "lodash/some"
|
||||
import groupBy from "lodash/groupBy"
|
||||
import assign from "lodash/assign"
|
||||
|
||||
export function buildModel(
|
||||
productions: Record<string, Rule>
|
||||
): CstNodeTypeDefinition[] {
|
||||
const generator = new CstNodeDefinitionGenerator()
|
||||
const allRules = values(productions)
|
||||
return map(allRules, (rule) => generator.visitRule(rule))
|
||||
}
|
||||
|
||||
export type CstNodeTypeDefinition = {
|
||||
name: string
|
||||
properties: PropertyTypeDefinition[]
|
||||
}
|
||||
|
||||
export type PropertyTypeDefinition = {
|
||||
name: string
|
||||
type: PropertyArrayType
|
||||
optional: boolean
|
||||
}
|
||||
|
||||
export type PropertyArrayType =
|
||||
| TokenArrayType
|
||||
| RuleArrayType
|
||||
| (TokenArrayType | RuleArrayType)[]
|
||||
|
||||
export type TokenArrayType = { kind: "token" }
|
||||
export type RuleArrayType = {
|
||||
kind: "rule"
|
||||
name: string
|
||||
}
|
||||
|
||||
class CstNodeDefinitionGenerator extends GAstVisitor {
|
||||
visitRule(node: Rule): CstNodeTypeDefinition {
|
||||
const rawElements = this.visitEach(node.definition)
|
||||
|
||||
const grouped = groupBy(rawElements, (el) => el.propertyName)
|
||||
const properties = map(grouped, (group, propertyName) => {
|
||||
const allNullable = !some(group, (el) => !el.canBeNull)
|
||||
|
||||
// In an alternation with a label a property name can have
|
||||
// multiple types.
|
||||
let propertyType: PropertyArrayType = group[0].type
|
||||
if (group.length > 1) {
|
||||
propertyType = map(group, (g) => g.type)
|
||||
}
|
||||
|
||||
return {
|
||||
name: propertyName,
|
||||
type: propertyType,
|
||||
optional: allNullable
|
||||
} as PropertyTypeDefinition
|
||||
})
|
||||
|
||||
return {
|
||||
name: node.name,
|
||||
properties: properties
|
||||
}
|
||||
}
|
||||
|
||||
visitAlternative(node: Alternative) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true })
|
||||
}
|
||||
|
||||
visitOption(node: Option) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true })
|
||||
}
|
||||
|
||||
visitRepetition(node: Repetition) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true })
|
||||
}
|
||||
|
||||
visitRepetitionMandatory(node: RepetitionMandatory) {
|
||||
return this.visitEach(node.definition)
|
||||
}
|
||||
|
||||
visitRepetitionMandatoryWithSeparator(
|
||||
node: RepetitionMandatoryWithSeparator
|
||||
) {
|
||||
return this.visitEach(node.definition).concat({
|
||||
propertyName: node.separator.name,
|
||||
canBeNull: true,
|
||||
type: getType(node.separator)
|
||||
})
|
||||
}
|
||||
|
||||
visitRepetitionWithSeparator(node: RepetitionWithSeparator) {
|
||||
return this.visitEachAndOverrideWith(node.definition, {
|
||||
canBeNull: true
|
||||
}).concat({
|
||||
propertyName: node.separator.name,
|
||||
canBeNull: true,
|
||||
type: getType(node.separator)
|
||||
})
|
||||
}
|
||||
|
||||
visitAlternation(node: Alternation) {
|
||||
return this.visitEachAndOverrideWith(node.definition, { canBeNull: true })
|
||||
}
|
||||
|
||||
visitTerminal(node: Terminal): PropertyTupleElement[] {
|
||||
return [
|
||||
{
|
||||
propertyName: node.label || node.terminalType.name,
|
||||
canBeNull: false,
|
||||
type: getType(node)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
visitNonTerminal(node: NonTerminal): PropertyTupleElement[] {
|
||||
return [
|
||||
{
|
||||
propertyName: node.label || node.nonTerminalName,
|
||||
canBeNull: false,
|
||||
type: getType(node)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
private visitEachAndOverrideWith(
|
||||
definition: IProduction[],
|
||||
override: Partial<PropertyTupleElement>
|
||||
) {
|
||||
return map(
|
||||
this.visitEach(definition),
|
||||
(definition) => assign({}, definition, override) as PropertyTupleElement
|
||||
)
|
||||
}
|
||||
|
||||
private visitEach(definition: IProduction[]) {
|
||||
return flatten<PropertyTupleElement>(
|
||||
map(
|
||||
definition,
|
||||
(definition) => this.visit(definition) as PropertyTupleElement[]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
type PropertyTupleElement = {
|
||||
propertyName: string
|
||||
canBeNull: boolean
|
||||
type: TokenArrayType | RuleArrayType
|
||||
}
|
||||
|
||||
function getType(
|
||||
production: Terminal | NonTerminal | TokenType
|
||||
): TokenArrayType | RuleArrayType {
|
||||
if (production instanceof NonTerminal) {
|
||||
return {
|
||||
kind: "rule",
|
||||
name: production.referencedRule.name
|
||||
}
|
||||
}
|
||||
|
||||
return { kind: "token" }
|
||||
}
|
||||
Reference in New Issue
Block a user