-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from janpfeifer/errors
Improved error reporting
- Loading branch information
Showing
17 changed files
with
1,176 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Package common holds functionality that is common to multiple other packages. | ||
package common | ||
|
||
import "sort" | ||
|
||
// Set implements a Set for the key type T. | ||
type Set[T comparable] map[T]struct{} | ||
|
||
// MakeSet returns an empty Set of the given type. Size is optional, and if given | ||
// will reserve the expected size. | ||
func MakeSet[T comparable](size ...int) Set[T] { | ||
if len(size) == 0 { | ||
return make(Set[T]) | ||
} | ||
return make(Set[T], size[0]) | ||
} | ||
|
||
// Has returns true if Set s has the given key. | ||
func (s Set[T]) Has(key T) bool { | ||
_, found := s[key] | ||
return found | ||
} | ||
|
||
// Insert key into set. | ||
func (s Set[T]) Insert(key T) { | ||
s[key] = struct{}{} | ||
} | ||
|
||
// SortedKeys enumerate keys from a string map and sort them. | ||
// TODO: make it for any key type. | ||
func SortedKeys[T any](m map[string]T) (keys []string) { | ||
keys = make([]string, 0, len(m)) | ||
for key := range m { | ||
keys = append(keys, key) | ||
} | ||
sort.Strings(keys) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Package `goexec` | ||
|
||
The package `goexec` is responsible for executing the notebook cells using Go, as well as keeping the | ||
state of all current declarations (functions, variables, types, constants, imports) that once | ||
declared, stay alive for subsequent cell executions. | ||
|
||
The code is organized in the following files: | ||
|
||
* `goexec.go`: definition of the main `State` object and the various Go structs for the various declarations | ||
(functions, variables, types, constants, imports), including the concept of cursor. | ||
* `execcode.go`: implements `State.ExecuteCell()`, the main functionality offered by the package. | ||
* `composer.go`: generate dynamically a `main.go` file from pre-parsed declarations. It includes some | ||
the code that renders teh various types of declarations, and a writer that keep tabs on the cursor position. | ||
* `parser.go`: methods and objects used to parse the Go code from the cell, and again after `goimports` is run. |
Oops, something went wrong.