diff --git a/internal/pkg/auxents/repl/verbs.go b/internal/pkg/auxents/repl/verbs.go index 74d6bf867..b7a9baaf4 100644 --- a/internal/pkg/auxents/repl/verbs.go +++ b/internal/pkg/auxents/repl/verbs.go @@ -54,6 +54,7 @@ func init() { {verbNames: []string{":e", ":end"}, handlerFunc: handleEnd, usageFunc: usageEnd}, {verbNames: []string{":astprint"}, handlerFunc: handleASTPrint, usageFunc: usageASTPrint}, {verbNames: []string{":blocks"}, handlerFunc: handleBlocks, usageFunc: usageBlocks}, + {verbNames: []string{":rb", ":resetblocks"}, handlerFunc: handleResetBlocks, usageFunc: usageResetBlocks}, {verbNames: []string{":q", ":quit"}, handlerFunc: nil, usageFunc: usageQuit}, {verbNames: []string{":h", ":help"}, handlerFunc: handleHelp, usageFunc: usageHelp}, } @@ -108,11 +109,16 @@ func (repl *Repl) handleNonDSLLine(trimmedLine string) bool { // TODO: describe me if strings.HasPrefix(verbName, "??") { - handleHelpFindSingle(repl, verbName[2:]) - return true - } - if strings.HasPrefix(verbName, "?") { - handleHelpSingle(repl, verbName[1:]) + if verbName[2:] != "" { + handleHelpFindSingle(repl, verbName[2:]) + return true + } + } else if strings.HasPrefix(verbName, "?") { + if verbName[1:] != "" { + handleHelpSingle(repl, verbName[1:]) + } else { + usageHelp(repl) + } return true } @@ -818,6 +824,21 @@ func handleBlocks(repl *Repl, args []string) bool { return true } +// ---------------------------------------------------------------- +func usageResetBlocks(repl *Repl) { + fmt.Println(":resetblocks with no arguments.") + fmt.Println("Clears out all begin, main, and end blocks that have been loaded.") + +} +func handleResetBlocks(repl *Repl, args []string) bool { + args = args[1:] // strip off verb + if len(args) != 0 { + return false + } + repl.cstRootNode.ResetBlocksForREPL() + return true +} + // ---------------------------------------------------------------- func usageQuit(repl *Repl) { fmt.Println(":quit with no arguments.") diff --git a/internal/pkg/dsl/cst/root.go b/internal/pkg/dsl/cst/root.go index 4a959f722..eeaeb0c18 100644 --- a/internal/pkg/dsl/cst/root.go +++ b/internal/pkg/dsl/cst/root.go @@ -501,3 +501,10 @@ func (root *RootNode) ShowBlockReport() { fmt.Printf("#main %d\n", len(root.mainBlock.executables)) fmt.Printf("#end %d\n", len(root.endBlocks)) } + +// This is for the REPL's resetblocks command. +func (root *RootNode) ResetBlocksForREPL() { + root.beginBlocks = make([]*StatementBlockNode, 0) + root.mainBlock.executables = make([]IExecutable, 0) + root.endBlocks = make([]*StatementBlockNode, 0) +}