@chevrotain/gast
Advanced tools
Comparing version 10.5.0 to 11.0.0
@@ -1,3 +0,3 @@ | ||
export { Rule, Terminal, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Alternation, Alternative, serializeGrammar, serializeProduction } from "./model"; | ||
export { GAstVisitor } from "./visitor"; | ||
export { getProductionDslName, isOptionalProd, isBranchingProd, isSequenceProd } from "./helpers"; | ||
export { Rule, Terminal, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Alternation, Alternative, serializeGrammar, serializeProduction, } from "./model.js"; | ||
export { GAstVisitor } from "./visitor.js"; | ||
export { getProductionDslName, isOptionalProd, isBranchingProd, isSequenceProd, } from "./helpers.js"; |
@@ -1,24 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSequenceProd = exports.isBranchingProd = exports.isOptionalProd = exports.getProductionDslName = exports.GAstVisitor = exports.serializeProduction = exports.serializeGrammar = exports.Alternative = exports.Alternation = exports.RepetitionWithSeparator = exports.RepetitionMandatoryWithSeparator = exports.RepetitionMandatory = exports.Repetition = exports.Option = exports.NonTerminal = exports.Terminal = exports.Rule = void 0; | ||
var model_1 = require("./model"); | ||
Object.defineProperty(exports, "Rule", { enumerable: true, get: function () { return model_1.Rule; } }); | ||
Object.defineProperty(exports, "Terminal", { enumerable: true, get: function () { return model_1.Terminal; } }); | ||
Object.defineProperty(exports, "NonTerminal", { enumerable: true, get: function () { return model_1.NonTerminal; } }); | ||
Object.defineProperty(exports, "Option", { enumerable: true, get: function () { return model_1.Option; } }); | ||
Object.defineProperty(exports, "Repetition", { enumerable: true, get: function () { return model_1.Repetition; } }); | ||
Object.defineProperty(exports, "RepetitionMandatory", { enumerable: true, get: function () { return model_1.RepetitionMandatory; } }); | ||
Object.defineProperty(exports, "RepetitionMandatoryWithSeparator", { enumerable: true, get: function () { return model_1.RepetitionMandatoryWithSeparator; } }); | ||
Object.defineProperty(exports, "RepetitionWithSeparator", { enumerable: true, get: function () { return model_1.RepetitionWithSeparator; } }); | ||
Object.defineProperty(exports, "Alternation", { enumerable: true, get: function () { return model_1.Alternation; } }); | ||
Object.defineProperty(exports, "Alternative", { enumerable: true, get: function () { return model_1.Alternative; } }); | ||
Object.defineProperty(exports, "serializeGrammar", { enumerable: true, get: function () { return model_1.serializeGrammar; } }); | ||
Object.defineProperty(exports, "serializeProduction", { enumerable: true, get: function () { return model_1.serializeProduction; } }); | ||
var visitor_1 = require("./visitor"); | ||
Object.defineProperty(exports, "GAstVisitor", { enumerable: true, get: function () { return visitor_1.GAstVisitor; } }); | ||
var helpers_1 = require("./helpers"); | ||
Object.defineProperty(exports, "getProductionDslName", { enumerable: true, get: function () { return helpers_1.getProductionDslName; } }); | ||
Object.defineProperty(exports, "isOptionalProd", { enumerable: true, get: function () { return helpers_1.isOptionalProd; } }); | ||
Object.defineProperty(exports, "isBranchingProd", { enumerable: true, get: function () { return helpers_1.isBranchingProd; } }); | ||
Object.defineProperty(exports, "isSequenceProd", { enumerable: true, get: function () { return helpers_1.isSequenceProd; } }); | ||
export { Rule, Terminal, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Alternation, Alternative, serializeGrammar, serializeProduction, } from "./model.js"; | ||
export { GAstVisitor } from "./visitor.js"; | ||
export { getProductionDslName, isOptionalProd, isBranchingProd, isSequenceProd, } from "./helpers.js"; | ||
//# sourceMappingURL=api.js.map |
@@ -1,3 +0,3 @@ | ||
import { NonTerminal } from "./model"; | ||
import { IProduction, IProductionWithOccurrence } from "@chevrotain/types"; | ||
import { NonTerminal } from "./model.js"; | ||
import type { IProduction, IProductionWithOccurrence } from "@chevrotain/types"; | ||
export declare function isSequenceProd(prod: IProduction): prod is { | ||
@@ -4,0 +4,0 @@ definition: IProduction[]; |
@@ -1,27 +0,17 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getProductionDslName = exports.isBranchingProd = exports.isOptionalProd = exports.isSequenceProd = void 0; | ||
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) { | ||
return (prod instanceof model_1.Alternative || | ||
prod instanceof model_1.Option || | ||
prod instanceof model_1.Repetition || | ||
prod instanceof model_1.RepetitionMandatory || | ||
prod instanceof model_1.RepetitionMandatoryWithSeparator || | ||
prod instanceof model_1.RepetitionWithSeparator || | ||
prod instanceof model_1.Terminal || | ||
prod instanceof model_1.Rule); | ||
import { every, includes, some } from "lodash-es"; | ||
import { AbstractProduction, Alternation, Alternative, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Rule, Terminal, } from "./model.js"; | ||
export function isSequenceProd(prod) { | ||
return (prod instanceof Alternative || | ||
prod instanceof Option || | ||
prod instanceof Repetition || | ||
prod instanceof RepetitionMandatory || | ||
prod instanceof RepetitionMandatoryWithSeparator || | ||
prod instanceof RepetitionWithSeparator || | ||
prod instanceof Terminal || | ||
prod instanceof Rule); | ||
} | ||
exports.isSequenceProd = isSequenceProd; | ||
function isOptionalProd(prod, alreadyVisited) { | ||
if (alreadyVisited === void 0) { alreadyVisited = []; } | ||
var isDirectlyOptional = prod instanceof model_1.Option || | ||
prod instanceof model_1.Repetition || | ||
prod instanceof model_1.RepetitionWithSeparator; | ||
export function isOptionalProd(prod, alreadyVisited = []) { | ||
const isDirectlyOptional = prod instanceof Option || | ||
prod instanceof Repetition || | ||
prod instanceof RepetitionWithSeparator; | ||
if (isDirectlyOptional) { | ||
@@ -33,17 +23,17 @@ return true; | ||
// may be indirectly optional ((A?B?C?) | (D?E?F?)) | ||
if (prod instanceof model_1.Alternation) { | ||
if (prod instanceof Alternation) { | ||
// for OR its enough for just one of the alternatives to be optional | ||
return (0, some_1.default)(prod.definition, function (subProd) { | ||
return some(prod.definition, (subProd) => { | ||
return isOptionalProd(subProd, alreadyVisited); | ||
}); | ||
} | ||
else if (prod instanceof model_1.NonTerminal && (0, includes_1.default)(alreadyVisited, prod)) { | ||
else if (prod instanceof NonTerminal && includes(alreadyVisited, prod)) { | ||
// avoiding stack overflow due to infinite recursion | ||
return false; | ||
} | ||
else if (prod instanceof model_1.AbstractProduction) { | ||
if (prod instanceof model_1.NonTerminal) { | ||
else if (prod instanceof AbstractProduction) { | ||
if (prod instanceof NonTerminal) { | ||
alreadyVisited.push(prod); | ||
} | ||
return (0, every_1.default)(prod.definition, function (subProd) { | ||
return every(prod.definition, (subProd) => { | ||
return isOptionalProd(subProd, alreadyVisited); | ||
@@ -56,32 +46,31 @@ }); | ||
} | ||
exports.isOptionalProd = isOptionalProd; | ||
function isBranchingProd(prod) { | ||
return prod instanceof model_1.Alternation; | ||
export function isBranchingProd(prod) { | ||
return prod instanceof Alternation; | ||
} | ||
exports.isBranchingProd = isBranchingProd; | ||
function getProductionDslName(prod) { | ||
export function getProductionDslName(prod) { | ||
/* istanbul ignore else */ | ||
if (prod instanceof model_1.NonTerminal) { | ||
if (prod instanceof NonTerminal) { | ||
return "SUBRULE"; | ||
} | ||
else if (prod instanceof model_1.Option) { | ||
else if (prod instanceof Option) { | ||
return "OPTION"; | ||
} | ||
else if (prod instanceof model_1.Alternation) { | ||
else if (prod instanceof Alternation) { | ||
return "OR"; | ||
} | ||
else if (prod instanceof model_1.RepetitionMandatory) { | ||
else if (prod instanceof RepetitionMandatory) { | ||
return "AT_LEAST_ONE"; | ||
} | ||
else if (prod instanceof model_1.RepetitionMandatoryWithSeparator) { | ||
else if (prod instanceof RepetitionMandatoryWithSeparator) { | ||
return "AT_LEAST_ONE_SEP"; | ||
} | ||
else if (prod instanceof model_1.RepetitionWithSeparator) { | ||
else if (prod instanceof RepetitionWithSeparator) { | ||
return "MANY_SEP"; | ||
} | ||
else if (prod instanceof model_1.Repetition) { | ||
else if (prod instanceof Repetition) { | ||
return "MANY"; | ||
} | ||
else if (prod instanceof model_1.Terminal) { | ||
else if (prod instanceof Terminal) { | ||
return "CONSUME"; | ||
/* c8 ignore next 3 */ | ||
} | ||
@@ -92,3 +81,2 @@ else { | ||
} | ||
exports.getProductionDslName = getProductionDslName; | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,2 +0,2 @@ | ||
import { IGASTVisitor, IProduction, IProductionWithOccurrence, ISerializedGast, TokenType } from "@chevrotain/types"; | ||
import type { IGASTVisitor, IProduction, IProductionWithOccurrence, ISerializedGast, TokenType } from "@chevrotain/types"; | ||
export declare abstract class AbstractProduction<T extends IProduction = IProduction> implements IProduction { | ||
@@ -3,0 +3,0 @@ protected _definition: T[]; |
@@ -1,28 +0,2 @@ | ||
"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.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; | ||
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")); | ||
import { assign, forEach, isRegExp, isString, map, pickBy } from "lodash-es"; | ||
// TODO: duplicated code to avoid extracting another sub-package -- how to avoid? | ||
@@ -39,182 +13,129 @@ function tokenLabel(tokType) { | ||
function hasTokenLabel(obj) { | ||
return (0, isString_1.default)(obj.LABEL) && obj.LABEL !== ""; | ||
return isString(obj.LABEL) && obj.LABEL !== ""; | ||
} | ||
var AbstractProduction = /** @class */ (function () { | ||
function AbstractProduction(_definition) { | ||
export class AbstractProduction { | ||
get definition() { | ||
return this._definition; | ||
} | ||
set definition(value) { | ||
this._definition = value; | ||
} | ||
constructor(_definition) { | ||
this._definition = _definition; | ||
} | ||
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) { | ||
accept(visitor) { | ||
visitor.visit(this); | ||
(0, forEach_1.default)(this.definition, function (prod) { | ||
forEach(this.definition, (prod) => { | ||
prod.accept(visitor); | ||
}); | ||
}; | ||
return AbstractProduction; | ||
}()); | ||
exports.AbstractProduction = AbstractProduction; | ||
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; | ||
} | ||
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) { | ||
} | ||
export class NonTerminal extends AbstractProduction { | ||
constructor(options) { | ||
super([]); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
set definition(definition) { | ||
// immutable | ||
} | ||
get definition() { | ||
if (this.referencedRule !== undefined) { | ||
return this.referencedRule.definition; | ||
} | ||
return []; | ||
} | ||
accept(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; | ||
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; | ||
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; | ||
} | ||
export class Rule extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.orgText = ""; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return Alternative; | ||
}(AbstractProduction)); | ||
exports.Alternative = Alternative; | ||
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; | ||
} | ||
export class Alternative extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.ignoreAmbiguities = false; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return Option; | ||
}(AbstractProduction)); | ||
exports.Option = Option; | ||
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; | ||
} | ||
export class Option extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return RepetitionMandatory; | ||
}(AbstractProduction)); | ||
exports.RepetitionMandatory = RepetitionMandatory; | ||
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; | ||
} | ||
export class RepetitionMandatory extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return RepetitionMandatoryWithSeparator; | ||
}(AbstractProduction)); | ||
exports.RepetitionMandatoryWithSeparator = RepetitionMandatoryWithSeparator; | ||
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; | ||
} | ||
export class RepetitionMandatoryWithSeparator extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return Repetition; | ||
}(AbstractProduction)); | ||
exports.Repetition = Repetition; | ||
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; | ||
} | ||
export class Repetition extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
return RepetitionWithSeparator; | ||
}(AbstractProduction)); | ||
exports.RepetitionWithSeparator = RepetitionWithSeparator; | ||
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; | ||
} | ||
export class RepetitionWithSeparator extends AbstractProduction { | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
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; | ||
var Terminal = /** @class */ (function () { | ||
function Terminal(options) { | ||
} | ||
export class Alternation extends AbstractProduction { | ||
get definition() { | ||
return this._definition; | ||
} | ||
set definition(value) { | ||
this._definition = value; | ||
} | ||
constructor(options) { | ||
super(options.definition); | ||
this.idx = 1; | ||
(0, assign_1.default)(this, (0, pickBy_1.default)(options, function (v) { return v !== undefined; })); | ||
this.ignoreAmbiguities = false; | ||
this.hasPredicates = false; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
Terminal.prototype.accept = function (visitor) { | ||
} | ||
export class Terminal { | ||
constructor(options) { | ||
this.idx = 1; | ||
assign(this, pickBy(options, (v) => v !== undefined)); | ||
} | ||
accept(visitor) { | ||
visitor.visit(this); | ||
}; | ||
return Terminal; | ||
}()); | ||
exports.Terminal = Terminal; | ||
function serializeGrammar(topRules) { | ||
return (0, map_1.default)(topRules, serializeProduction); | ||
} | ||
} | ||
exports.serializeGrammar = serializeGrammar; | ||
function serializeProduction(node) { | ||
export function serializeGrammar(topRules) { | ||
return map(topRules, serializeProduction); | ||
} | ||
export function serializeProduction(node) { | ||
function convertDefinition(definition) { | ||
return (0, map_1.default)(definition, serializeProduction); | ||
return map(definition, serializeProduction); | ||
} | ||
/* istanbul ignore else */ | ||
if (node instanceof NonTerminal) { | ||
var serializedNonTerminal = { | ||
const serializedNonTerminal = { | ||
type: "NonTerminal", | ||
name: node.nonTerminalName, | ||
idx: node.idx | ||
idx: node.idx, | ||
}; | ||
if ((0, isString_1.default)(node.label)) { | ||
if (isString(node.label)) { | ||
serializedNonTerminal.label = node.label; | ||
@@ -227,3 +148,3 @@ } | ||
type: "Alternative", | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -235,3 +156,3 @@ } | ||
idx: node.idx, | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -243,3 +164,3 @@ } | ||
idx: node.idx, | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -252,3 +173,3 @@ } | ||
separator: (serializeProduction(new Terminal({ terminalType: node.separator }))), | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -261,3 +182,3 @@ } | ||
separator: (serializeProduction(new Terminal({ terminalType: node.separator }))), | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -269,3 +190,3 @@ } | ||
idx: node.idx, | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
@@ -277,18 +198,18 @@ } | ||
idx: node.idx, | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
} | ||
else if (node instanceof Terminal) { | ||
var serializedTerminal = { | ||
const serializedTerminal = { | ||
type: "Terminal", | ||
name: node.terminalType.name, | ||
label: tokenLabel(node.terminalType), | ||
idx: node.idx | ||
idx: node.idx, | ||
}; | ||
if ((0, isString_1.default)(node.label)) { | ||
if (isString(node.label)) { | ||
serializedTerminal.terminalLabel = node.label; | ||
} | ||
var pattern = node.terminalType.PATTERN; | ||
const pattern = node.terminalType.PATTERN; | ||
if (node.terminalType.PATTERN) { | ||
serializedTerminal.pattern = (0, isRegExp_1.default)(pattern) | ||
serializedTerminal.pattern = isRegExp(pattern) | ||
? pattern.source | ||
@@ -304,4 +225,5 @@ : pattern; | ||
orgText: node.orgText, | ||
definition: convertDefinition(node.definition) | ||
definition: convertDefinition(node.definition), | ||
}; | ||
/* c8 ignore next 3 */ | ||
} | ||
@@ -312,3 +234,2 @@ else { | ||
} | ||
exports.serializeProduction = serializeProduction; | ||
//# sourceMappingURL=model.js.map |
@@ -1,3 +0,3 @@ | ||
import { Alternation, Alternative, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Rule, Terminal } from "./model"; | ||
import { IProduction } from "@chevrotain/types"; | ||
import { Alternation, Alternative, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Rule, Terminal } from "./model.js"; | ||
import type { IProduction } from "@chevrotain/types"; | ||
export declare abstract class GAstVisitor { | ||
@@ -4,0 +4,0 @@ visit(node: IProduction): any; |
@@ -1,59 +0,52 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GAstVisitor = void 0; | ||
var model_1 = require("./model"); | ||
var GAstVisitor = /** @class */ (function () { | ||
function GAstVisitor() { | ||
} | ||
GAstVisitor.prototype.visit = function (node) { | ||
var nodeAny = node; | ||
import { Alternation, Alternative, NonTerminal, Option, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Rule, Terminal, } from "./model.js"; | ||
export class GAstVisitor { | ||
visit(node) { | ||
const nodeAny = node; | ||
switch (nodeAny.constructor) { | ||
case model_1.NonTerminal: | ||
case NonTerminal: | ||
return this.visitNonTerminal(nodeAny); | ||
case model_1.Alternative: | ||
case Alternative: | ||
return this.visitAlternative(nodeAny); | ||
case model_1.Option: | ||
case Option: | ||
return this.visitOption(nodeAny); | ||
case model_1.RepetitionMandatory: | ||
case RepetitionMandatory: | ||
return this.visitRepetitionMandatory(nodeAny); | ||
case model_1.RepetitionMandatoryWithSeparator: | ||
case RepetitionMandatoryWithSeparator: | ||
return this.visitRepetitionMandatoryWithSeparator(nodeAny); | ||
case model_1.RepetitionWithSeparator: | ||
case RepetitionWithSeparator: | ||
return this.visitRepetitionWithSeparator(nodeAny); | ||
case model_1.Repetition: | ||
case Repetition: | ||
return this.visitRepetition(nodeAny); | ||
case model_1.Alternation: | ||
case Alternation: | ||
return this.visitAlternation(nodeAny); | ||
case model_1.Terminal: | ||
case Terminal: | ||
return this.visitTerminal(nodeAny); | ||
case model_1.Rule: | ||
case Rule: | ||
return this.visitRule(nodeAny); | ||
/* istanbul ignore next */ | ||
/* c8 ignore next 2 */ | ||
default: | ||
throw Error("non exhaustive match"); | ||
} | ||
}; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitNonTerminal = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitAlternative = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitOption = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitRepetition = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitRepetitionMandatory = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitRepetitionMandatoryWithSeparator = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitRepetitionWithSeparator = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitAlternation = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitTerminal = function (node) { }; | ||
/* istanbul ignore next - testing the fact a NOOP function exists is non-trivial */ | ||
GAstVisitor.prototype.visitRule = function (node) { }; | ||
return GAstVisitor; | ||
}()); | ||
exports.GAstVisitor = GAstVisitor; | ||
} | ||
/* c8 ignore next */ | ||
visitNonTerminal(node) { } | ||
/* c8 ignore next */ | ||
visitAlternative(node) { } | ||
/* c8 ignore next */ | ||
visitOption(node) { } | ||
/* c8 ignore next */ | ||
visitRepetition(node) { } | ||
/* c8 ignore next */ | ||
visitRepetitionMandatory(node) { } | ||
/* c8 ignore next 3 */ | ||
visitRepetitionMandatoryWithSeparator(node) { } | ||
/* c8 ignore next */ | ||
visitRepetitionWithSeparator(node) { } | ||
/* c8 ignore next */ | ||
visitAlternation(node) { } | ||
/* c8 ignore next */ | ||
visitTerminal(node) { } | ||
/* c8 ignore next */ | ||
visitRule(node) { } | ||
} | ||
//# sourceMappingURL=visitor.js.map |
{ | ||
"name": "@chevrotain/gast", | ||
"version": "10.5.0", | ||
"version": "11.0.0", | ||
"description": "Grammar AST structure for Chevrotain Parsers", | ||
@@ -10,10 +10,12 @@ "keywords": [], | ||
"license": "Apache-2.0", | ||
"typings": "lib/src/api.d.ts", | ||
"main": "lib/src/api.js", | ||
"type": "module", | ||
"types": "lib/src/api.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./lib/src/api.js" | ||
} | ||
}, | ||
"files": [ | ||
"src/**/*.ts", | ||
"lib/src/**/*.js", | ||
"lib/src/**/*.d.ts", | ||
"lib/src/**/*.js.map", | ||
"api.d.ts" | ||
"lib/src/**/*.d.ts" | ||
], | ||
@@ -35,10 +37,10 @@ "repository": { | ||
"compile": "tsc", | ||
"coverage": "nyc mocha" | ||
"coverage": "c8 mocha --enable-source-maps" | ||
}, | ||
"dependencies": { | ||
"@chevrotain/types": "10.5.0", | ||
"lodash": "4.17.21" | ||
"@chevrotain/types": "11.0.0", | ||
"lodash-es": "4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "4.14.191" | ||
"@types/lodash-es": "4.17.7" | ||
}, | ||
@@ -48,3 +50,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "f5fdf95b8da570c702753252b0a3f7aa34d64f3b" | ||
"gitHead": "a04f844af77289a207b2e168f4aa5108116380e3" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Yes
30862
10
528
1
+ Addedlodash-es@4.17.21
+ Added@chevrotain/types@11.0.0(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removedlodash@4.17.21
- Removed@chevrotain/types@10.5.0(transitive)
- Removedlodash@4.17.21(transitive)
Updated@chevrotain/types@11.0.0