The Poltergeist's Interpreter
Define an arcane grammar to parse and execute custom haunting scripts, translating strings into ghostly actions.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Ectoplasmic Parsing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class Expression {
Interpret(context) {
throw Error("Not implemented")
}
}
class TypeExpression extends Expression {
__New(text) {
this.text := text
}
Interpret(context) {
Send(this.text)
}
}
class WaitExpression extends Expression {
__New(time) {
this.time := time
}
Interpret(context) {
Sleep(this.time)
}
}
; A simplistic parser that translates a script into expressions
script := "TYPE:Boo WAIT:500 TYPE:!"
actions := []
Loop Parse, script, A_Space
{
parts := StrSplit(A_LoopField, ":")
if (parts[1] == "TYPE") {
actions.Push(TypeExpression(parts[2]))
} else if (parts[1] == "WAIT") {
actions.Push(WaitExpression(parts[2]))
}
}
for index, expr in actions {
expr.Interpret("")
}
Runic Tags:
#autohotkey
#interpreter
#automation
#poltergeist