add /break to break out of loops

This commit is contained in:
LenAnderson
2024-06-24 08:36:39 -04:00
parent 914e8eb4cf
commit c4c3218424
5 changed files with 55 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import { MacroAutoCompleteOption } from '../autocomplete/MacroAutoCompleteOption
import { SlashCommandBreakPoint } from './SlashCommandBreakPoint.js';
import { SlashCommandDebugController } from './SlashCommandDebugController.js';
import { commonEnumProviders } from './SlashCommandCommonEnumsProvider.js';
import { SlashCommandBreak } from './SlashCommandBreak.js';
/** @typedef {import('./SlashCommand.js').NamedArgumentsCapture} NamedArgumentsCapture */
/** @typedef {import('./SlashCommand.js').NamedArguments} NamedArguments */
@ -162,6 +163,11 @@ export class SlashCommandParser {
helpString: 'Set a breakpoint for debugging in the QR Editor.',
}));
}
if (!Object.keys(this.commands).includes('break')) {
SlashCommandParser.addCommandObjectUnsafe(SlashCommand.fromProps({ name: 'break',
helpString: 'Break out of a loop.',
}));
}
//TODO should not be re-registered from every instance
this.registerLanguage();
@ -644,6 +650,9 @@ export class SlashCommandParser {
if (this.debugController) {
closure.executorList.push(bp);
}
} else if (this.testBreak()) {
const b = this.parseBreak();
closure.executorList.push(b);
} else if (this.testCommand()) {
const cmd = this.parseCommand();
cmd.injectPipe = injectPipe;
@ -687,6 +696,18 @@ export class SlashCommandParser {
return bp;
}
testBreak() {
return this.testSymbol(/\/break(\s|\||$)/);
}
parseBreak() {
const b = new SlashCommandBreak();
b.start = this.index + 1;
this.take('/break'.length);
b.end = this.index;
this.commandIndex.push(b);
return b;
}
testComment() {
return this.testSymbol(/\/[/#]/);
}