add hw2
This commit is contained in:
3
node_modules/@chevrotain/gast/lib/src/api.d.ts
generated
vendored
Normal file
3
node_modules/@chevrotain/gast/lib/src/api.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
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";
|
||||
4
node_modules/@chevrotain/gast/lib/src/api.js
generated
vendored
Normal file
4
node_modules/@chevrotain/gast/lib/src/api.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
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
node_modules/@chevrotain/gast/lib/src/api.js.map
generated
vendored
Normal file
1
node_modules/@chevrotain/gast/lib/src/api.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,gCAAgC,EAChC,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,cAAc,CAAC"}
|
||||
10
node_modules/@chevrotain/gast/lib/src/helpers.d.ts
generated
vendored
Normal file
10
node_modules/@chevrotain/gast/lib/src/helpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { NonTerminal } from "./model.js";
|
||||
import type { IProduction, IProductionWithOccurrence } from "@chevrotain/types";
|
||||
export declare function isSequenceProd(prod: IProduction): prod is {
|
||||
definition: IProduction[];
|
||||
} & IProduction;
|
||||
export declare function isOptionalProd(prod: IProduction, alreadyVisited?: NonTerminal[]): boolean;
|
||||
export declare function isBranchingProd(prod: IProduction): prod is {
|
||||
definition: IProduction[];
|
||||
} & IProduction;
|
||||
export declare function getProductionDslName(prod: IProductionWithOccurrence): string;
|
||||
79
node_modules/@chevrotain/gast/lib/src/helpers.js
generated
vendored
Normal file
79
node_modules/@chevrotain/gast/lib/src/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
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);
|
||||
}
|
||||
export function isOptionalProd(prod, alreadyVisited = []) {
|
||||
const isDirectlyOptional = prod instanceof Option ||
|
||||
prod instanceof Repetition ||
|
||||
prod instanceof RepetitionWithSeparator;
|
||||
if (isDirectlyOptional) {
|
||||
return true;
|
||||
}
|
||||
// note that this can cause infinite loop if one optional empty TOP production has a cyclic dependency with another
|
||||
// empty optional top rule
|
||||
// may be indirectly optional ((A?B?C?) | (D?E?F?))
|
||||
if (prod instanceof Alternation) {
|
||||
// for OR its enough for just one of the alternatives to be optional
|
||||
return some(prod.definition, (subProd) => {
|
||||
return isOptionalProd(subProd, alreadyVisited);
|
||||
});
|
||||
}
|
||||
else if (prod instanceof NonTerminal && includes(alreadyVisited, prod)) {
|
||||
// avoiding stack overflow due to infinite recursion
|
||||
return false;
|
||||
}
|
||||
else if (prod instanceof AbstractProduction) {
|
||||
if (prod instanceof NonTerminal) {
|
||||
alreadyVisited.push(prod);
|
||||
}
|
||||
return every(prod.definition, (subProd) => {
|
||||
return isOptionalProd(subProd, alreadyVisited);
|
||||
});
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export function isBranchingProd(prod) {
|
||||
return prod instanceof Alternation;
|
||||
}
|
||||
export function getProductionDslName(prod) {
|
||||
/* istanbul ignore else */
|
||||
if (prod instanceof NonTerminal) {
|
||||
return "SUBRULE";
|
||||
}
|
||||
else if (prod instanceof Option) {
|
||||
return "OPTION";
|
||||
}
|
||||
else if (prod instanceof Alternation) {
|
||||
return "OR";
|
||||
}
|
||||
else if (prod instanceof RepetitionMandatory) {
|
||||
return "AT_LEAST_ONE";
|
||||
}
|
||||
else if (prod instanceof RepetitionMandatoryWithSeparator) {
|
||||
return "AT_LEAST_ONE_SEP";
|
||||
}
|
||||
else if (prod instanceof RepetitionWithSeparator) {
|
||||
return "MANY_SEP";
|
||||
}
|
||||
else if (prod instanceof Repetition) {
|
||||
return "MANY";
|
||||
}
|
||||
else if (prod instanceof Terminal) {
|
||||
return "CONSUME";
|
||||
/* c8 ignore next 3 */
|
||||
}
|
||||
else {
|
||||
throw Error("non exhaustive match");
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=helpers.js.map
|
||||
1
node_modules/@chevrotain/gast/lib/src/helpers.js.map
generated
vendored
Normal file
1
node_modules/@chevrotain/gast/lib/src/helpers.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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D,OAAO,KAAK,CACW,IAAK,CAAC,UAAU,EACrC,CAAC,OAAoB,EAAE,EAAE;YACvB,OAAO,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACjD,CAAC,CACF,CAAC;KACH;SAAM;QACL,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,IAAiB;IAEjB,OAAO,IAAI,YAAY,WAAW,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAA+B;IAClE,0BAA0B;IAC1B,IAAI,IAAI,YAAY,WAAW,EAAE;QAC/B,OAAO,SAAS,CAAC;KAClB;SAAM,IAAI,IAAI,YAAY,MAAM,EAAE;QACjC,OAAO,QAAQ,CAAC;KACjB;SAAM,IAAI,IAAI,YAAY,WAAW,EAAE;QACtC,OAAO,IAAI,CAAC;KACb;SAAM,IAAI,IAAI,YAAY,mBAAmB,EAAE;QAC9C,OAAO,cAAc,CAAC;KACvB;SAAM,IAAI,IAAI,YAAY,gCAAgC,EAAE;QAC3D,OAAO,kBAAkB,CAAC;KAC3B;SAAM,IAAI,IAAI,YAAY,uBAAuB,EAAE;QAClD,OAAO,UAAU,CAAC;KACnB;SAAM,IAAI,IAAI,YAAY,UAAU,EAAE;QACrC,OAAO,MAAM,CAAC;KACf;SAAM,IAAI,IAAI,YAAY,QAAQ,EAAE;QACnC,OAAO,SAAS,CAAC;QACjB,sBAAsB;KACvB;SAAM;QACL,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACrC;AACH,CAAC"}
|
||||
144
node_modules/@chevrotain/gast/lib/src/model.d.ts
generated
vendored
Normal file
144
node_modules/@chevrotain/gast/lib/src/model.d.ts
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
import type { IGASTVisitor, IProduction, IProductionWithOccurrence, ISerializedGast, TokenType } from "@chevrotain/types";
|
||||
export declare abstract class AbstractProduction<T extends IProduction = IProduction> implements IProduction {
|
||||
protected _definition: T[];
|
||||
get definition(): T[];
|
||||
set definition(value: T[]);
|
||||
constructor(_definition: T[]);
|
||||
accept(visitor: IGASTVisitor): void;
|
||||
}
|
||||
export declare class NonTerminal extends AbstractProduction implements IProductionWithOccurrence {
|
||||
nonTerminalName: string;
|
||||
label?: string;
|
||||
referencedRule: Rule;
|
||||
idx: number;
|
||||
constructor(options: {
|
||||
nonTerminalName: string;
|
||||
label?: string;
|
||||
referencedRule?: Rule;
|
||||
idx?: number;
|
||||
});
|
||||
set definition(definition: IProduction[]);
|
||||
get definition(): IProduction[];
|
||||
accept(visitor: IGASTVisitor): void;
|
||||
}
|
||||
export declare class Rule extends AbstractProduction {
|
||||
name: string;
|
||||
orgText: string;
|
||||
constructor(options: {
|
||||
name: string;
|
||||
definition: IProduction[];
|
||||
orgText?: string;
|
||||
});
|
||||
}
|
||||
export declare class Alternative extends AbstractProduction {
|
||||
ignoreAmbiguities: boolean;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
ignoreAmbiguities?: boolean;
|
||||
});
|
||||
}
|
||||
export declare class Option extends AbstractProduction implements IProductionWithOccurrence {
|
||||
idx: number;
|
||||
maxLookahead?: number;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
idx?: number;
|
||||
maxLookahead?: number;
|
||||
});
|
||||
}
|
||||
export declare class RepetitionMandatory extends AbstractProduction implements IProductionWithOccurrence {
|
||||
idx: number;
|
||||
maxLookahead?: number;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
idx?: number;
|
||||
maxLookahead?: number;
|
||||
});
|
||||
}
|
||||
export declare class RepetitionMandatoryWithSeparator extends AbstractProduction implements IProductionWithOccurrence {
|
||||
separator: TokenType;
|
||||
idx: number;
|
||||
maxLookahead?: number;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
separator: TokenType;
|
||||
idx?: number;
|
||||
});
|
||||
}
|
||||
export declare class Repetition extends AbstractProduction implements IProductionWithOccurrence {
|
||||
separator: TokenType;
|
||||
idx: number;
|
||||
maxLookahead?: number;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
idx?: number;
|
||||
maxLookahead?: number;
|
||||
});
|
||||
}
|
||||
export declare class RepetitionWithSeparator extends AbstractProduction implements IProductionWithOccurrence {
|
||||
separator: TokenType;
|
||||
idx: number;
|
||||
maxLookahead?: number;
|
||||
constructor(options: {
|
||||
definition: IProduction[];
|
||||
separator: TokenType;
|
||||
idx?: number;
|
||||
});
|
||||
}
|
||||
export declare class Alternation extends AbstractProduction<Alternative> implements IProductionWithOccurrence {
|
||||
idx: number;
|
||||
ignoreAmbiguities: boolean;
|
||||
hasPredicates: boolean;
|
||||
maxLookahead?: number;
|
||||
get definition(): Alternative[];
|
||||
set definition(value: Alternative[]);
|
||||
constructor(options: {
|
||||
definition: Alternative[];
|
||||
idx?: number;
|
||||
ignoreAmbiguities?: boolean;
|
||||
hasPredicates?: boolean;
|
||||
maxLookahead?: number;
|
||||
});
|
||||
}
|
||||
export declare class Terminal implements IProductionWithOccurrence {
|
||||
terminalType: TokenType;
|
||||
label?: string;
|
||||
idx: number;
|
||||
constructor(options: {
|
||||
terminalType: TokenType;
|
||||
label?: string;
|
||||
idx?: number;
|
||||
});
|
||||
accept(visitor: IGASTVisitor): void;
|
||||
}
|
||||
export interface ISerializedBasic extends ISerializedGast {
|
||||
type: "Alternative" | "Option" | "RepetitionMandatory" | "Repetition" | "Alternation";
|
||||
idx?: number;
|
||||
}
|
||||
export interface ISerializedGastRule extends ISerializedGast {
|
||||
type: "Rule";
|
||||
name: string;
|
||||
orgText: string;
|
||||
}
|
||||
export interface ISerializedNonTerminal extends ISerializedGast {
|
||||
type: "NonTerminal";
|
||||
name: string;
|
||||
label?: string;
|
||||
idx: number;
|
||||
}
|
||||
export interface ISerializedTerminal extends ISerializedGast {
|
||||
type: "Terminal";
|
||||
name: string;
|
||||
terminalLabel?: string;
|
||||
label?: string;
|
||||
pattern?: string;
|
||||
idx: number;
|
||||
}
|
||||
export interface ISerializedTerminalWithSeparator extends ISerializedGast {
|
||||
type: "RepetitionMandatoryWithSeparator" | "RepetitionWithSeparator";
|
||||
idx: number;
|
||||
separator: ISerializedTerminal;
|
||||
}
|
||||
export type ISerializedGastAny = ISerializedBasic | ISerializedGastRule | ISerializedNonTerminal | ISerializedTerminal | ISerializedTerminalWithSeparator;
|
||||
export declare function serializeGrammar(topRules: Rule[]): ISerializedGast[];
|
||||
export declare function serializeProduction(node: IProduction): ISerializedGast;
|
||||
225
node_modules/@chevrotain/gast/lib/src/model.js
generated
vendored
Normal file
225
node_modules/@chevrotain/gast/lib/src/model.js
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
import { assign, forEach, isRegExp, isString, map, pickBy } from "lodash-es";
|
||||
// TODO: duplicated code to avoid extracting another sub-package -- how to avoid?
|
||||
function tokenLabel(tokType) {
|
||||
if (hasTokenLabel(tokType)) {
|
||||
return tokType.LABEL;
|
||||
}
|
||||
else {
|
||||
return tokType.name;
|
||||
}
|
||||
}
|
||||
// TODO: duplicated code to avoid extracting another sub-package -- how to avoid?
|
||||
function hasTokenLabel(obj) {
|
||||
return isString(obj.LABEL) && obj.LABEL !== "";
|
||||
}
|
||||
export class AbstractProduction {
|
||||
get definition() {
|
||||
return this._definition;
|
||||
}
|
||||
set definition(value) {
|
||||
this._definition = value;
|
||||
}
|
||||
constructor(_definition) {
|
||||
this._definition = _definition;
|
||||
}
|
||||
accept(visitor) {
|
||||
visitor.visit(this);
|
||||
forEach(this.definition, (prod) => {
|
||||
prod.accept(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
|
||||
}
|
||||
}
|
||||
export class Rule extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.orgText = "";
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class Alternative extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.ignoreAmbiguities = false;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class Option extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class RepetitionMandatory extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class RepetitionMandatoryWithSeparator extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class Repetition extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class RepetitionWithSeparator extends AbstractProduction {
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class Alternation extends AbstractProduction {
|
||||
get definition() {
|
||||
return this._definition;
|
||||
}
|
||||
set definition(value) {
|
||||
this._definition = value;
|
||||
}
|
||||
constructor(options) {
|
||||
super(options.definition);
|
||||
this.idx = 1;
|
||||
this.ignoreAmbiguities = false;
|
||||
this.hasPredicates = false;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
}
|
||||
export class Terminal {
|
||||
constructor(options) {
|
||||
this.idx = 1;
|
||||
assign(this, pickBy(options, (v) => v !== undefined));
|
||||
}
|
||||
accept(visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
export function serializeGrammar(topRules) {
|
||||
return map(topRules, serializeProduction);
|
||||
}
|
||||
export function serializeProduction(node) {
|
||||
function convertDefinition(definition) {
|
||||
return map(definition, serializeProduction);
|
||||
}
|
||||
/* istanbul ignore else */
|
||||
if (node instanceof NonTerminal) {
|
||||
const serializedNonTerminal = {
|
||||
type: "NonTerminal",
|
||||
name: node.nonTerminalName,
|
||||
idx: node.idx,
|
||||
};
|
||||
if (isString(node.label)) {
|
||||
serializedNonTerminal.label = node.label;
|
||||
}
|
||||
return serializedNonTerminal;
|
||||
}
|
||||
else if (node instanceof Alternative) {
|
||||
return {
|
||||
type: "Alternative",
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof Option) {
|
||||
return {
|
||||
type: "Option",
|
||||
idx: node.idx,
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof RepetitionMandatory) {
|
||||
return {
|
||||
type: "RepetitionMandatory",
|
||||
idx: node.idx,
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof RepetitionMandatoryWithSeparator) {
|
||||
return {
|
||||
type: "RepetitionMandatoryWithSeparator",
|
||||
idx: node.idx,
|
||||
separator: (serializeProduction(new Terminal({ terminalType: node.separator }))),
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof RepetitionWithSeparator) {
|
||||
return {
|
||||
type: "RepetitionWithSeparator",
|
||||
idx: node.idx,
|
||||
separator: (serializeProduction(new Terminal({ terminalType: node.separator }))),
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof Repetition) {
|
||||
return {
|
||||
type: "Repetition",
|
||||
idx: node.idx,
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof Alternation) {
|
||||
return {
|
||||
type: "Alternation",
|
||||
idx: node.idx,
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
}
|
||||
else if (node instanceof Terminal) {
|
||||
const serializedTerminal = {
|
||||
type: "Terminal",
|
||||
name: node.terminalType.name,
|
||||
label: tokenLabel(node.terminalType),
|
||||
idx: node.idx,
|
||||
};
|
||||
if (isString(node.label)) {
|
||||
serializedTerminal.terminalLabel = node.label;
|
||||
}
|
||||
const pattern = node.terminalType.PATTERN;
|
||||
if (node.terminalType.PATTERN) {
|
||||
serializedTerminal.pattern = isRegExp(pattern)
|
||||
? pattern.source
|
||||
: pattern;
|
||||
}
|
||||
return serializedTerminal;
|
||||
}
|
||||
else if (node instanceof Rule) {
|
||||
return {
|
||||
type: "Rule",
|
||||
name: node.name,
|
||||
orgText: node.orgText,
|
||||
definition: convertDefinition(node.definition),
|
||||
};
|
||||
/* c8 ignore next 3 */
|
||||
}
|
||||
else {
|
||||
throw Error("non exhaustive match");
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=model.js.map
|
||||
1
node_modules/@chevrotain/gast/lib/src/model.js.map
generated
vendored
Normal file
1
node_modules/@chevrotain/gast/lib/src/model.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
15
node_modules/@chevrotain/gast/lib/src/visitor.d.ts
generated
vendored
Normal file
15
node_modules/@chevrotain/gast/lib/src/visitor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
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 {
|
||||
visit(node: IProduction): any;
|
||||
visitNonTerminal(node: NonTerminal): any;
|
||||
visitAlternative(node: Alternative): any;
|
||||
visitOption(node: Option): any;
|
||||
visitRepetition(node: Repetition): any;
|
||||
visitRepetitionMandatory(node: RepetitionMandatory): any;
|
||||
visitRepetitionMandatoryWithSeparator(node: RepetitionMandatoryWithSeparator): any;
|
||||
visitRepetitionWithSeparator(node: RepetitionWithSeparator): any;
|
||||
visitAlternation(node: Alternation): any;
|
||||
visitTerminal(node: Terminal): any;
|
||||
visitRule(node: Rule): any;
|
||||
}
|
||||
52
node_modules/@chevrotain/gast/lib/src/visitor.js
generated
vendored
Normal file
52
node_modules/@chevrotain/gast/lib/src/visitor.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
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 NonTerminal:
|
||||
return this.visitNonTerminal(nodeAny);
|
||||
case Alternative:
|
||||
return this.visitAlternative(nodeAny);
|
||||
case Option:
|
||||
return this.visitOption(nodeAny);
|
||||
case RepetitionMandatory:
|
||||
return this.visitRepetitionMandatory(nodeAny);
|
||||
case RepetitionMandatoryWithSeparator:
|
||||
return this.visitRepetitionMandatoryWithSeparator(nodeAny);
|
||||
case RepetitionWithSeparator:
|
||||
return this.visitRepetitionWithSeparator(nodeAny);
|
||||
case Repetition:
|
||||
return this.visitRepetition(nodeAny);
|
||||
case Alternation:
|
||||
return this.visitAlternation(nodeAny);
|
||||
case Terminal:
|
||||
return this.visitTerminal(nodeAny);
|
||||
case Rule:
|
||||
return this.visitRule(nodeAny);
|
||||
/* c8 ignore next 2 */
|
||||
default:
|
||||
throw Error("non exhaustive match");
|
||||
}
|
||||
}
|
||||
/* 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
|
||||
1
node_modules/@chevrotain/gast/lib/src/visitor.js.map
generated
vendored
Normal file
1
node_modules/@chevrotain/gast/lib/src/visitor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"visitor.js","sourceRoot":"","sources":["../../src/visitor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,gCAAgC,EAChC,uBAAuB,EACvB,IAAI,EACJ,QAAQ,GACT,MAAM,YAAY,CAAC;AAGpB,MAAM,OAAgB,WAAW;IACxB,KAAK,CAAC,IAAiB;QAC5B,MAAM,OAAO,GAAQ,IAAI,CAAC;QAC1B,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACxC,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACxC,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACnC,KAAK,mBAAmB;gBACtB,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,gCAAgC;gBACnC,OAAO,IAAI,CAAC,qCAAqC,CAAC,OAAO,CAAC,CAAC;YAC7D,KAAK,uBAAuB;gBAC1B,OAAO,IAAI,CAAC,4BAA4B,CAAC,OA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