First upload version 0.0.1
This commit is contained in:
43
node_modules/node-llama-cpp/dist/utils/gbnfJson/terminals/GbnfString.js
generated
vendored
Normal file
43
node_modules/node-llama-cpp/dist/utils/gbnfJson/terminals/GbnfString.js
generated
vendored
Normal 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
|
||||
Reference in New Issue
Block a user