Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :resetblocks / :rb to REPL #920

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions internal/pkg/auxents/repl/verbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.")
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/dsl/cst/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}