mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add callable closure vars
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { SlashCommand } from './SlashCommand.js';
|
||||
import { SlashCommandClosure } from './SlashCommandClosure.js';
|
||||
import { SlashCommandClosureExecutor } from './SlashCommandClosureExecutor.js';
|
||||
import { SlashCommandExecutor } from './SlashCommandExecutor.js';
|
||||
import { SlashCommandParserError } from './SlashCommandParserError.js';
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
@ -232,6 +233,9 @@ export class SlashCommandParser {
|
||||
this.discardWhitespace();
|
||||
}
|
||||
while (!this.testClosureEnd()) {
|
||||
if (this.testClosureCall()) {
|
||||
closure.executorList.push(this.parseClosureCall());
|
||||
}
|
||||
if (this.testCommand()) {
|
||||
closure.executorList.push(this.parseCommand());
|
||||
} else {
|
||||
@ -260,6 +264,37 @@ export class SlashCommandParser {
|
||||
return closure;
|
||||
}
|
||||
|
||||
testClosureCall() {
|
||||
return this.char == '/'
|
||||
&& this.behind.slice(-1) != '\\'
|
||||
&& !['/', '#'].includes(this.ahead[0])
|
||||
&& /^\S+\(/.test(this.ahead)
|
||||
;
|
||||
}
|
||||
testClosureCallEnd() {
|
||||
return this.char == ')' && this.behind.slice(-1) != '\\';
|
||||
}
|
||||
parseClosureCall() {
|
||||
this.take(); // discard /
|
||||
let name = '';
|
||||
while (!/\s|\(/.test(this.char)) name += this.take(); // take chars until opening (
|
||||
this.take(); // discard opening (
|
||||
const executor = new SlashCommandClosureExecutor();
|
||||
executor.name = name;
|
||||
this.discardWhitespace();
|
||||
while (this.testNamedArgument()) {
|
||||
const arg = this.parseNamedArgument();
|
||||
executor.providedArguments[arg.key] = arg.value;
|
||||
this.discardWhitespace();
|
||||
}
|
||||
if (this.testClosureCallEnd()) {
|
||||
this.take(); // discard closing )
|
||||
return executor;
|
||||
} else {
|
||||
throw new SlashCommandParserError(`Unexpected end of closure call at position ${this.index - 2}`, this.text, this.index);
|
||||
}
|
||||
}
|
||||
|
||||
testCommand() {
|
||||
return this.char == '/' && this.behind.slice(-1) != '\\' && !['/', '#'].includes(this.ahead[0]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user