2026-02-10 04:15:33 +00:00
|
|
|
import {Command, joinDestructured, ParseContext, StrTerm, unwrapDestructured, wrapString} from "./command.js";
|
2025-11-12 03:37:32 +00:00
|
|
|
import {LexInput} from "../lexer.js";
|
2026-02-10 04:15:33 +00:00
|
|
|
import {StrVM} from "../vm.js";
|
|
|
|
|
import {Awaitable} from "../../util/types.js";
|
2025-11-12 03:37:32 +00:00
|
|
|
|
2026-02-10 04:15:33 +00:00
|
|
|
export class Join extends Command<{ with?: StrTerm }> {
|
|
|
|
|
attemptParse(context: ParseContext): { with?: StrTerm } {
|
2025-11-12 03:37:32 +00:00
|
|
|
return {
|
2026-02-10 04:15:33 +00:00
|
|
|
with: context.popOptionalTerm(),
|
2025-11-12 03:37:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayName(): string {
|
|
|
|
|
return 'join'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isParseCandidate(token: LexInput): boolean {
|
|
|
|
|
return this.isKeyword(token, 'join')
|
|
|
|
|
}
|
2026-02-10 04:15:33 +00:00
|
|
|
|
|
|
|
|
execute(vm: StrVM, data: { with?: StrTerm }): Awaitable<StrVM> {
|
2026-02-10 05:49:30 +00:00
|
|
|
return vm.replaceContextMatchingTerm(ctx => ({
|
|
|
|
|
restructure: parts => {
|
2026-02-10 04:15:33 +00:00
|
|
|
if ( data.with ) {
|
2026-02-10 05:49:30 +00:00
|
|
|
return parts
|
|
|
|
|
.map(part => part.value)
|
|
|
|
|
.join(ctx.resolveString(data.with))
|
2026-02-10 04:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 05:49:30 +00:00
|
|
|
return joinDestructured(parts)
|
|
|
|
|
}
|
|
|
|
|
}))
|
2026-02-10 04:15:33 +00:00
|
|
|
}
|
2025-11-12 03:37:32 +00:00
|
|
|
}
|