@chevrotain/gast
Advanced tools
Comparing version 10.2.0 to 10.3.0
@@ -7,6 +7,6 @@ "use strict"; | ||
exports.getProductionDslName = exports.isBranchingProd = exports.isOptionalProd = exports.isSequenceProd = void 0; | ||
const some_1 = __importDefault(require("lodash/some")); | ||
const every_1 = __importDefault(require("lodash/every")); | ||
const includes_1 = __importDefault(require("lodash/includes")); | ||
const model_1 = require("./model"); | ||
var some_1 = __importDefault(require("lodash/some")); | ||
var every_1 = __importDefault(require("lodash/every")); | ||
var includes_1 = __importDefault(require("lodash/includes")); | ||
var model_1 = require("./model"); | ||
function isSequenceProd(prod) { | ||
@@ -23,4 +23,5 @@ return (prod instanceof model_1.Alternative || | ||
exports.isSequenceProd = isSequenceProd; | ||
function isOptionalProd(prod, alreadyVisited = []) { | ||
const isDirectlyOptional = prod instanceof model_1.Option || | ||
function isOptionalProd(prod, alreadyVisited) { | ||
if (alreadyVisited === void 0) { alreadyVisited = []; } | ||
var isDirectlyOptional = prod instanceof model_1.Option || | ||
prod instanceof model_1.Repetition || | ||
@@ -36,3 +37,3 @@ prod instanceof model_1.RepetitionWithSeparator; | ||
// for OR its enough for just one of the alternatives to be optional | ||
return (0, some_1.default)(prod.definition, (subProd) => { | ||
return (0, some_1.default)(prod.definition, function (subProd) { | ||
return isOptionalProd(subProd, alreadyVisited); | ||
@@ -49,3 +50,3 @@ }); | ||
} | ||
return (0, every_1.default)(prod.definition, (subProd) => { | ||
return (0, every_1.default)(prod.definition, function (subProd) { | ||
return isOptionalProd(subProd, alreadyVisited); | ||
@@ -52,0 +53,0 @@ }); |
"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) { | ||
@@ -7,8 +22,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.serializeProduction = exports.serializeGrammar = exports.Terminal = exports.Alternation = exports.RepetitionWithSeparator = exports.Repetition = exports.RepetitionMandatoryWithSeparator = exports.RepetitionMandatory = exports.Option = exports.Alternative = exports.Rule = exports.NonTerminal = exports.AbstractProduction = void 0; | ||
const map_1 = __importDefault(require("lodash/map")); | ||
const forEach_1 = __importDefault(require("lodash/forEach")); | ||
const isString_1 = __importDefault(require("lodash/isString")); | ||
const isRegExp_1 = __importDefault(require("lodash/isRegExp")); | ||
const pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
const assign_1 = __importDefault(require("lodash/assign")); | ||
var map_1 = __importDefault(require("lodash/map")); | ||
var forEach_1 = __importDefault(require("lodash/forEach")); | ||
var isString_1 = __importDefault(require("lodash/isString")); | ||
var isRegExp_1 = __importDefault(require("lodash/isRegExp")); | ||
var pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
var assign_1 = __importDefault(require("lodash/assign")); | ||
// TODO: duplicated code to avoid extracting another sub-package -- how to avoid? | ||
@@ -27,122 +42,163 @@ function tokenLabel(tokType) { | ||
} | ||
class AbstractProduction { | ||
constructor(_definition) { | ||
var AbstractProduction = /** @class */ (function () { | ||
function AbstractProduction(_definition) { | ||
this._definition = _definition; | ||
} | ||
get definition() { | ||
return this._definition; | ||
} | ||
set definition(value) { | ||
this._definition = value; | ||
} | ||
accept(visitor) { | ||
Object.defineProperty(AbstractProduction.prototype, "definition", { | ||
get: function () { | ||
return this._definition; | ||
}, | ||
set: function (value) { | ||
this._definition = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
AbstractProduction.prototype.accept = function (visitor) { | ||
visitor.visit(this); | ||
(0, forEach_1.default)(this.definition, (prod) => { | ||
(0, forEach_1.default)(this.definition, function (prod) { | ||
prod.accept(visitor); | ||
}); | ||
} | ||
} | ||
}; | ||
return AbstractProduction; | ||
}()); | ||
exports.AbstractProduction = AbstractProduction; | ||
class NonTerminal extends AbstractProduction { | ||
constructor(options) { | ||
super([]); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var NonTerminal = /** @class */ (function (_super) { | ||
__extends(NonTerminal, _super); | ||
function NonTerminal(options) { | ||
var _this = _super.call(this, []) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
set definition(definition) { | ||
// immutable | ||
} | ||
get definition() { | ||
if (this.referencedRule !== undefined) { | ||
return this.referencedRule.definition; | ||
} | ||
return []; | ||
} | ||
accept(visitor) { | ||
Object.defineProperty(NonTerminal.prototype, "definition", { | ||
get: function () { | ||
if (this.referencedRule !== undefined) { | ||
return this.referencedRule.definition; | ||
} | ||
return []; | ||
}, | ||
set: function (definition) { | ||
// immutable | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
NonTerminal.prototype.accept = function (visitor) { | ||
visitor.visit(this); | ||
// don't visit children of a reference, we will get cyclic infinite loops if we do so | ||
} | ||
} | ||
}; | ||
return NonTerminal; | ||
}(AbstractProduction)); | ||
exports.NonTerminal = NonTerminal; | ||
class Rule extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.orgText = ""; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var Rule = /** @class */ (function (_super) { | ||
__extends(Rule, _super); | ||
function Rule(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.orgText = ""; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return Rule; | ||
}(AbstractProduction)); | ||
exports.Rule = Rule; | ||
class Alternative extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.ignoreAmbiguities = false; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var Alternative = /** @class */ (function (_super) { | ||
__extends(Alternative, _super); | ||
function Alternative(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.ignoreAmbiguities = false; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return Alternative; | ||
}(AbstractProduction)); | ||
exports.Alternative = Alternative; | ||
class Option extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var Option = /** @class */ (function (_super) { | ||
__extends(Option, _super); | ||
function Option(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return Option; | ||
}(AbstractProduction)); | ||
exports.Option = Option; | ||
class RepetitionMandatory extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var RepetitionMandatory = /** @class */ (function (_super) { | ||
__extends(RepetitionMandatory, _super); | ||
function RepetitionMandatory(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return RepetitionMandatory; | ||
}(AbstractProduction)); | ||
exports.RepetitionMandatory = RepetitionMandatory; | ||
class RepetitionMandatoryWithSeparator extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var RepetitionMandatoryWithSeparator = /** @class */ (function (_super) { | ||
__extends(RepetitionMandatoryWithSeparator, _super); | ||
function RepetitionMandatoryWithSeparator(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return RepetitionMandatoryWithSeparator; | ||
}(AbstractProduction)); | ||
exports.RepetitionMandatoryWithSeparator = RepetitionMandatoryWithSeparator; | ||
class Repetition extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var Repetition = /** @class */ (function (_super) { | ||
__extends(Repetition, _super); | ||
function Repetition(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return Repetition; | ||
}(AbstractProduction)); | ||
exports.Repetition = Repetition; | ||
class RepetitionWithSeparator extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var RepetitionWithSeparator = /** @class */ (function (_super) { | ||
__extends(RepetitionWithSeparator, _super); | ||
function RepetitionWithSeparator(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
} | ||
return RepetitionWithSeparator; | ||
}(AbstractProduction)); | ||
exports.RepetitionWithSeparator = RepetitionWithSeparator; | ||
class Alternation extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
this.ignoreAmbiguities = false; | ||
this.hasPredicates = false; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
var Alternation = /** @class */ (function (_super) { | ||
__extends(Alternation, _super); | ||
function Alternation(options) { | ||
var _this = _super.call(this, options.definition) || this; | ||
_this.idx = 1; | ||
_this.ignoreAmbiguities = false; | ||
_this.hasPredicates = false; | ||
(0, assign_1.default)(_this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
return _this; | ||
} | ||
get definition() { | ||
return this._definition; | ||
} | ||
set definition(value) { | ||
this._definition = value; | ||
} | ||
} | ||
Object.defineProperty(Alternation.prototype, "definition", { | ||
get: function () { | ||
return this._definition; | ||
}, | ||
set: function (value) { | ||
this._definition = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Alternation; | ||
}(AbstractProduction)); | ||
exports.Alternation = Alternation; | ||
class Terminal { | ||
constructor(options) { | ||
var Terminal = /** @class */ (function () { | ||
function Terminal(options) { | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, (v) => v !== undefined)); | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
} | ||
accept(visitor) { | ||
Terminal.prototype.accept = function (visitor) { | ||
visitor.visit(this); | ||
} | ||
} | ||
}; | ||
return Terminal; | ||
}()); | ||
exports.Terminal = Terminal; | ||
@@ -159,3 +215,3 @@ function serializeGrammar(topRules) { | ||
if (node instanceof NonTerminal) { | ||
const serializedNonTerminal = { | ||
var serializedNonTerminal = { | ||
type: "NonTerminal", | ||
@@ -221,3 +277,3 @@ name: node.nonTerminalName, | ||
else if (node instanceof Terminal) { | ||
const serializedTerminal = { | ||
var serializedTerminal = { | ||
type: "Terminal", | ||
@@ -231,3 +287,3 @@ name: node.terminalType.name, | ||
} | ||
const pattern = node.terminalType.PATTERN; | ||
var pattern = node.terminalType.PATTERN; | ||
if (node.terminalType.PATTERN) { | ||
@@ -234,0 +290,0 @@ serializedTerminal.pattern = (0, isRegExp_1.default)(pattern) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GAstVisitor = void 0; | ||
const model_1 = require("./model"); | ||
class GAstVisitor { | ||
visit(node) { | ||
const nodeAny = node; | ||
var model_1 = require("./model"); | ||
var GAstVisitor = /** @class */ (function () { | ||
function GAstVisitor() { | ||
} | ||
GAstVisitor.prototype.visit = function (node) { | ||
var nodeAny = node; | ||
switch (nodeAny.constructor) { | ||
@@ -33,25 +35,26 @@ case model_1.NonTerminal: | ||
} | ||
} | ||
}; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitNonTerminal(node) { } | ||
GAstVisitor.prototype.visitNonTerminal = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitAlternative(node) { } | ||
GAstVisitor.prototype.visitAlternative = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitOption(node) { } | ||
GAstVisitor.prototype.visitOption = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitRepetition(node) { } | ||
GAstVisitor.prototype.visitRepetition = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitRepetitionMandatory(node) { } | ||
GAstVisitor.prototype.visitRepetitionMandatory = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitRepetitionMandatoryWithSeparator(node) { } | ||
GAstVisitor.prototype.visitRepetitionMandatoryWithSeparator = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitRepetitionWithSeparator(node) { } | ||
GAstVisitor.prototype.visitRepetitionWithSeparator = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitAlternation(node) { } | ||
GAstVisitor.prototype.visitAlternation = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitTerminal(node) { } | ||
GAstVisitor.prototype.visitTerminal = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
visitRule(node) { } | ||
} | ||
GAstVisitor.prototype.visitRule = function (node) { }; | ||
return GAstVisitor; | ||
}()); | ||
exports.GAstVisitor = GAstVisitor; | ||
//# sourceMappingURL=visitor.js.map |
{ | ||
"name": "@chevrotain/gast", | ||
"version": "10.2.0", | ||
"version": "10.3.0", | ||
"description": "Grammar AST structure for Chevrotain Parsers", | ||
@@ -37,3 +37,3 @@ "keywords": [], | ||
"dependencies": { | ||
"@chevrotain/types": "^10.2.0", | ||
"@chevrotain/types": "10.3.0", | ||
"lodash": "4.17.21" | ||
@@ -47,3 +47,3 @@ }, | ||
}, | ||
"gitHead": "f9c92d8ec45c9236abb53091380682d4b32f8207" | ||
"gitHead": "5ca7d276f475839c815a2686f38e2814371935c9" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66570
1207
+ Added@chevrotain/types@10.3.0(transitive)
- Removed@chevrotain/types@10.5.0(transitive)
Updated@chevrotain/types@10.3.0