First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
export declare class GbnfAnyJson extends GbnfTerminal {
readonly scopeState: GbnfJsonScopeState;
constructor(scopeState?: GbnfJsonScopeState);
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,53 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
import { GbnfString } from "./GbnfString.js";
import { GbnfOr } from "./GbnfOr.js";
import { GbnfNumber } from "./GbnfNumber.js";
import { GbnfBoolean } from "./GbnfBoolean.js";
import { GbnfNull } from "./GbnfNull.js";
import { GbnfArray } from "./GbnfArray.js";
import { reservedRuleNames } from "./gbnfConsts.js";
import { GbnfObjectMap } from "./GbnfObjectMap.js";
export class GbnfAnyJson extends GbnfTerminal {
scopeState;
constructor(scopeState = new GbnfJsonScopeState()) {
super();
this.scopeState = scopeState;
}
getGrammar(grammarGenerator) {
const subAnyJsonScopeItem = this.scopeState.settings.allowNewLines
? new GbnfAnyJson(new GbnfJsonScopeState({
allowNewLines: false,
scopePadSpaces: this.scopeState.settings.scopePadSpaces
}, this.scopeState.currentNestingScope))
: new GbnfSubAnyJson(this.scopeState);
return new GbnfOr([
new GbnfString(),
new GbnfNumber({ allowFractional: true }),
new GbnfBoolean(),
new GbnfNull(),
new GbnfArray({
items: subAnyJsonScopeItem,
scopeState: this.scopeState
}),
new GbnfObjectMap({
fields: [],
additionalProperties: subAnyJsonScopeItem,
scopeState: this.scopeState
})
]).getGrammar(grammarGenerator);
}
getRuleName() {
return reservedRuleNames.anyJson({
allowNewLines: this.scopeState.settings.allowNewLines,
scopeSpaces: this.scopeState.settings.scopePadSpaces,
nestingScope: this.scopeState.currentNestingScope
});
}
}
class GbnfSubAnyJson extends GbnfAnyJson {
getGrammar() {
return this.getRuleName();
}
}
//# sourceMappingURL=GbnfAnyJson.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfAnyJson.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfAnyJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,WAAY,SAAQ,YAAY;IACzB,UAAU,CAAqB;IAE/C,YAAmB,aAAiC,IAAI,kBAAkB,EAAE;QACxE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,gBAAsC;QACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;YAC9D,CAAC,CAAC,IAAI,WAAW,CACb,IAAI,kBAAkB,CAAC;gBACnB,aAAa,EAAE,KAAK;gBACpB,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;aAC1D,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAC1C;YACD,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE1C,OAAO,IAAI,MAAM,CAAC;YACd,IAAI,UAAU,EAAE;YAChB,IAAI,UAAU,CAAC,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC;YACvC,IAAI,WAAW,EAAE;YACjB,IAAI,QAAQ,EAAE;YACd,IAAI,SAAS,CAAC;gBACV,KAAK,EAAE,mBAAmB;gBAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;aAC9B,CAAC;YACF,IAAI,aAAa,CAAC;gBACd,MAAM,EAAE,EAAE;gBACV,oBAAoB,EAAE,mBAAmB;gBACzC,UAAU,EAAE,IAAI,CAAC,UAAU;aAC9B,CAAC;SACL,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,OAAO,CAAC;YAC7B,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;YACrD,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;YACpD,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB;SACpD,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,cAAe,SAAQ,WAAW;IACpB,UAAU;QACtB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;CACJ"}

View File

@@ -0,0 +1,18 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
export declare class GbnfArray extends GbnfTerminal {
readonly items?: GbnfTerminal;
readonly prefixItems?: GbnfTerminal[];
readonly minItems: number;
readonly maxItems?: number;
readonly scopeState: GbnfJsonScopeState;
constructor({ items, prefixItems, minItems, maxItems, scopeState }: {
items?: GbnfTerminal;
prefixItems?: GbnfTerminal[];
minItems?: number;
maxItems?: number;
scopeState: GbnfJsonScopeState;
});
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,83 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
import { GbnfWhitespace } from "./GbnfWhitespace.js";
import { GbnfGrammar } from "./GbnfGrammar.js";
import { GbnfRepetition } from "./GbnfRepetition.js";
import { GbnfCommaWhitespace } from "./GbnfCommaWhitespace.js";
import { GbnfAnyJson } from "./GbnfAnyJson.js";
export class GbnfArray extends GbnfTerminal {
items;
prefixItems;
minItems;
maxItems;
scopeState;
constructor({ items, prefixItems, minItems = 0, maxItems, scopeState = new GbnfJsonScopeState() }) {
super();
this.items = items;
this.prefixItems = prefixItems;
this.minItems = Math.floor(minItems);
this.maxItems = maxItems == null ? undefined : Math.floor(maxItems);
this.scopeState = scopeState;
if (this.prefixItems != null && this.minItems < this.prefixItems.length)
this.minItems = this.prefixItems.length;
else if (this.minItems < 0)
this.minItems = 0;
if (this.maxItems != null && this.maxItems < this.minItems)
this.maxItems = this.minItems;
else if (this.maxItems != null && this.maxItems < 0)
this.maxItems = 0;
}
getGrammar(grammarGenerator) {
const getWhitespaceRule = (newScope, newLine) => (newScope
? new GbnfWhitespace(this.scopeState.getForNewScope(), { newLine })
: new GbnfWhitespace(this.scopeState, { newLine }));
const getWhitespaceRuleName = (newScope, newLine) => (getWhitespaceRule(newScope, newLine).resolve(grammarGenerator));
const getCommaWhitespaceRule = (newScope, newLine) => (newScope
? new GbnfCommaWhitespace(this.scopeState.getForNewScope(), { newLine })
: new GbnfCommaWhitespace(this.scopeState, { newLine }));
const getCommaWhitespaceRuleName = (newScope, newLine) => (getCommaWhitespaceRule(newScope, newLine).resolve(grammarGenerator));
const arrayItemsGrammar = [];
if (this.prefixItems != null && this.prefixItems.length > 0) {
for (const item of this.prefixItems) {
if (arrayItemsGrammar.length > 0)
arrayItemsGrammar.push(getCommaWhitespaceRuleName(true, "before"));
arrayItemsGrammar.push(item.resolve(grammarGenerator));
}
if (this.minItems > this.prefixItems.length || this.maxItems == null || this.maxItems > this.prefixItems.length) {
const restMinRepetitions = this.minItems - this.prefixItems.length;
const restMaxRepetitions = this.maxItems == null
? undefined
: this.maxItems - this.prefixItems.length;
if (arrayItemsGrammar.length > 0)
arrayItemsGrammar.push(new GbnfRepetition({
value: new GbnfGrammar([
getCommaWhitespaceRuleName(true, "before"),
(this.items ?? new GbnfAnyJson()).resolve(grammarGenerator)
], true),
minRepetitions: restMinRepetitions,
maxRepetitions: restMaxRepetitions
}).getGrammar(grammarGenerator));
else
arrayItemsGrammar.push(new GbnfRepetition({
value: this.items ?? new GbnfAnyJson(),
separator: getCommaWhitespaceRule(true, "before"),
minRepetitions: restMinRepetitions,
maxRepetitions: restMaxRepetitions
}).getGrammar(grammarGenerator));
}
}
else
arrayItemsGrammar.push(new GbnfRepetition({
value: this.items ?? new GbnfAnyJson(),
separator: getCommaWhitespaceRule(true, "before"),
minRepetitions: this.minItems,
maxRepetitions: this.maxItems
}).getGrammar(grammarGenerator));
return new GbnfGrammar([
'"["', getWhitespaceRuleName(true, "before"),
new GbnfGrammar(arrayItemsGrammar).getGrammar(),
getWhitespaceRuleName(false, "before"), '"]"'
]).getGrammar();
}
}
//# sourceMappingURL=GbnfArray.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfArray.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAA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CAAC,gBAAgB,CAAC,CAClC,CAAC;YACV,CAAC;QACL,CAAC;;YACG,iBAAiB,CAAC,IAAI,CAClB,IAAI,cAAc,CAAC;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,WAAW,EAAE;gBACtC,SAAS,EAAE,sBAAsB,CAAC,IAAI,EAAE,QAAQ,CAAC;gBACjD,cAAc,EAAE,IAAI,CAAC,QAAQ;gBAC7B,cAAc,EAAE,IAAI,CAAC,QAAQ;aAChC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAClC,CAAC;QAEN,OAAO,IAAI,WAAW,CAAC;YACnB,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC;YAC5C,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAC,UAAU,EAAE;YAC/C,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK;SAChD,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ"}

View File

@@ -0,0 +1,7 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfBoolean extends GbnfTerminal {
getGrammar(): string;
protected getGrammarFromResolve(): string;
private _getGrammar;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,22 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
export class GbnfBoolean extends GbnfTerminal {
getGrammar() {
return this._getGrammar();
}
getGrammarFromResolve() {
return this._getGrammar(false);
}
_getGrammar(wrap = true) {
const values = ['"true"', '"false"'];
if (wrap)
return [
"(", values.join(" | "), ")"
].join(" ");
return values.join(" | ");
}
getRuleName() {
return reservedRuleNames.boolean;
}
}
//# sourceMappingURL=GbnfBoolean.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfBoolean.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;IAEkB,qBAAqB;QACpC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,OAAgB,IAAI;QACpC,MAAM,MAAM,GAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAE/C,IAAI,IAAI;YACJ,OAAO;gBACH,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG;aAC/B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEhB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,OAAO,CAAC;IACrC,CAAC;CACJ"}

View File

@@ -0,0 +1,7 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfBooleanValue extends GbnfTerminal {
readonly value: boolean;
constructor(value: boolean);
getGrammar(): string;
resolve(): string;
}

View File

@@ -0,0 +1,17 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfBooleanValue extends GbnfTerminal {
value;
constructor(value) {
super();
this.value = value;
}
getGrammar() {
if (this.value)
return '"true"';
return '"false"';
}
resolve() {
return this.getGrammar();
}
}
//# sourceMappingURL=GbnfBooleanValue.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfBooleanValue.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfBooleanValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9B,KAAK,CAAU;IAE/B,YAAmB,KAAc;QAC7B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEM,UAAU;QACb,IAAI,IAAI,CAAC,KAAK;YACV,OAAO,QAAQ,CAAC;QAEpB,OAAO,SAAS,CAAC;IACrB,CAAC;IAEe,OAAO;QACnB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;CACJ"}

View File

@@ -0,0 +1,11 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
export declare class GbnfCommaWhitespace extends GbnfTerminal {
readonly scopeState: GbnfJsonScopeState;
readonly newLine: "before" | "after" | false;
constructor(scopeState: GbnfJsonScopeState, { newLine }?: {
newLine?: "before" | "after" | false;
});
getGrammar(): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,28 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammar } from "./GbnfGrammar.js";
import { GbnfWhitespace } from "./GbnfWhitespace.js";
import { reservedRuleNames } from "./gbnfConsts.js";
export class GbnfCommaWhitespace extends GbnfTerminal {
scopeState;
newLine;
constructor(scopeState, { newLine = "before" } = {}) {
super();
this.scopeState = scopeState;
this.newLine = newLine;
}
getGrammar() {
return new GbnfGrammar([
'","', new GbnfWhitespace(this.scopeState, { newLine: this.newLine }).getGrammar()
]).getGrammar();
}
getRuleName() {
return reservedRuleNames.commaWhitespace({
newLine: this.scopeState.settings.allowNewLines
? this.newLine
: false,
scopeSpaces: this.scopeState.settings.scopePadSpaces,
nestingScope: this.scopeState.currentNestingScope
});
}
}
//# sourceMappingURL=GbnfCommaWhitespace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfCommaWhitespace.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfCommaWhitespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACjC,UAAU,CAAqB;IAC/B,OAAO,CAA6B;IAEpD,YAAmB,UAA8B,EAAE,EAC/C,OAAO,GAAG,QAAQ,KAGlB,EAAE;QACF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,WAAW,CAAC;YACnB,KAAK,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,EAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAC,CAAC,CAAC,UAAU,EAAE;SACnF,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,eAAe,CAAC;YACrC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa;gBAC3C,CAAC,CAAC,IAAI,CAAC,OAAO;gBACd,CAAC,CAAC,KAAK;YACX,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc;YACpD,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,mBAAmB;SACpD,CAAC,CAAC;IACP,CAAC;CACJ"}

View File

@@ -0,0 +1,11 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
import { GbnfJsonFormatStringSchema } from "../types.js";
export declare class GbnfFormatString extends GbnfTerminal {
readonly format: GbnfJsonFormatStringSchema["format"];
constructor(format: GbnfJsonFormatStringSchema["format"]);
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
protected getRuleName(): string;
private _getDateGrammar;
private _getTimeGrammar;
}

View File

@@ -0,0 +1,90 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
import { GbnfGrammar } from "./GbnfGrammar.js";
import { GbnfString } from "./GbnfString.js";
export class GbnfFormatString extends GbnfTerminal {
format;
constructor(format) {
super();
this.format = format;
}
getGrammar(grammarGenerator) {
const quote = '"\\""';
if (this.format === "date")
return new GbnfGrammar([
quote,
this._getDateGrammar(),
quote
]).getGrammar();
else if (this.format === "time") {
return new GbnfGrammar([
quote,
this._getTimeGrammar(),
quote
]).getGrammar();
}
else if (this.format === "date-time")
return new GbnfGrammar([
quote,
this._getDateGrammar(),
'"T"',
this._getTimeGrammar(),
quote
]).getGrammar();
return new GbnfString({
minLength: 0,
maxLength: 0
}).resolve(grammarGenerator);
}
getRuleName() {
return reservedRuleNames.formatString(this.format);
}
_getDateGrammar() {
return new GbnfGrammar([
"[0-9]{4}",
'"-"',
or([
'"0" [1-9]',
'"1" [012]'
]),
'"-"',
or([
'"0" [1-9]',
"[12] [0-9]",
'"3" [01]'
])
]).getGrammar();
}
_getTimeGrammar() {
return new GbnfGrammar([
or([
"[01] [0-9]",
'"2" [0-3]'
]),
'":"',
"[0-5] [0-9]",
'":"',
"[0-5] [0-9]",
'( "." [0-9]{3} )?',
or([
'"Z"',
new GbnfGrammar([
or([
'"+"',
'"-"'
]),
or([
"[01] [0-9]",
'"2" [0-3]'
]),
'":"',
"[0-5] [0-9]"
]).getGrammar()
])
]).getGrammar();
}
}
function or(values) {
return "(" + values.join(" | ") + ")";
}
//# sourceMappingURL=GbnfFormatString.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfFormatString.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfFormatString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAC,MAAM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ACC,WAAW;gBACX,YAAY;gBACZ,UAAU;aACb,CAAC;SACL,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEO,eAAe;QACnB,OAAO,IAAI,WAAW,CAAC;YACnB,EAAE,CAAC;gBACC,YAAY;gBACZ,WAAW;aACd,CAAC;YACF,KAAK;YACL,aAAa;YACb,KAAK;YACL,aAAa;YACb,mBAAmB;YACnB,EAAE,CAAC;gBACC,KAAK;gBACL,IAAI,WAAW,CAAC;oBACZ,EAAE,CAAC;wBACC,KAAK;wBACL,KAAK;qBACR,CAAC;oBACF,EAAE,CAAC;wBACC,YAAY;wBACZ,WAAW;qBACd,CAAC;oBACF,KAAK;oBACL,aAAa;iBAChB,CAAC,CAAC,UAAU,EAAE;aAClB,CAAC;SACL,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ;AAED,SAAS,EAAE,CAAC,MAAgB;IACxB,OAAO,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;AAC1C,CAAC"}

View File

@@ -0,0 +1,9 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfGrammar extends GbnfTerminal {
readonly grammar: string | string[];
readonly resolveToRawGrammar: boolean;
constructor(grammar: string | string[], resolveToRawGrammar?: boolean);
getGrammar(): string;
resolve(grammarGenerator: GbnfGrammarGenerator, resolveAsRootGrammar?: boolean): string;
}

View File

@@ -0,0 +1,23 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfGrammar extends GbnfTerminal {
grammar;
resolveToRawGrammar;
constructor(grammar, resolveToRawGrammar = false) {
super();
this.grammar = grammar;
this.resolveToRawGrammar = resolveToRawGrammar;
}
getGrammar() {
if (this.grammar instanceof Array)
return this.grammar
.filter((item) => item !== "")
.join(" ");
return this.grammar;
}
resolve(grammarGenerator, resolveAsRootGrammar = false) {
if (this.resolveToRawGrammar)
return this.getGrammar();
return super.resolve(grammarGenerator, resolveAsRootGrammar);
}
}
//# sourceMappingURL=GbnfGrammar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfGrammar.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfGrammar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIhD,MAAM,OAAO,WAAY,SAAQ,YAAY;IACzB,OAAO,CAAoB;IAC3B,mBAAmB,CAAU;IAE7C,YAAmB,OAA0B,EAAE,sBAA+B,KAAK;QAC/E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACnD,CAAC;IAEM,UAAU;QACb,IAAI,IAAI,CAAC,OAAO,YAAY,KAAK;YAC7B,OAAO,IAAI,CAAC,OAAO;iBACd,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;iBAC7B,IAAI,CAAC,GAAG,CAAC,CAAC;QAEnB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAEe,OAAO,CAAC,gBAAsC,EAAE,uBAAgC,KAAK;QACjG,IAAI,IAAI,CAAC,mBAAmB;YACxB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;QAE7B,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACjE,CAAC;CACJ"}

View File

@@ -0,0 +1,5 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfInsideStringChar extends GbnfTerminal {
getGrammar(): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,24 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
export class GbnfInsideStringChar extends GbnfTerminal {
getGrammar() {
return [
negatedCharacterSet([
'"',
"\\\\",
"\\x7F",
"\\x00-\\x1F"
]),
// escape sequences
'"\\\\" ["\\\\/bfnrt]',
'"\\\\u" [0-9a-fA-F]{4}'
].join(" | ");
}
getRuleName() {
return reservedRuleNames.stringChar;
}
}
function negatedCharacterSet(characterDefinitions) {
return "[^" + characterDefinitions.join("") + "]";
}
//# sourceMappingURL=GbnfInsideStringChar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfInsideStringChar.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfInsideStringChar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAElD,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAC3C,UAAU;QACb,OAAO;YACH,mBAAmB,CAAC;gBAChB,GAAG;gBACH,MAAM;gBACN,OAAO;gBACP,aAAa;aAChB,CAAC;YAEF,mBAAmB;YACnB,sBAAsB;YACtB,wBAAwB;SAC3B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,UAAU,CAAC;IACxC,CAAC;CACJ;AAED,SAAS,mBAAmB,CAAC,oBAA8B;IACvD,OAAO,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AACtD,CAAC"}

View File

@@ -0,0 +1,5 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfNull extends GbnfTerminal {
getGrammar(): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,11 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
export class GbnfNull extends GbnfTerminal {
getGrammar() {
return '"null"';
}
getRuleName() {
return reservedRuleNames.null;
}
}
//# sourceMappingURL=GbnfNull.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfNull.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfNull.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,QAAS,SAAQ,YAAY;IAC/B,UAAU;QACb,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,IAAI,CAAC;IAClC,CAAC;CACJ"}

View File

@@ -0,0 +1,9 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfNumber extends GbnfTerminal {
readonly allowFractional: boolean;
constructor({ allowFractional }: {
allowFractional: boolean;
});
getGrammar(): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,22 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
export class GbnfNumber extends GbnfTerminal {
allowFractional;
constructor({ allowFractional = true }) {
super();
this.allowFractional = allowFractional;
}
getGrammar() {
const num = '"-"? ("0" | [1-9] [0-9]{0,15})';
const exponent = ' ([eE] [-+]? ("0" | [1-9] [0-9]{0,15}))?';
if (this.allowFractional)
return num + ' ("." [0-9]{1,16})?' + exponent;
return num + exponent;
}
getRuleName() {
if (this.allowFractional)
return reservedRuleNames.number.fractional;
return reservedRuleNames.number.integer;
}
}
//# sourceMappingURL=GbnfNumber.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfNumber.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,UAAW,SAAQ,YAAY;IACxB,eAAe,CAAU;IAEzC,YAAmB,EAAC,eAAe,GAAG,IAAI,EAA6B;QACnE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAEM,UAAU;QACb,MAAM,GAAG,GAAG,gCAAgC,CAAC;QAC7C,MAAM,QAAQ,GAAG,0CAA0C,CAAC;QAE5D,IAAI,IAAI,CAAC,eAAe;YACpB,OAAO,GAAG,GAAG,qBAAqB,GAAG,QAAQ,CAAC;QAElD,OAAO,GAAG,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAEkB,WAAW;QAC1B,IAAI,IAAI,CAAC,eAAe;YACpB,OAAO,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC;QAE/C,OAAO,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC;IAC5C,CAAC;CACJ"}

View File

@@ -0,0 +1,9 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfNumberValue extends GbnfTerminal {
readonly value: number;
constructor(value: number);
getGrammar(): string;
resolve(grammarGenerator: GbnfGrammarGenerator, resolveAsRootGrammar?: boolean): string;
protected generateRuleName(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,21 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfNumberValue extends GbnfTerminal {
value;
constructor(value) {
super();
this.value = value;
}
getGrammar() {
return '"' + JSON.stringify(this.value) + '"';
}
resolve(grammarGenerator, resolveAsRootGrammar = false) {
const grammar = this.getGrammar();
if (grammar.length <= grammarGenerator.getProposedLiteralValueRuleNameLength())
return grammar;
return super.resolve(grammarGenerator, resolveAsRootGrammar);
}
generateRuleName(grammarGenerator) {
return grammarGenerator.generateRuleNameForLiteralValue(this.value);
}
}
//# sourceMappingURL=GbnfNumberValue.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfNumberValue.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfNumberValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIhD,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC7B,KAAK,CAAS;IAE9B,YAAmB,KAAa;QAC5B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEe,UAAU;QACtB,OAAO,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;IAClD,CAAC;IAEe,OAAO,CAAC,gBAAsC,EAAE,uBAAgC,KAAK;QACjG,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,OAAO,CAAC,MAAM,IAAI,gBAAgB,CAAC,qCAAqC,EAAE;YAC1E,OAAO,OAAO,CAAC;QAEnB,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACjE,CAAC;IAEkB,gBAAgB,CAAC,gBAAsC;QACtE,OAAO,gBAAgB,CAAC,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;CACJ"}

View File

@@ -0,0 +1,28 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
import { GbnfString } from "./GbnfString.js";
import { GbnfStringValue } from "./GbnfStringValue.js";
export declare class GbnfObjectMap extends GbnfTerminal {
readonly fields: Array<Readonly<{
key: GbnfString | GbnfStringValue;
value: GbnfTerminal;
required: true;
}>>;
readonly additionalProperties?: GbnfTerminal;
readonly minProperties: number;
readonly maxProperties?: number;
readonly scopeState: GbnfJsonScopeState;
constructor({ fields, additionalProperties, minProperties, maxProperties, scopeState }: {
fields: Array<Readonly<{
key: GbnfString | GbnfStringValue;
value: GbnfTerminal;
required: true;
}>>;
additionalProperties?: GbnfTerminal;
minProperties?: number;
maxProperties?: number;
scopeState?: GbnfJsonScopeState;
});
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,88 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
import { GbnfString } from "./GbnfString.js";
import { GbnfWhitespace } from "./GbnfWhitespace.js";
import { GbnfGrammar } from "./GbnfGrammar.js";
import { GbnfRepetition } from "./GbnfRepetition.js";
import { GbnfCommaWhitespace } from "./GbnfCommaWhitespace.js";
export class GbnfObjectMap extends GbnfTerminal {
fields;
additionalProperties;
minProperties;
maxProperties;
scopeState;
constructor({ fields, additionalProperties, minProperties = 0, maxProperties, scopeState = new GbnfJsonScopeState() }) {
super();
this.fields = fields;
this.additionalProperties = additionalProperties;
this.minProperties = Math.floor(minProperties);
this.maxProperties = maxProperties == null ? undefined : Math.floor(maxProperties);
this.scopeState = scopeState;
if (this.minProperties < this.fields.length)
this.minProperties = this.fields.length;
if (this.maxProperties != null && this.maxProperties < this.minProperties)
this.maxProperties = this.minProperties;
else if (this.maxProperties != null && this.maxProperties < 0)
this.maxProperties = 0;
}
getGrammar(grammarGenerator) {
const getWhitespaceRuleName = (newScope, newLine) => (newScope
? new GbnfWhitespace(this.scopeState.getForNewScope(), { newLine }).resolve(grammarGenerator)
: new GbnfWhitespace(this.scopeState, { newLine }).resolve(grammarGenerator));
const getCommaWhitespaceRule = (newScope, newLine) => (newScope
? new GbnfCommaWhitespace(this.scopeState.getForNewScope(), { newLine })
: new GbnfCommaWhitespace(this.scopeState, { newLine }));
const getCommaWhitespaceRuleName = (newScope, newLine) => (getCommaWhitespaceRule(newScope, newLine).resolve(grammarGenerator));
const objectItemsGrammar = [];
for (const { key, value } of this.fields) {
if (objectItemsGrammar.length > 0)
objectItemsGrammar.push(getCommaWhitespaceRuleName(true, "before"));
objectItemsGrammar.push(new GbnfGrammar([
key.getGrammar(grammarGenerator), '":"', "[ ]?", value.resolve(grammarGenerator)
]).getGrammar());
}
if (this.additionalProperties != null) {
const additionalPropertiesGrammar = new GbnfGrammar([
new GbnfString().resolve(grammarGenerator), '":"', "[ ]?", this.additionalProperties.resolve(grammarGenerator)
]);
if (this.minProperties > this.fields.length) {
if (objectItemsGrammar.length > 0)
objectItemsGrammar.push(getCommaWhitespaceRuleName(true, "before"));
objectItemsGrammar.push(new GbnfRepetition({
value: additionalPropertiesGrammar,
separator: getCommaWhitespaceRule(true, "before"),
minRepetitions: this.minProperties - this.fields.length,
maxRepetitions: this.maxProperties == null
? undefined
: this.maxProperties - this.fields.length
}).getGrammar(grammarGenerator));
}
else if (this.maxProperties == null || this.maxProperties > this.fields.length) {
if (objectItemsGrammar.length === 0)
objectItemsGrammar.push(new GbnfRepetition({
value: additionalPropertiesGrammar,
separator: getCommaWhitespaceRule(true, "before"),
maxRepetitions: this.maxProperties == null
? undefined
: this.maxProperties - this.fields.length
}).getGrammar(grammarGenerator));
else
objectItemsGrammar.push(new GbnfRepetition({
value: new GbnfGrammar([
getCommaWhitespaceRuleName(true, "before"),
additionalPropertiesGrammar.resolve(grammarGenerator)
], true),
maxRepetitions: this.maxProperties == null
? undefined
: this.maxProperties - this.fields.length
}).getGrammar(grammarGenerator));
}
}
return new GbnfGrammar([
'"{"', getWhitespaceRuleName(true, "before"),
new GbnfGrammar(objectItemsGrammar).getGrammar(),
getWhitespaceRuleName(false, "before"), '"}"'
]).getGrammar();
}
}
//# sourceMappingURL=GbnfObjectMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfObjectMap.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfObjectMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7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S;4BACX,CAAC,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM;qBAChD,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAClC,CAAC;;oBAEF,kBAAkB,CAAC,IAAI,CACnB,IAAI,cAAc,CAAC;wBACf,KAAK,EAAE,IAAI,WAAW,CAAC;4BACnB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,CAAC;4BAC1C,2BAA2B,CAAC,OAAO,CAAC,gBAAgB,CAAC;yBACxD,EAAE,IAAI,CAAC;wBACR,cAAc,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI;4BACtC,CAAC,CAAC,SAAS;4BACX,CAAC,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM;qBAChD,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAClC,CAAC;YACV,CAAC;QACL,CAAC;QAED,OAAO,IAAI,WAAW,CAAC;YACnB,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC;YAC5C,IAAI,WAAW,CAAC,kBAAkB,CAAC,CAAC,UAAU,EAAE;YAChD,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK;SAChD,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ"}

View File

@@ -0,0 +1,9 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfOr extends GbnfTerminal {
readonly values: readonly GbnfTerminal[];
readonly useRawGrammar: boolean;
constructor(values: readonly GbnfTerminal[], useRawGrammar?: boolean);
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
resolve(grammarGenerator: GbnfGrammarGenerator, resolveAsRootGrammar?: boolean): string;
}

View File

@@ -0,0 +1,34 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { grammarNoValue } from "./gbnfConsts.js";
export class GbnfOr extends GbnfTerminal {
values;
useRawGrammar;
constructor(values, useRawGrammar = false) {
super();
this.values = values;
this.useRawGrammar = useRawGrammar;
}
getGrammar(grammarGenerator) {
const mappedValues = this.values
.map((v) => (this.useRawGrammar
? v.getGrammar(grammarGenerator)
: v.resolve(grammarGenerator)))
.filter((value) => value !== "" && value !== grammarNoValue);
if (mappedValues.length === 0)
return grammarNoValue;
else if (mappedValues.length === 1)
return mappedValues[0];
return "( " + mappedValues.join(" | ") + " )";
}
resolve(grammarGenerator, resolveAsRootGrammar = false) {
const mappedValues = this.values
.map((v) => v.resolve(grammarGenerator))
.filter((value) => value !== "" && value !== grammarNoValue);
if (mappedValues.length === 0)
return grammarNoValue;
else if (mappedValues.length === 1)
return mappedValues[0];
return super.resolve(grammarGenerator, resolveAsRootGrammar);
}
}
//# sourceMappingURL=GbnfOr.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfOr.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfOr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAG/C,MAAM,OAAO,MAAO,SAAQ,YAAY;IACpB,MAAM,CAA0B;IAChC,aAAa,CAAU;IAEvC,YAAmB,MAA+B,EAAE,gBAAyB,KAAK;QAC9E,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAEM,UAAU,CAAC,gBAAsC;QACpD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM;aAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACR,IAAI,CAAC,aAAa;YACd,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC;YAChC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CACpC,CAAC;aACD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,cAAc,CAAC,CAAC;QAEjE,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;YACzB,OAAO,cAAc,CAAC;aACrB,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;YAC9B,OAAO,YAAY,CAAC,CAAC,CAAE,CAAC;QAE5B,OAAO,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAClD,CAAC;IAEe,OAAO,CAAC,gBAAsC,EAAE,uBAAgC,KAAK;QACjG,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM;aAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;aACvC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,cAAc,CAAC,CAAC;QAEjE,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;YACzB,OAAO,cAAc,CAAC;aACrB,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;YAC9B,OAAO,YAAY,CAAC,CAAC,CAAE,CAAC;QAE5B,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACjE,CAAC;CACJ"}

View File

@@ -0,0 +1,15 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
import { GbnfJsonSchema } from "../types.js";
export declare class GbnfRef extends GbnfTerminal {
readonly getValueTerminal: () => GbnfTerminal;
readonly defName: string;
readonly def: GbnfJsonSchema;
constructor({ getValueTerminal, defName, def }: {
getValueTerminal: () => GbnfTerminal;
defName: string;
def: GbnfJsonSchema;
});
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
protected generateRuleName(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,34 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfRef extends GbnfTerminal {
getValueTerminal;
defName;
def;
constructor({ getValueTerminal, defName, def }) {
super();
this.getValueTerminal = getValueTerminal;
this.defName = defName;
this.def = def;
}
getGrammar(grammarGenerator) {
return this.generateRuleName(grammarGenerator);
}
generateRuleName(grammarGenerator) {
if (!grammarGenerator.defRuleNames.has([this.defName, this.def])) {
const alreadyGeneratingGrammarForThisRef = grammarGenerator.defRuleNames.get([this.defName, this.def]) === null;
if (alreadyGeneratingGrammarForThisRef)
return grammarGenerator.generateRuleNameForDef(this.defName, this.def);
grammarGenerator.defRuleNames.set([this.defName, this.def], null);
const grammar = this.getValueTerminal().resolve(grammarGenerator);
if (grammarGenerator.rules.has(grammar) && grammarGenerator.defRuleNames.get([this.defName, this.def]) === null) {
grammarGenerator.defRuleNames.set([this.defName, this.def], grammar);
return grammar;
}
const ruleName = grammarGenerator.generateRuleNameForDef(this.defName, this.def);
grammarGenerator.rules.set(ruleName, grammar);
grammarGenerator.ruleContentToRuleName.set(grammar, ruleName);
return ruleName;
}
return grammarGenerator.generateRuleNameForDef(this.defName, this.def);
}
}
//# sourceMappingURL=GbnfRef.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfRef.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAKhD,MAAM,OAAO,OAAQ,SAAQ,YAAY;IACrB,gBAAgB,CAAqB;IACrC,OAAO,CAAS;IAChB,GAAG,CAAiB;IAEpC,YAAmB,EACf,gBAAgB,EAChB,OAAO,EACP,GAAG,EAKN;QACG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,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AAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9C,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAE9D,OAAO,QAAQ,CAAC;QACpB,CAAC;QAED,OAAO,gBAAgB,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;CACJ"}

View File

@@ -0,0 +1,15 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfRepetition extends GbnfTerminal {
readonly value: GbnfTerminal;
readonly separator?: GbnfTerminal;
readonly minRepetitions: number;
readonly maxRepetitions: number | null;
constructor({ value, separator, minRepetitions, maxRepetitions }: {
value: GbnfTerminal;
separator?: GbnfTerminal;
minRepetitions?: number;
maxRepetitions?: number | null;
});
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,86 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammar } from "./GbnfGrammar.js";
import { grammarNoValue } from "./gbnfConsts.js";
export class GbnfRepetition extends GbnfTerminal {
value;
separator;
minRepetitions;
maxRepetitions;
constructor({ value, separator, minRepetitions = 0, maxRepetitions }) {
super();
this.value = value;
this.separator = separator;
this.minRepetitions = Math.floor(minRepetitions);
this.maxRepetitions = maxRepetitions == null ? null : Math.floor(maxRepetitions);
if (this.minRepetitions < 0)
this.minRepetitions = 0;
if (this.maxRepetitions != null && this.maxRepetitions < 0)
this.maxRepetitions = 0;
if (this.maxRepetitions != null && this.maxRepetitions < this.minRepetitions)
this.maxRepetitions = this.minRepetitions;
}
getGrammar(grammarGenerator) {
if (this.maxRepetitions === 0)
return grammarNoValue;
const resolvedValue = this.value.resolve(grammarGenerator);
const resolvedSeparator = this.separator?.resolve(grammarGenerator);
if (this.minRepetitions === 0 && this.maxRepetitions == 1)
return new GbnfGrammar(["(", resolvedValue, ")?"]).getGrammar();
else if (this.minRepetitions === 1 && this.maxRepetitions === 1)
return resolvedValue;
else if (this.minRepetitions === this.maxRepetitions) {
if (resolvedSeparator == null)
return new GbnfGrammar(["(", resolvedValue, "){" + String(this.minRepetitions) + "}"]).getGrammar();
if (this.minRepetitions === 2)
return new GbnfGrammar([resolvedValue, resolvedSeparator, resolvedValue]).getGrammar();
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, "){" + String(this.minRepetitions - 1) + "}"
]).getGrammar();
}
else if (this.minRepetitions === 0 && this.maxRepetitions == null) {
if (resolvedSeparator == null)
return new GbnfGrammar(["(", resolvedValue, ")*"]).getGrammar();
return new GbnfGrammar([
"(", resolvedValue, "(", resolvedSeparator, resolvedValue, ")*", ")?"
]).getGrammar();
}
else if (this.minRepetitions === 1 && this.maxRepetitions == null) {
if (resolvedSeparator == null)
return new GbnfGrammar(["(", resolvedValue, ")+"]).getGrammar();
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, ")*"
]).getGrammar();
}
else if (this.maxRepetitions == null) {
if (resolvedSeparator == null)
return new GbnfGrammar(["(", resolvedValue, "){" + String(this.minRepetitions) + ",}"]).getGrammar();
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, "){" + String(this.minRepetitions - 1) + ",}"
]).getGrammar();
}
if (resolvedSeparator == null)
return new GbnfGrammar(["(", resolvedValue, "){" + String(this.minRepetitions) + "," + String(this.maxRepetitions) + "}"]).getGrammar();
if (this.minRepetitions === 0) {
if (this.maxRepetitions === 2)
return new GbnfGrammar([
"(", resolvedValue, "(", resolvedSeparator, resolvedValue, ")?", ")?"
]).getGrammar();
return new GbnfGrammar([
"(", resolvedValue, "(", resolvedSeparator, resolvedValue, "){0," + String(this.maxRepetitions - 1) + "}", ")?"
]).getGrammar();
}
else if (this.minRepetitions === 1) {
if (this.maxRepetitions === 2)
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, ")?"
]).getGrammar();
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, "){0," + String(this.maxRepetitions - 1) + "}"
]).getGrammar();
}
return new GbnfGrammar([
resolvedValue, "(", resolvedSeparator, resolvedValue, "){" + String(this.minRepetitions - 1) + "," + String(this.maxRepetitions - 1) + "}"
]).getGrammar();
}
}
//# sourceMappingURL=GbnfRepetition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfRepetition.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfRepetition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAG/C,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC5B,KAAK,CAAe;IACpB,SAAS,CAAgB;IACzB,cAAc,CAAS;IACvB,cAAc,CAAgB;IAE9C,YAAmB,EAAC,KAAK,EAAE,SAAS,EAAE,cAAc,GAAG,CAAC,EAAE,cAAc,EAEvE;QACG,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAEjF,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC;YACvB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QAE5B,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC;YACtD,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QAE5B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;QAED,OAAO,IAAI,WAAW,CAAC;YACnB,aAAa,EAAE,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,GAAG,GAAG;SAC7I,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ"}

View File

@@ -0,0 +1,12 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfString extends GbnfTerminal {
readonly minLength: number;
readonly maxLength?: number;
constructor({ minLength, maxLength }?: {
minLength?: number;
maxLength?: number;
});
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,43 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
import { GbnfRepetition } from "./GbnfRepetition.js";
import { GbnfInsideStringChar } from "./GbnfInsideStringChar.js";
export class GbnfString extends GbnfTerminal {
minLength;
maxLength;
constructor({ minLength = 0, maxLength } = {}) {
super();
this.minLength = Math.floor(minLength ?? 0);
this.maxLength = maxLength == null ? undefined : Math.floor(maxLength);
if (this.minLength < 0)
this.minLength = 0;
if (this.maxLength != null && this.maxLength < this.minLength)
this.maxLength = this.minLength;
}
getGrammar(grammarGenerator) {
if (this.minLength == 0 && this.maxLength == null)
return [
'"\\""',
new GbnfInsideStringChar().resolve(grammarGenerator) + "*",
'"\\""'
].join(" ");
else if (this.minLength == 0 && this.maxLength == 0)
return '"\\"\\""';
return [
'"\\""',
new GbnfRepetition({
value: new GbnfInsideStringChar(),
minRepetitions: this.minLength,
maxRepetitions: this.maxLength
}).getGrammar(grammarGenerator),
'"\\""'
].join(" ");
}
getRuleName() {
return reservedRuleNames.string({
minLength: this.minLength,
maxLength: this.maxLength
});
}
}
//# sourceMappingURL=GbnfString.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfString.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAG/D,MAAM,OAAO,UAAW,SAAQ,YAAY;IACxB,SAAS,CAAS;IAClB,SAAS,CAAU;IAEnC,YAAmB,EACf,SAAS,GAAG,CAAC,EACb,SAAS,KAIT,EAAE;QACF,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEvE,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC;YAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QAEvB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS;YACzD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACxC,CAAC;IAEM,UAAU,CAAC,gBAAsC;QACpD,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI;YAC7C,OAAO;gBACH,OAAO;gBACP,IAAI,oBAAoB,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,GAAG;gBAC1D,OAAO;aACV,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACX,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC;YAC/C,OAAO,UAAU,CAAC;QAEtB,OAAO;YACH,OAAO;YACP,IAAI,cAAc,CAAC;gBACf,KAAK,EAAE,IAAI,oBAAoB,EAAE;gBACjC,cAAc,EAAE,IAAI,CAAC,SAAS;gBAC9B,cAAc,EAAE,IAAI,CAAC,SAAS;aACjC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC;YAC/B,OAAO;SACV,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,MAAM,CAAC;YAC5B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAC,CAAC;IACP,CAAC;CACJ"}

View File

@@ -0,0 +1,8 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
export declare class GbnfStringValue extends GbnfTerminal {
readonly value: string;
constructor(value: string);
getGrammar(): string;
protected generateRuleName(grammarGenerator: GbnfGrammarGenerator): string;
}

View File

@@ -0,0 +1,26 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfStringValue extends GbnfTerminal {
value;
constructor(value) {
super();
this.value = value;
}
getGrammar() {
return [
'"',
'\\"',
this.value
.replaceAll("\\", "\\\\\\\\")
.replaceAll("\t", "\\\\t")
.replaceAll("\r", "\\\\r")
.replaceAll("\n", "\\\\n")
.replaceAll('"', "\\\\" + '\\"'),
'\\"',
'"'
].join("");
}
generateRuleName(grammarGenerator) {
return grammarGenerator.generateRuleNameForLiteralValue(this.value);
}
}
//# sourceMappingURL=GbnfStringValue.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfStringValue.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfStringValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIhD,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC7B,KAAK,CAAS;IAE9B,YAAmB,KAAa;QAC5B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEe,UAAU;QACtB,OAAO;YACH,GAAG;YACH,KAAK;YACL,IAAI,CAAC,KAAK;iBACL,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC;iBAC5B,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;iBACzB,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;iBACzB,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;iBACzB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;YACpC,KAAK;YACL,GAAG;SACN,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;IAEkB,gBAAgB,CAAC,gBAAsC;QACtE,OAAO,gBAAgB,CAAC,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;CACJ"}

View File

@@ -0,0 +1,6 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export declare class GbnfVerbatimText extends GbnfTerminal {
readonly value: string;
constructor(value: string);
getGrammar(): string;
}

View File

@@ -0,0 +1,21 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
export class GbnfVerbatimText extends GbnfTerminal {
value;
constructor(value) {
super();
this.value = value;
}
getGrammar() {
return [
'"',
this.value
.replaceAll("\\", "\\\\")
.replaceAll('"', '\\"')
.replaceAll("\t", "\\t")
.replaceAll("\r", "\\r")
.replaceAll("\n", "\\n"),
'"'
].join("");
}
}
//# sourceMappingURL=GbnfVerbatimText.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfVerbatimText.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfVerbatimText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAC9B,KAAK,CAAS;IAE9B,YAAmB,KAAa;QAC5B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAEe,UAAU;QACtB,OAAO;YACH,GAAG;YACH,IAAI,CAAC,KAAK;iBACL,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;iBACxB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;iBACtB,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC;iBACvB,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC;iBACvB,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC;YAC5B,GAAG;SACN,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;CACJ"}

View File

@@ -0,0 +1,13 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
export declare class GbnfWhitespace extends GbnfTerminal {
readonly scopeState: GbnfJsonScopeState;
readonly newLine: "before" | "after" | false;
constructor(scopeState: GbnfJsonScopeState, { newLine }?: {
newLine?: "before" | "after" | false;
});
getGrammar(): string;
protected getGrammarFromResolve(): string;
private _getGrammar;
protected getRuleName(): string;
}

View File

@@ -0,0 +1,67 @@
import { GbnfTerminal } from "../GbnfTerminal.js";
import { reservedRuleNames } from "./gbnfConsts.js";
import { GbnfVerbatimText } from "./GbnfVerbatimText.js";
export class GbnfWhitespace extends GbnfTerminal {
scopeState;
newLine;
constructor(scopeState, { newLine = "before" } = {}) {
super();
this.scopeState = scopeState;
this.newLine = newLine;
}
getGrammar() {
return this._getGrammar();
}
getGrammarFromResolve() {
return this._getGrammar(false);
}
_getGrammar(wrap = true) {
if (this.scopeState.settings.allowNewLines && this.newLine !== false) {
const values = [
...(this.newLine === "before"
? ["[\\n]"]
: []),
...(this.scopeState.currentNestingScope === 0
? []
: [
or([
verbatimTextRepetition(" ", this.scopeState.currentNestingScope * this.scopeState.settings.scopePadSpaces),
verbatimTextRepetition("\t", this.scopeState.currentNestingScope)
])
]),
...(this.newLine === "after"
? ["[\\n]"]
: [])
];
return or([
values.join(" "),
"[ ]?"
], wrap);
}
return "[ ]?";
}
getRuleName() {
return reservedRuleNames.whitespace({
newLine: this.scopeState.settings.allowNewLines
? this.newLine
: false,
scopeSpaces: this.scopeState.settings.scopePadSpaces,
nestingScope: this.scopeState.currentNestingScope
});
}
}
function or(definitions, wrap = true) {
if (!wrap)
return definitions.join(" | ");
return "(" + definitions.join(" | ") + ")";
}
function verbatimTextRepetition(text, count) {
const textRepetitionGrammar = new GbnfVerbatimText(text.repeat(count)).getGrammar();
if (count <= 1)
return textRepetitionGrammar;
const textRepetitionGrammarWithRepetition = new GbnfVerbatimText(text).getGrammar() + "{" + count + "}";
if (textRepetitionGrammarWithRepetition.length < textRepetitionGrammar.length)
return textRepetitionGrammarWithRepetition;
return textRepetitionGrammar;
}
//# sourceMappingURL=GbnfWhitespace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GbnfWhitespace.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfWhitespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAGvD,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC5B,UAAU,CAAqB;IAC/B,OAAO,CAA6B;IAEpD,YAAmB,UAA8B,EAAE,EAC/C,OAAO,GAAG,QAAQ,KAGlB,EAAE;QACF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;IAE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,CAAC,UAAU,CAAC,mBAAmB;SACpD,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,EAAE,CAAC,WAAqB,EAAE,OAAgB,IAAI;IACnD,IAAI,CAAC,IAAI;QACL,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEnC,OAAO,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;AAC/C,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY,EAAE,KAAa;IACvD,MAAM,qBAAqB,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAEpF,IAAI,KAAK,IAAI,CAAC;QACV,OAAO,qBAAqB,CAAC;IAEjC,MAAM,mCAAmC,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACxG,IAAI,mCAAmC,CAAC,MAAM,GAAG,qBAAqB,CAAC,MAAM;QACzE,OAAO,mCAAmC,CAAC;IAE/C,OAAO,qBAAqB,CAAC;AACjC,CAAC"}

View File

@@ -0,0 +1,30 @@
export declare const grammarNoValue = "\"\"";
export declare const reservedRuleNames: {
readonly null: "null-rule";
readonly boolean: "boolean-rule";
readonly number: {
readonly fractional: "fractional-number-rule";
readonly integer: "integer-number-rule";
};
readonly stringChar: "string-char-rule";
readonly string: ({ minLength, maxLength }: {
minLength: number;
maxLength?: number;
}) => string;
readonly formatString: (format: string) => string;
readonly whitespace: ({ newLine, nestingScope, scopeSpaces }: {
newLine?: "before" | "after" | false;
nestingScope: number;
scopeSpaces: number;
}) => string;
readonly commaWhitespace: ({ newLine, nestingScope, scopeSpaces }: {
newLine?: "before" | "after" | false;
nestingScope: number;
scopeSpaces: number;
}) => string;
readonly anyJson: ({ allowNewLines, nestingScope, scopeSpaces }: {
allowNewLines: boolean;
nestingScope: number;
scopeSpaces: number;
}) => string;
};

View File

@@ -0,0 +1,72 @@
export const grammarNoValue = '""';
export const reservedRuleNames = {
null: "null-rule",
boolean: "boolean-rule",
number: {
fractional: "fractional-number-rule",
integer: "integer-number-rule"
},
stringChar: "string-char-rule",
string({ minLength, maxLength }) {
if (minLength === 0 && maxLength == null)
return "string-rule";
else if (maxLength == null)
return [
"string-",
minLength,
"-rule"
].join("");
return [
"string-",
minLength,
"-",
maxLength,
"-rule"
].join("");
},
formatString(format) {
return "string-format-" + format + "-rule";
},
whitespace({ newLine, nestingScope, scopeSpaces }) {
if (!newLine)
return "whitespace-no-new-lines-rule";
return [
"whitespace-",
newLine === "before"
? "b"
: newLine === "after"
? "a"
: "n",
"-" + nestingScope,
"-" + scopeSpaces,
"-rule"
].join("");
},
commaWhitespace({ newLine, nestingScope, scopeSpaces }) {
if (!newLine)
return "comma-whitespace-no-new-lines-rule";
return [
"comma-whitespace-",
newLine === "before"
? "b"
: newLine === "after"
? "a"
: "n",
"-" + nestingScope,
"-" + scopeSpaces,
"-rule"
].join("");
},
anyJson({ allowNewLines, nestingScope, scopeSpaces }) {
return [
"any-json-",
!allowNewLines
? "s-"
: "",
nestingScope,
"-" + scopeSpaces,
"-rule"
].join("");
}
};
//# sourceMappingURL=gbnfConsts.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"gbnfConsts.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/gbnfConsts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC7B,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE;QACJ,UAAU,EAAE,wBAAwB;QACpC,OAAO,EAAE,qBAAqB;KACjC;IACD,UAAU,EAAE,kBAAkB;IAC9B,MAAM,CAAC,EAAC,SAAS,EAAE,SAAS,EAA0C;QAClE,IAAI,SAAS,KAAK,CAAC,IAA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