id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
8,900
matryer/moq
pkg/moq/moq.go
New
func New(src, packageName string) (*Mocker, error) { srcPkg, err := pkgInfoFromPath(src, packages.LoadSyntax) if err != nil { return nil, fmt.Errorf("Couldn't load source package: %s", err) } pkgPath := srcPkg.PkgPath if len(packageName) == 0 { packageName = srcPkg.Name } else { mockPkgPath := filepath.Joi...
go
func New(src, packageName string) (*Mocker, error) { srcPkg, err := pkgInfoFromPath(src, packages.LoadSyntax) if err != nil { return nil, fmt.Errorf("Couldn't load source package: %s", err) } pkgPath := srcPkg.PkgPath if len(packageName) == 0 { packageName = srcPkg.Name } else { mockPkgPath := filepath.Joi...
[ "func", "New", "(", "src", ",", "packageName", "string", ")", "(", "*", "Mocker", ",", "error", ")", "{", "srcPkg", ",", "err", ":=", "pkgInfoFromPath", "(", "src", ",", "packages", ".", "LoadSyntax", ")", "\n", "if", "err", "!=", "nil", "{", "return...
// New makes a new Mocker for the specified package directory.
[ "New", "makes", "a", "new", "Mocker", "for", "the", "specified", "package", "directory", "." ]
6cfb0558e1bd81d19c9909483c39e199634fed29
https://github.com/matryer/moq/blob/6cfb0558e1bd81d19c9909483c39e199634fed29/pkg/moq/moq.go#L73-L105
8,901
matryer/moq
pkg/moq/moq.go
Mock
func (m *Mocker) Mock(w io.Writer, name ...string) error { if len(name) == 0 { return errors.New("must specify one interface") } doc := doc{ PackageName: m.pkgName, Imports: moqImports, } mocksMethods := false tpkg := m.srcPkg.Types for _, n := range name { iface := tpkg.Scope().Lookup(n) if ifa...
go
func (m *Mocker) Mock(w io.Writer, name ...string) error { if len(name) == 0 { return errors.New("must specify one interface") } doc := doc{ PackageName: m.pkgName, Imports: moqImports, } mocksMethods := false tpkg := m.srcPkg.Types for _, n := range name { iface := tpkg.Scope().Lookup(n) if ifa...
[ "func", "(", "m", "*", "Mocker", ")", "Mock", "(", "w", "io", ".", "Writer", ",", "name", "...", "string", ")", "error", "{", "if", "len", "(", "name", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\...
// Mock generates a mock for the specified interface name.
[ "Mock", "generates", "a", "mock", "for", "the", "specified", "interface", "name", "." ]
6cfb0558e1bd81d19c9909483c39e199634fed29
https://github.com/matryer/moq/blob/6cfb0558e1bd81d19c9909483c39e199634fed29/pkg/moq/moq.go#L108-L173
8,902
thejerf/suture
supervisor.go
Stop
func (s *Supervisor) Stop() { s.Lock() if s.state == notRunning { s.state = terminated s.Unlock() return } s.state = terminated s.Unlock() done := make(chan struct{}) if s.sendControl(stopSupervisor{done}) { <-done } }
go
func (s *Supervisor) Stop() { s.Lock() if s.state == notRunning { s.state = terminated s.Unlock() return } s.state = terminated s.Unlock() done := make(chan struct{}) if s.sendControl(stopSupervisor{done}) { <-done } }
[ "func", "(", "s", "*", "Supervisor", ")", "Stop", "(", ")", "{", "s", ".", "Lock", "(", ")", "\n", "if", "s", ".", "state", "==", "notRunning", "{", "s", ".", "state", "=", "terminated", "\n", "s", ".", "Unlock", "(", ")", "\n", "return", "\n",...
// Stop stops the Supervisor. // // This function will not return until either all Services have stopped, or // they timeout after the timeout value given to the Supervisor at // creation.
[ "Stop", "stops", "the", "Supervisor", ".", "This", "function", "will", "not", "return", "until", "either", "all", "Services", "have", "stopped", "or", "they", "timeout", "after", "the", "timeout", "value", "given", "to", "the", "Supervisor", "at", "creation", ...
e97a74fdc74a2ddc29931e289bf419891b491712
https://github.com/thejerf/suture/blob/e97a74fdc74a2ddc29931e289bf419891b491712/supervisor.go#L526-L540
8,903
ericchiang/k8s
client.go
NewClient
func NewClient(config *Config) (*Client, error) { if len(config.Contexts) == 0 { if config.CurrentContext != "" { return nil, fmt.Errorf("no contexts with name %q", config.CurrentContext) } if n := len(config.Clusters); n == 0 { return nil, errors.New("no clusters provided") } else if n > 1 { return ...
go
func NewClient(config *Config) (*Client, error) { if len(config.Contexts) == 0 { if config.CurrentContext != "" { return nil, fmt.Errorf("no contexts with name %q", config.CurrentContext) } if n := len(config.Clusters); n == 0 { return nil, errors.New("no clusters provided") } else if n > 1 { return ...
[ "func", "NewClient", "(", "config", "*", "Config", ")", "(", "*", "Client", ",", "error", ")", "{", "if", "len", "(", "config", ".", "Contexts", ")", "==", "0", "{", "if", "config", ".", "CurrentContext", "!=", "\"", "\"", "{", "return", "nil", ","...
// NewClient initializes a client from a client config.
[ "NewClient", "initializes", "a", "client", "from", "a", "client", "config", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/client.go#L137-L211
8,904
ericchiang/k8s
client.go
NewInClusterClient
func NewInClusterClient() (*Client, error) { host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT") if len(host) == 0 || len(port) == 0 { return nil, errors.New("unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined") } names...
go
func NewInClusterClient() (*Client, error) { host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT") if len(host) == 0 || len(port) == 0 { return nil, errors.New("unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined") } names...
[ "func", "NewInClusterClient", "(", ")", "(", "*", "Client", ",", "error", ")", "{", "host", ",", "port", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "len", "(", "host", ")", "==",...
// NewInClusterClient returns a client that uses the service account bearer token mounted // into Kubernetes pods.
[ "NewInClusterClient", "returns", "a", "client", "that", "uses", "the", "service", "account", "bearer", "token", "mounted", "into", "Kubernetes", "pods", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/client.go#L215-L235
8,905
ericchiang/k8s
examples/api-errors.go
createConfigMap
func createConfigMap(client *k8s.Client, name string, values map[string]string) error { cm := &v1.ConfigMap{ Metadata: &metav1.ObjectMeta{ Name: &name, Namespace: &client.Namespace, }, Data: values, } err := client.Create(context.Background(), cm) // If an HTTP error was returned by the API serve...
go
func createConfigMap(client *k8s.Client, name string, values map[string]string) error { cm := &v1.ConfigMap{ Metadata: &metav1.ObjectMeta{ Name: &name, Namespace: &client.Namespace, }, Data: values, } err := client.Create(context.Background(), cm) // If an HTTP error was returned by the API serve...
[ "func", "createConfigMap", "(", "client", "*", "k8s", ".", "Client", ",", "name", "string", ",", "values", "map", "[", "string", "]", "string", ")", "error", "{", "cm", ":=", "&", "v1", ".", "ConfigMap", "{", "Metadata", ":", "&", "metav1", ".", "Obj...
// createConfigMap creates a configmap in the client's default namespace // but does not return an error if a configmap of the same name already // exists.
[ "createConfigMap", "creates", "a", "configmap", "in", "the", "client", "s", "default", "namespace", "but", "does", "not", "return", "an", "error", "if", "a", "configmap", "of", "the", "same", "name", "already", "exists", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/examples/api-errors.go#L18-L38
8,906
ericchiang/k8s
labels.go
Eq
func (l *LabelSelector) Eq(key, val string) { if !validLabelValue(key) || !validLabelValue(val) { return } l.stmts = append(l.stmts, key+"="+val) }
go
func (l *LabelSelector) Eq(key, val string) { if !validLabelValue(key) || !validLabelValue(val) { return } l.stmts = append(l.stmts, key+"="+val) }
[ "func", "(", "l", "*", "LabelSelector", ")", "Eq", "(", "key", ",", "val", "string", ")", "{", "if", "!", "validLabelValue", "(", "key", ")", "||", "!", "validLabelValue", "(", "val", ")", "{", "return", "\n", "}", "\n", "l", ".", "stmts", "=", "...
// Eq selects labels which have the key and the key has the provide value.
[ "Eq", "selects", "labels", "which", "have", "the", "key", "and", "the", "key", "has", "the", "provide", "value", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/labels.go#L47-L52
8,907
ericchiang/k8s
labels.go
In
func (l *LabelSelector) In(key string, vals ...string) { if !validLabelValue(key) || len(vals) == 0 { return } for _, val := range vals { if !validLabelValue(val) { return } } l.stmts = append(l.stmts, key+" in ("+strings.Join(vals, ", ")+")") }
go
func (l *LabelSelector) In(key string, vals ...string) { if !validLabelValue(key) || len(vals) == 0 { return } for _, val := range vals { if !validLabelValue(val) { return } } l.stmts = append(l.stmts, key+" in ("+strings.Join(vals, ", ")+")") }
[ "func", "(", "l", "*", "LabelSelector", ")", "In", "(", "key", "string", ",", "vals", "...", "string", ")", "{", "if", "!", "validLabelValue", "(", "key", ")", "||", "len", "(", "vals", ")", "==", "0", "{", "return", "\n", "}", "\n", "for", "_", ...
// In selects labels which have the key and the key has one of the provided values.
[ "In", "selects", "labels", "which", "have", "the", "key", "and", "the", "key", "has", "one", "of", "the", "provided", "values", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/labels.go#L64-L74
8,908
ericchiang/k8s
resource.go
QueryParam
func QueryParam(name, value string) Option { return optionFunc(func(base string, v url.Values) string { v.Set(name, value) return base }) }
go
func QueryParam(name, value string) Option { return optionFunc(func(base string, v url.Values) string { v.Set(name, value) return base }) }
[ "func", "QueryParam", "(", "name", ",", "value", "string", ")", "Option", "{", "return", "optionFunc", "(", "func", "(", "base", "string", ",", "v", "url", ".", "Values", ")", "string", "{", "v", ".", "Set", "(", "name", ",", "value", ")", "\n", "r...
// QueryParam can be used to manually set a URL query parameter by name.
[ "QueryParam", "can", "be", "used", "to", "manually", "set", "a", "URL", "query", "parameter", "by", "name", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/resource.go#L39-L44
8,909
ericchiang/k8s
resource.go
Timeout
func Timeout(d time.Duration) Option { return QueryParam( "timeoutSeconds", strconv.FormatInt(int64(d/time.Second), 10), ) }
go
func Timeout(d time.Duration) Option { return QueryParam( "timeoutSeconds", strconv.FormatInt(int64(d/time.Second), 10), ) }
[ "func", "Timeout", "(", "d", "time", ".", "Duration", ")", "Option", "{", "return", "QueryParam", "(", "\"", "\"", ",", "strconv", ".", "FormatInt", "(", "int64", "(", "d", "/", "time", ".", "Second", ")", ",", "10", ")", ",", ")", "\n", "}" ]
// Timeout declares the timeout for list and watch operations. Timeout // is only accurate to the second.
[ "Timeout", "declares", "the", "timeout", "for", "list", "and", "watch", "operations", ".", "Timeout", "is", "only", "accurate", "to", "the", "second", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/resource.go#L98-L103
8,910
ericchiang/k8s
examples/out-of-cluster-client.go
loadClient
func loadClient(kubeconfigPath string) (*k8s.Client, error) { data, err := ioutil.ReadFile(kubeconfigPath) if err != nil { return nil, fmt.Errorf("read kubeconfig: %v", err) } // Unmarshal YAML into a Kubernetes config object. var config k8s.Config if err := yaml.Unmarshal(data, &config); err != nil { return...
go
func loadClient(kubeconfigPath string) (*k8s.Client, error) { data, err := ioutil.ReadFile(kubeconfigPath) if err != nil { return nil, fmt.Errorf("read kubeconfig: %v", err) } // Unmarshal YAML into a Kubernetes config object. var config k8s.Config if err := yaml.Unmarshal(data, &config); err != nil { return...
[ "func", "loadClient", "(", "kubeconfigPath", "string", ")", "(", "*", "k8s", ".", "Client", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "kubeconfigPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ...
// loadClient parses a kubeconfig from a file and returns a Kubernetes // client. It does not support extensions or client auth providers.
[ "loadClient", "parses", "a", "kubeconfig", "from", "a", "file", "and", "returns", "a", "Kubernetes", "client", ".", "It", "does", "not", "support", "extensions", "or", "client", "auth", "providers", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/examples/out-of-cluster-client.go#L16-L28
8,911
ericchiang/k8s
codec.go
marshal
func marshal(i interface{}) (string, []byte, error) { if _, ok := i.(proto.Message); ok { data, err := marshalPB(i) return contentTypePB, data, err } data, err := json.Marshal(i) return contentTypeJSON, data, err }
go
func marshal(i interface{}) (string, []byte, error) { if _, ok := i.(proto.Message); ok { data, err := marshalPB(i) return contentTypePB, data, err } data, err := json.Marshal(i) return contentTypeJSON, data, err }
[ "func", "marshal", "(", "i", "interface", "{", "}", ")", "(", "string", ",", "[", "]", "byte", ",", "error", ")", "{", "if", "_", ",", "ok", ":=", "i", ".", "(", "proto", ".", "Message", ")", ";", "ok", "{", "data", ",", "err", ":=", "marshal...
// marshal encodes an object and returns the content type of that resource // and the marshaled representation. // // marshal prefers protobuf encoding, but falls back to JSON.
[ "marshal", "encodes", "an", "object", "and", "returns", "the", "content", "type", "of", "that", "resource", "and", "the", "marshaled", "representation", ".", "marshal", "prefers", "protobuf", "encoding", "but", "falls", "back", "to", "JSON", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/codec.go#L29-L36
8,912
ericchiang/k8s
codec.go
unmarshal
func unmarshal(data []byte, contentType string, i interface{}) error { msg, isPBMsg := i.(proto.Message) if contentType == contentTypePB && isPBMsg { if err := unmarshalPB(data, msg); err != nil { return fmt.Errorf("decode protobuf: %v", err) } return nil } if isPBMsg { // only decode into JSON of a prot...
go
func unmarshal(data []byte, contentType string, i interface{}) error { msg, isPBMsg := i.(proto.Message) if contentType == contentTypePB && isPBMsg { if err := unmarshalPB(data, msg); err != nil { return fmt.Errorf("decode protobuf: %v", err) } return nil } if isPBMsg { // only decode into JSON of a prot...
[ "func", "unmarshal", "(", "data", "[", "]", "byte", ",", "contentType", "string", ",", "i", "interface", "{", "}", ")", "error", "{", "msg", ",", "isPBMsg", ":=", "i", ".", "(", "proto", ".", "Message", ")", "\n", "if", "contentType", "==", "contentT...
// unmarshal decoded an object given the content type of the encoded form.
[ "unmarshal", "decoded", "an", "object", "given", "the", "content", "type", "of", "the", "encoded", "form", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/codec.go#L39-L58
8,913
ericchiang/k8s
watch.go
Next
func (w *Watcher) Next(r Resource) (string, error) { return w.watcher.Next(r) }
go
func (w *Watcher) Next(r Resource) (string, error) { return w.watcher.Next(r) }
[ "func", "(", "w", "*", "Watcher", ")", "Next", "(", "r", "Resource", ")", "(", "string", ",", "error", ")", "{", "return", "w", ".", "watcher", ".", "Next", "(", "r", ")", "\n", "}" ]
// Next decodes the next event from the watch stream. Errors are fatal, and // indicate that the watcher should no longer be used, and must be recreated.
[ "Next", "decodes", "the", "next", "event", "from", "the", "watch", "stream", ".", "Errors", "are", "fatal", "and", "indicate", "that", "the", "watcher", "should", "no", "longer", "be", "used", "and", "must", "be", "recreated", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/watch.go#L36-L38
8,914
ericchiang/k8s
apis/meta/v1/json.go
MarshalJSON
func (t Time) MarshalJSON() ([]byte, error) { var seconds, nanos int64 if t.Seconds != nil { seconds = *t.Seconds } if t.Nanos != nil { nanos = int64(*t.Nanos) } return json.Marshal(time.Unix(seconds, nanos)) }
go
func (t Time) MarshalJSON() ([]byte, error) { var seconds, nanos int64 if t.Seconds != nil { seconds = *t.Seconds } if t.Nanos != nil { nanos = int64(*t.Nanos) } return json.Marshal(time.Unix(seconds, nanos)) }
[ "func", "(", "t", "Time", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "seconds", ",", "nanos", "int64", "\n", "if", "t", ".", "Seconds", "!=", "nil", "{", "seconds", "=", "*", "t", ".", "Seconds", "\n", "...
// JSON marshaling logic for the Time type so it can be used for custom // resources, which serialize to JSON.
[ "JSON", "marshaling", "logic", "for", "the", "Time", "type", "so", "it", "can", "be", "used", "for", "custom", "resources", "which", "serialize", "to", "JSON", "." ]
68fb2168bedf77759577a56e44f2ccfaf7229673
https://github.com/ericchiang/k8s/blob/68fb2168bedf77759577a56e44f2ccfaf7229673/apis/meta/v1/json.go#L11-L20
8,915
petar/GoLLRB
llrb/llrb.go
Has
func (t *LLRB) Has(key Item) bool { return t.Get(key) != nil }
go
func (t *LLRB) Has(key Item) bool { return t.Get(key) != nil }
[ "func", "(", "t", "*", "LLRB", ")", "Has", "(", "key", "Item", ")", "bool", "{", "return", "t", ".", "Get", "(", "key", ")", "!=", "nil", "\n", "}" ]
// Has returns true if the tree contains an element whose order is the same as that of key.
[ "Has", "returns", "true", "if", "the", "tree", "contains", "an", "element", "whose", "order", "is", "the", "same", "as", "that", "of", "key", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L97-L99
8,916
petar/GoLLRB
llrb/llrb.go
Get
func (t *LLRB) Get(key Item) Item { h := t.root for h != nil { switch { case less(key, h.Item): h = h.Left case less(h.Item, key): h = h.Right default: return h.Item } } return nil }
go
func (t *LLRB) Get(key Item) Item { h := t.root for h != nil { switch { case less(key, h.Item): h = h.Left case less(h.Item, key): h = h.Right default: return h.Item } } return nil }
[ "func", "(", "t", "*", "LLRB", ")", "Get", "(", "key", "Item", ")", "Item", "{", "h", ":=", "t", ".", "root", "\n", "for", "h", "!=", "nil", "{", "switch", "{", "case", "less", "(", "key", ",", "h", ".", "Item", ")", ":", "h", "=", "h", "...
// Get retrieves an element from the tree whose order is the same as that of key.
[ "Get", "retrieves", "an", "element", "from", "the", "tree", "whose", "order", "is", "the", "same", "as", "that", "of", "key", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L102-L115
8,917
petar/GoLLRB
llrb/llrb.go
Min
func (t *LLRB) Min() Item { h := t.root if h == nil { return nil } for h.Left != nil { h = h.Left } return h.Item }
go
func (t *LLRB) Min() Item { h := t.root if h == nil { return nil } for h.Left != nil { h = h.Left } return h.Item }
[ "func", "(", "t", "*", "LLRB", ")", "Min", "(", ")", "Item", "{", "h", ":=", "t", ".", "root", "\n", "if", "h", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "for", "h", ".", "Left", "!=", "nil", "{", "h", "=", "h", ".", "Left", "\n...
// Min returns the minimum element in the tree.
[ "Min", "returns", "the", "minimum", "element", "in", "the", "tree", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L118-L127
8,918
petar/GoLLRB
llrb/llrb.go
Max
func (t *LLRB) Max() Item { h := t.root if h == nil { return nil } for h.Right != nil { h = h.Right } return h.Item }
go
func (t *LLRB) Max() Item { h := t.root if h == nil { return nil } for h.Right != nil { h = h.Right } return h.Item }
[ "func", "(", "t", "*", "LLRB", ")", "Max", "(", ")", "Item", "{", "h", ":=", "t", ".", "root", "\n", "if", "h", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "for", "h", ".", "Right", "!=", "nil", "{", "h", "=", "h", ".", "Right", "...
// Max returns the maximum element in the tree.
[ "Max", "returns", "the", "maximum", "element", "in", "the", "tree", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L130-L139
8,919
petar/GoLLRB
llrb/llrb.go
ReplaceOrInsert
func (t *LLRB) ReplaceOrInsert(item Item) Item { if item == nil { panic("inserting nil item") } var replaced Item t.root, replaced = t.replaceOrInsert(t.root, item) t.root.Black = true if replaced == nil { t.count++ } return replaced }
go
func (t *LLRB) ReplaceOrInsert(item Item) Item { if item == nil { panic("inserting nil item") } var replaced Item t.root, replaced = t.replaceOrInsert(t.root, item) t.root.Black = true if replaced == nil { t.count++ } return replaced }
[ "func", "(", "t", "*", "LLRB", ")", "ReplaceOrInsert", "(", "item", "Item", ")", "Item", "{", "if", "item", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "replaced", "Item", "\n", "t", ".", "root", ",", "replaced", "=",...
// ReplaceOrInsert inserts item into the tree. If an existing // element has the same order, it is removed from the tree and returned.
[ "ReplaceOrInsert", "inserts", "item", "into", "the", "tree", ".", "If", "an", "existing", "element", "has", "the", "same", "order", "it", "is", "removed", "from", "the", "tree", "and", "returned", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L155-L166
8,920
petar/GoLLRB
llrb/llrb.go
InsertNoReplace
func (t *LLRB) InsertNoReplace(item Item) { if item == nil { panic("inserting nil item") } t.root = t.insertNoReplace(t.root, item) t.root.Black = true t.count++ }
go
func (t *LLRB) InsertNoReplace(item Item) { if item == nil { panic("inserting nil item") } t.root = t.insertNoReplace(t.root, item) t.root.Black = true t.count++ }
[ "func", "(", "t", "*", "LLRB", ")", "InsertNoReplace", "(", "item", "Item", ")", "{", "if", "item", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "t", ".", "root", "=", "t", ".", "insertNoReplace", "(", "t", ".", "root", ","...
// InsertNoReplace inserts item into the tree. If an existing // element has the same order, both elements remain in the tree.
[ "InsertNoReplace", "inserts", "item", "into", "the", "tree", ".", "If", "an", "existing", "element", "has", "the", "same", "order", "both", "elements", "remain", "in", "the", "tree", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L191-L198
8,921
petar/GoLLRB
llrb/llrb.go
walkDownRot234
func walkDownRot234(h *Node) *Node { if isRed(h.Left) && isRed(h.Right) { flip(h) } return h }
go
func walkDownRot234(h *Node) *Node { if isRed(h.Left) && isRed(h.Right) { flip(h) } return h }
[ "func", "walkDownRot234", "(", "h", "*", "Node", ")", "*", "Node", "{", "if", "isRed", "(", "h", ".", "Left", ")", "&&", "isRed", "(", "h", ".", "Right", ")", "{", "flip", "(", "h", ")", "\n", "}", "\n\n", "return", "h", "\n", "}" ]
// Rotation driver routines for 2-3-4 algorithm
[ "Rotation", "driver", "routines", "for", "2", "-", "3", "-", "4", "algorithm" ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L238-L244
8,922
petar/GoLLRB
llrb/llrb.go
DeleteMin
func (t *LLRB) DeleteMin() Item { var deleted Item t.root, deleted = deleteMin(t.root) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
go
func (t *LLRB) DeleteMin() Item { var deleted Item t.root, deleted = deleteMin(t.root) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
[ "func", "(", "t", "*", "LLRB", ")", "DeleteMin", "(", ")", "Item", "{", "var", "deleted", "Item", "\n", "t", ".", "root", ",", "deleted", "=", "deleteMin", "(", "t", ".", "root", ")", "\n", "if", "t", ".", "root", "!=", "nil", "{", "t", ".", ...
// DeleteMin deletes the minimum element in the tree and returns the // deleted item or nil otherwise.
[ "DeleteMin", "deletes", "the", "minimum", "element", "in", "the", "tree", "and", "returns", "the", "deleted", "item", "or", "nil", "otherwise", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L260-L270
8,923
petar/GoLLRB
llrb/llrb.go
deleteMin
func deleteMin(h *Node) (*Node, Item) { if h == nil { return nil, nil } if h.Left == nil { return nil, h.Item } if !isRed(h.Left) && !isRed(h.Left.Left) { h = moveRedLeft(h) } var deleted Item h.Left, deleted = deleteMin(h.Left) return fixUp(h), deleted }
go
func deleteMin(h *Node) (*Node, Item) { if h == nil { return nil, nil } if h.Left == nil { return nil, h.Item } if !isRed(h.Left) && !isRed(h.Left.Left) { h = moveRedLeft(h) } var deleted Item h.Left, deleted = deleteMin(h.Left) return fixUp(h), deleted }
[ "func", "deleteMin", "(", "h", "*", "Node", ")", "(", "*", "Node", ",", "Item", ")", "{", "if", "h", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "if", "h", ".", "Left", "==", "nil", "{", "return", "nil", ",", "h", ".", "...
// deleteMin code for LLRB 2-3 trees
[ "deleteMin", "code", "for", "LLRB", "2", "-", "3", "trees" ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L273-L289
8,924
petar/GoLLRB
llrb/llrb.go
DeleteMax
func (t *LLRB) DeleteMax() Item { var deleted Item t.root, deleted = deleteMax(t.root) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
go
func (t *LLRB) DeleteMax() Item { var deleted Item t.root, deleted = deleteMax(t.root) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
[ "func", "(", "t", "*", "LLRB", ")", "DeleteMax", "(", ")", "Item", "{", "var", "deleted", "Item", "\n", "t", ".", "root", ",", "deleted", "=", "deleteMax", "(", "t", ".", "root", ")", "\n", "if", "t", ".", "root", "!=", "nil", "{", "t", ".", ...
// DeleteMax deletes the maximum element in the tree and returns // the deleted item or nil otherwise
[ "DeleteMax", "deletes", "the", "maximum", "element", "in", "the", "tree", "and", "returns", "the", "deleted", "item", "or", "nil", "otherwise" ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L293-L303
8,925
petar/GoLLRB
llrb/llrb.go
Delete
func (t *LLRB) Delete(key Item) Item { var deleted Item t.root, deleted = t.delete(t.root, key) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
go
func (t *LLRB) Delete(key Item) Item { var deleted Item t.root, deleted = t.delete(t.root, key) if t.root != nil { t.root.Black = true } if deleted != nil { t.count-- } return deleted }
[ "func", "(", "t", "*", "LLRB", ")", "Delete", "(", "key", "Item", ")", "Item", "{", "var", "deleted", "Item", "\n", "t", ".", "root", ",", "deleted", "=", "t", ".", "delete", "(", "t", ".", "root", ",", "key", ")", "\n", "if", "t", ".", "root...
// Delete deletes an item from the tree whose key equals key. // The deleted item is return, otherwise nil is returned.
[ "Delete", "deletes", "an", "item", "from", "the", "tree", "whose", "key", "equals", "key", ".", "The", "deleted", "item", "is", "return", "otherwise", "nil", "is", "returned", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/llrb.go#L326-L336
8,926
petar/GoLLRB
llrb/iterator.go
AscendGreaterOrEqual
func (t *LLRB) AscendGreaterOrEqual(pivot Item, iterator ItemIterator) { t.ascendGreaterOrEqual(t.root, pivot, iterator) }
go
func (t *LLRB) AscendGreaterOrEqual(pivot Item, iterator ItemIterator) { t.ascendGreaterOrEqual(t.root, pivot, iterator) }
[ "func", "(", "t", "*", "LLRB", ")", "AscendGreaterOrEqual", "(", "pivot", "Item", ",", "iterator", "ItemIterator", ")", "{", "t", ".", "ascendGreaterOrEqual", "(", "t", ".", "root", ",", "pivot", ",", "iterator", ")", "\n", "}" ]
// AscendGreaterOrEqual will call iterator once for each element greater or equal to // pivot in ascending order. It will stop whenever the iterator returns false.
[ "AscendGreaterOrEqual", "will", "call", "iterator", "once", "for", "each", "element", "greater", "or", "equal", "to", "pivot", "in", "ascending", "order", ".", "It", "will", "stop", "whenever", "the", "iterator", "returns", "false", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/iterator.go#L35-L37
8,927
petar/GoLLRB
llrb/iterator.go
DescendLessOrEqual
func (t *LLRB) DescendLessOrEqual(pivot Item, iterator ItemIterator) { t.descendLessOrEqual(t.root, pivot, iterator) }
go
func (t *LLRB) DescendLessOrEqual(pivot Item, iterator ItemIterator) { t.descendLessOrEqual(t.root, pivot, iterator) }
[ "func", "(", "t", "*", "LLRB", ")", "DescendLessOrEqual", "(", "pivot", "Item", ",", "iterator", "ItemIterator", ")", "{", "t", ".", "descendLessOrEqual", "(", "t", ".", "root", ",", "pivot", ",", "iterator", ")", "\n", "}" ]
// DescendLessOrEqual will call iterator once for each element less than the // pivot in descending order. It will stop whenever the iterator returns false.
[ "DescendLessOrEqual", "will", "call", "iterator", "once", "for", "each", "element", "less", "than", "the", "pivot", "in", "descending", "order", ".", "It", "will", "stop", "whenever", "the", "iterator", "returns", "false", "." ]
53be0d36a84c2a886ca057d34b6aa4468df9ccb4
https://github.com/petar/GoLLRB/blob/53be0d36a84c2a886ca057d34b6aa4468df9ccb4/llrb/iterator.go#L76-L78
8,928
google/jsonapi
runtime.go
WithValue
func (r *Runtime) WithValue(key string, value interface{}) *Runtime { r.ctx[key] = value return r }
go
func (r *Runtime) WithValue(key string, value interface{}) *Runtime { r.ctx[key] = value return r }
[ "func", "(", "r", "*", "Runtime", ")", "WithValue", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "*", "Runtime", "{", "r", ".", "ctx", "[", "key", "]", "=", "value", "\n\n", "return", "r", "\n", "}" ]
// WithValue adds custom state variables to the runtime context.
[ "WithValue", "adds", "custom", "state", "variables", "to", "the", "runtime", "context", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/runtime.go#L51-L55
8,929
google/jsonapi
runtime.go
UnmarshalPayload
func (r *Runtime) UnmarshalPayload(reader io.Reader, model interface{}) error { return r.instrumentCall(UnmarshalStart, UnmarshalStop, func() error { return UnmarshalPayload(reader, model) }) }
go
func (r *Runtime) UnmarshalPayload(reader io.Reader, model interface{}) error { return r.instrumentCall(UnmarshalStart, UnmarshalStop, func() error { return UnmarshalPayload(reader, model) }) }
[ "func", "(", "r", "*", "Runtime", ")", "UnmarshalPayload", "(", "reader", "io", ".", "Reader", ",", "model", "interface", "{", "}", ")", "error", "{", "return", "r", ".", "instrumentCall", "(", "UnmarshalStart", ",", "UnmarshalStop", ",", "func", "(", ")...
// UnmarshalPayload has docs in request.go for UnmarshalPayload.
[ "UnmarshalPayload", "has", "docs", "in", "request", ".", "go", "for", "UnmarshalPayload", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/runtime.go#L72-L76
8,930
google/jsonapi
runtime.go
UnmarshalManyPayload
func (r *Runtime) UnmarshalManyPayload(reader io.Reader, kind reflect.Type) (elems []interface{}, err error) { r.instrumentCall(UnmarshalStart, UnmarshalStop, func() error { elems, err = UnmarshalManyPayload(reader, kind) return err }) return }
go
func (r *Runtime) UnmarshalManyPayload(reader io.Reader, kind reflect.Type) (elems []interface{}, err error) { r.instrumentCall(UnmarshalStart, UnmarshalStop, func() error { elems, err = UnmarshalManyPayload(reader, kind) return err }) return }
[ "func", "(", "r", "*", "Runtime", ")", "UnmarshalManyPayload", "(", "reader", "io", ".", "Reader", ",", "kind", "reflect", ".", "Type", ")", "(", "elems", "[", "]", "interface", "{", "}", ",", "err", "error", ")", "{", "r", ".", "instrumentCall", "("...
// UnmarshalManyPayload has docs in request.go for UnmarshalManyPayload.
[ "UnmarshalManyPayload", "has", "docs", "in", "request", ".", "go", "for", "UnmarshalManyPayload", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/runtime.go#L79-L86
8,931
google/jsonapi
request.go
UnmarshalManyPayload
func UnmarshalManyPayload(in io.Reader, t reflect.Type) ([]interface{}, error) { payload := new(ManyPayload) if err := json.NewDecoder(in).Decode(payload); err != nil { return nil, err } models := []interface{}{} // will be populated from the "data" includedMap := map[string]*Node{} // will be populate...
go
func UnmarshalManyPayload(in io.Reader, t reflect.Type) ([]interface{}, error) { payload := new(ManyPayload) if err := json.NewDecoder(in).Decode(payload); err != nil { return nil, err } models := []interface{}{} // will be populated from the "data" includedMap := map[string]*Node{} // will be populate...
[ "func", "UnmarshalManyPayload", "(", "in", "io", ".", "Reader", ",", "t", "reflect", ".", "Type", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "payload", ":=", "new", "(", "ManyPayload", ")", "\n\n", "if", "err", ":=", "json", ...
// UnmarshalManyPayload converts an io into a set of struct instances using // jsonapi tags on the type's struct fields.
[ "UnmarshalManyPayload", "converts", "an", "io", "into", "a", "set", "of", "struct", "instances", "using", "jsonapi", "tags", "on", "the", "type", "s", "struct", "fields", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/request.go#L113-L140
8,932
google/jsonapi
request.go
assign
func assign(field, value reflect.Value) { value = reflect.Indirect(value) if field.Kind() == reflect.Ptr { // initialize pointer so it's value // can be set by assignValue field.Set(reflect.New(field.Type().Elem())) field = field.Elem() } assignValue(field, value) }
go
func assign(field, value reflect.Value) { value = reflect.Indirect(value) if field.Kind() == reflect.Ptr { // initialize pointer so it's value // can be set by assignValue field.Set(reflect.New(field.Type().Elem())) field = field.Elem() } assignValue(field, value) }
[ "func", "assign", "(", "field", ",", "value", "reflect", ".", "Value", ")", "{", "value", "=", "reflect", ".", "Indirect", "(", "value", ")", "\n\n", "if", "field", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "// initialize pointer so it's v...
// assign will take the value specified and assign it to the field; if // field is expecting a ptr assign will assign a ptr.
[ "assign", "will", "take", "the", "value", "specified", "and", "assign", "it", "to", "the", "field", ";", "if", "field", "is", "expecting", "a", "ptr", "assign", "will", "assign", "a", "ptr", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/request.go#L347-L359
8,933
google/jsonapi
request.go
assignValue
func assignValue(field, value reflect.Value) { switch field.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: field.SetInt(value.Int()) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: field.SetUint(value.Uint()) case refl...
go
func assignValue(field, value reflect.Value) { switch field.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: field.SetInt(value.Int()) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: field.SetUint(value.Uint()) case refl...
[ "func", "assignValue", "(", "field", ",", "value", "reflect", ".", "Value", ")", "{", "switch", "field", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int8", ",", "reflect", ".", "Int16", ",", "reflect", ".", "Int32...
// assign assigns the specified value to the field, // expecting both values not to be pointer types.
[ "assign", "assigns", "the", "specified", "value", "to", "the", "field", "expecting", "both", "values", "not", "to", "be", "pointer", "types", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/request.go#L363-L380
8,934
google/jsonapi
response.go
Marshal
func Marshal(models interface{}) (Payloader, error) { switch vals := reflect.ValueOf(models); vals.Kind() { case reflect.Slice: m, err := convertToSliceInterface(&models) if err != nil { return nil, err } payload, err := marshalMany(m) if err != nil { return nil, err } if linkableModels, isLinka...
go
func Marshal(models interface{}) (Payloader, error) { switch vals := reflect.ValueOf(models); vals.Kind() { case reflect.Slice: m, err := convertToSliceInterface(&models) if err != nil { return nil, err } payload, err := marshalMany(m) if err != nil { return nil, err } if linkableModels, isLinka...
[ "func", "Marshal", "(", "models", "interface", "{", "}", ")", "(", "Payloader", ",", "error", ")", "{", "switch", "vals", ":=", "reflect", ".", "ValueOf", "(", "models", ")", ";", "vals", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Slice", ...
// Marshal does the same as MarshalPayload except it just returns the payload // and doesn't write out results. Useful if you use your own JSON rendering // library.
[ "Marshal", "does", "the", "same", "as", "MarshalPayload", "except", "it", "just", "returns", "the", "payload", "and", "doesn", "t", "write", "out", "results", ".", "Useful", "if", "you", "use", "your", "own", "JSON", "rendering", "library", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/response.go#L77-L112
8,935
google/jsonapi
response.go
marshalOne
func marshalOne(model interface{}) (*OnePayload, error) { included := make(map[string]*Node) rootNode, err := visitModelNode(model, &included, true) if err != nil { return nil, err } payload := &OnePayload{Data: rootNode} payload.Included = nodeMapValues(&included) return payload, nil }
go
func marshalOne(model interface{}) (*OnePayload, error) { included := make(map[string]*Node) rootNode, err := visitModelNode(model, &included, true) if err != nil { return nil, err } payload := &OnePayload{Data: rootNode} payload.Included = nodeMapValues(&included) return payload, nil }
[ "func", "marshalOne", "(", "model", "interface", "{", "}", ")", "(", "*", "OnePayload", ",", "error", ")", "{", "included", ":=", "make", "(", "map", "[", "string", "]", "*", "Node", ")", "\n\n", "rootNode", ",", "err", ":=", "visitModelNode", "(", "...
// marshalOne does the same as MarshalOnePayload except it just returns the // payload and doesn't write out results. Useful is you use your JSON rendering // library.
[ "marshalOne", "does", "the", "same", "as", "MarshalOnePayload", "except", "it", "just", "returns", "the", "payload", "and", "doesn", "t", "write", "out", "results", ".", "Useful", "is", "you", "use", "your", "JSON", "rendering", "library", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/response.go#L134-L146
8,936
google/jsonapi
response.go
marshalMany
func marshalMany(models []interface{}) (*ManyPayload, error) { payload := &ManyPayload{ Data: []*Node{}, } included := map[string]*Node{} for _, model := range models { node, err := visitModelNode(model, &included, true) if err != nil { return nil, err } payload.Data = append(payload.Data, node) } p...
go
func marshalMany(models []interface{}) (*ManyPayload, error) { payload := &ManyPayload{ Data: []*Node{}, } included := map[string]*Node{} for _, model := range models { node, err := visitModelNode(model, &included, true) if err != nil { return nil, err } payload.Data = append(payload.Data, node) } p...
[ "func", "marshalMany", "(", "models", "[", "]", "interface", "{", "}", ")", "(", "*", "ManyPayload", ",", "error", ")", "{", "payload", ":=", "&", "ManyPayload", "{", "Data", ":", "[", "]", "*", "Node", "{", "}", ",", "}", "\n", "included", ":=", ...
// marshalMany does the same as MarshalManyPayload except it just returns the // payload and doesn't write out results. Useful is you use your JSON rendering // library.
[ "marshalMany", "does", "the", "same", "as", "MarshalManyPayload", "except", "it", "just", "returns", "the", "payload", "and", "doesn", "t", "write", "out", "results", ".", "Useful", "is", "you", "use", "your", "JSON", "rendering", "library", "." ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/response.go#L151-L167
8,937
google/jsonapi
examples/models.go
JSONAPILinks
func (blog Blog) JSONAPILinks() *jsonapi.Links { return &jsonapi.Links{ "self": fmt.Sprintf("https://example.com/blogs/%d", blog.ID), } }
go
func (blog Blog) JSONAPILinks() *jsonapi.Links { return &jsonapi.Links{ "self": fmt.Sprintf("https://example.com/blogs/%d", blog.ID), } }
[ "func", "(", "blog", "Blog", ")", "JSONAPILinks", "(", ")", "*", "jsonapi", ".", "Links", "{", "return", "&", "jsonapi", ".", "Links", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "blog", ".", "ID", ")", ",", "}", "\n", "}...
// JSONAPILinks implements the Linkable interface for a blog
[ "JSONAPILinks", "implements", "the", "Linkable", "interface", "for", "a", "blog" ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/examples/models.go#L38-L42
8,938
google/jsonapi
examples/models.go
JSONAPIRelationshipLinks
func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links { if relation == "posts" { return &jsonapi.Links{ "related": fmt.Sprintf("https://example.com/blogs/%d/posts", blog.ID), } } if relation == "current_post" { return &jsonapi.Links{ "related": fmt.Sprintf("https://example.com/blogs/%...
go
func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links { if relation == "posts" { return &jsonapi.Links{ "related": fmt.Sprintf("https://example.com/blogs/%d/posts", blog.ID), } } if relation == "current_post" { return &jsonapi.Links{ "related": fmt.Sprintf("https://example.com/blogs/%...
[ "func", "(", "blog", "Blog", ")", "JSONAPIRelationshipLinks", "(", "relation", "string", ")", "*", "jsonapi", ".", "Links", "{", "if", "relation", "==", "\"", "\"", "{", "return", "&", "jsonapi", ".", "Links", "{", "\"", "\"", ":", "fmt", ".", "Sprintf...
// JSONAPIRelationshipLinks implements the RelationshipLinkable interface for a blog
[ "JSONAPIRelationshipLinks", "implements", "the", "RelationshipLinkable", "interface", "for", "a", "blog" ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/examples/models.go#L45-L57
8,939
google/jsonapi
examples/models.go
JSONAPIRelationshipMeta
func (blog Blog) JSONAPIRelationshipMeta(relation string) *jsonapi.Meta { if relation == "posts" { return &jsonapi.Meta{ "detail": "posts meta information", } } if relation == "current_post" { return &jsonapi.Meta{ "detail": "current post meta information", } } return nil }
go
func (blog Blog) JSONAPIRelationshipMeta(relation string) *jsonapi.Meta { if relation == "posts" { return &jsonapi.Meta{ "detail": "posts meta information", } } if relation == "current_post" { return &jsonapi.Meta{ "detail": "current post meta information", } } return nil }
[ "func", "(", "blog", "Blog", ")", "JSONAPIRelationshipMeta", "(", "relation", "string", ")", "*", "jsonapi", ".", "Meta", "{", "if", "relation", "==", "\"", "\"", "{", "return", "&", "jsonapi", ".", "Meta", "{", "\"", "\"", ":", "\"", "\"", ",", "}",...
// JSONAPIRelationshipMeta implements the RelationshipMetable interface for a blog
[ "JSONAPIRelationshipMeta", "implements", "the", "RelationshipMetable", "interface", "for", "a", "blog" ]
d0428f63eb511f08685bda2d0a6af1d7532fb1c0
https://github.com/google/jsonapi/blob/d0428f63eb511f08685bda2d0a6af1d7532fb1c0/examples/models.go#L67-L79
8,940
buger/goterm
terminal.go
applyTransform
func applyTransform(str string, transform sf) (out string) { out = "" for idx, line := range strings.Split(str, "\n") { out += transform(idx, line) } return }
go
func applyTransform(str string, transform sf) (out string) { out = "" for idx, line := range strings.Split(str, "\n") { out += transform(idx, line) } return }
[ "func", "applyTransform", "(", "str", "string", ",", "transform", "sf", ")", "(", "out", "string", ")", "{", "out", "=", "\"", "\"", "\n\n", "for", "idx", ",", "line", ":=", "range", "strings", ".", "Split", "(", "str", ",", "\"", "\\n", "\"", ")",...
// Apply given transformation func for each line in string
[ "Apply", "given", "transformation", "func", "for", "each", "line", "in", "string" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L99-L107
8,941
buger/goterm
terminal.go
MoveCursor
func MoveCursor(x int, y int) { fmt.Fprintf(Screen, "\033[%d;%dH", y, x) }
go
func MoveCursor(x int, y int) { fmt.Fprintf(Screen, "\033[%d;%dH", y, x) }
[ "func", "MoveCursor", "(", "x", "int", ",", "y", "int", ")", "{", "fmt", ".", "Fprintf", "(", "Screen", ",", "\"", "\\033", "\"", ",", "y", ",", "x", ")", "\n", "}" ]
// Move cursor to given position
[ "Move", "cursor", "to", "given", "position" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L115-L117
8,942
buger/goterm
terminal.go
MoveTo
func MoveTo(str string, x int, y int) (out string) { x, y = GetXY(x, y) return applyTransform(str, func(idx int, line string) string { return fmt.Sprintf("\033[%d;%dH%s", y+idx, x, line) }) }
go
func MoveTo(str string, x int, y int) (out string) { x, y = GetXY(x, y) return applyTransform(str, func(idx int, line string) string { return fmt.Sprintf("\033[%d;%dH%s", y+idx, x, line) }) }
[ "func", "MoveTo", "(", "str", "string", ",", "x", "int", ",", "y", "int", ")", "(", "out", "string", ")", "{", "x", ",", "y", "=", "GetXY", "(", "x", ",", "y", ")", "\n\n", "return", "applyTransform", "(", "str", ",", "func", "(", "idx", "int",...
// Move string to possition
[ "Move", "string", "to", "possition" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L140-L146
8,943
buger/goterm
terminal.go
ResetLine
func ResetLine(str string) (out string) { return applyTransform(str, func(idx int, line string) string { return fmt.Sprintf("%s%s", RESET_LINE, line) }) }
go
func ResetLine(str string) (out string) { return applyTransform(str, func(idx int, line string) string { return fmt.Sprintf("%s%s", RESET_LINE, line) }) }
[ "func", "ResetLine", "(", "str", "string", ")", "(", "out", "string", ")", "{", "return", "applyTransform", "(", "str", ",", "func", "(", "idx", "int", ",", "line", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", ...
// Return carrier to start of line
[ "Return", "carrier", "to", "start", "of", "line" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L149-L153
8,944
buger/goterm
terminal.go
Width
func Width() int { ws, err := getWinsize() if err != nil { return -1 } return int(ws.Col) }
go
func Width() int { ws, err := getWinsize() if err != nil { return -1 } return int(ws.Col) }
[ "func", "Width", "(", ")", "int", "{", "ws", ",", "err", ":=", "getWinsize", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n\n", "return", "int", "(", "ws", ".", "Col", ")", "\n", "}" ]
// Get console width
[ "Get", "console", "width" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L192-L200
8,945
buger/goterm
terminal.go
Height
func Height() int { ws, err := getWinsize() if err != nil { return -1 } return int(ws.Row) }
go
func Height() int { ws, err := getWinsize() if err != nil { return -1 } return int(ws.Row) }
[ "func", "Height", "(", ")", "int", "{", "ws", ",", "err", ":=", "getWinsize", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", "\n", "}", "\n", "return", "int", "(", "ws", ".", "Row", ")", "\n", "}" ]
// Get console height
[ "Get", "console", "height" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L203-L209
8,946
buger/goterm
terminal.go
Flush
func Flush() { for idx, str := range strings.SplitAfter(Screen.String(), "\n") { if idx > Height() { return } Output.WriteString(str) } Output.Flush() Screen.Reset() }
go
func Flush() { for idx, str := range strings.SplitAfter(Screen.String(), "\n") { if idx > Height() { return } Output.WriteString(str) } Output.Flush() Screen.Reset() }
[ "func", "Flush", "(", ")", "{", "for", "idx", ",", "str", ":=", "range", "strings", ".", "SplitAfter", "(", "Screen", ".", "String", "(", ")", ",", "\"", "\\n", "\"", ")", "{", "if", "idx", ">", "Height", "(", ")", "{", "return", "\n", "}", "\n...
// Flush buffer and ensure that it will not overflow screen
[ "Flush", "buffer", "and", "ensure", "that", "it", "will", "not", "overflow", "screen" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/terminal.go#L217-L228
8,947
buger/goterm
plot.go
getChartData
func getChartData(data *DataTable, index int) (out [][]float64) { for _, r := range data.rows { out = append(out, []float64{r[0], r[index]}) } return }
go
func getChartData(data *DataTable, index int) (out [][]float64) { for _, r := range data.rows { out = append(out, []float64{r[0], r[index]}) } return }
[ "func", "getChartData", "(", "data", "*", "DataTable", ",", "index", "int", ")", "(", "out", "[", "]", "[", "]", "float64", ")", "{", "for", "_", ",", "r", ":=", "range", "data", ".", "rows", "{", "out", "=", "append", "(", "out", ",", "[", "]"...
// DataTable can contain data for multiple graphs, we need to extract only 1
[ "DataTable", "can", "contain", "data", "for", "multiple", "graphs", "we", "need", "to", "extract", "only", "1" ]
c206103e1f37c0c6c5c039706305ea2aa6e8ad3b
https://github.com/buger/goterm/blob/c206103e1f37c0c6c5c039706305ea2aa6e8ad3b/plot.go#L280-L286
8,948
gorilla/csrf
store.go
Save
func (cs *cookieStore) Save(token []byte, w http.ResponseWriter) error { // Generate an encoded cookie value with the CSRF token. encoded, err := cs.sc.Encode(cs.name, token) if err != nil { return err } cookie := &http.Cookie{ Name: cs.name, Value: encoded, MaxAge: cs.maxAge, HttpOnly: cs.http...
go
func (cs *cookieStore) Save(token []byte, w http.ResponseWriter) error { // Generate an encoded cookie value with the CSRF token. encoded, err := cs.sc.Encode(cs.name, token) if err != nil { return err } cookie := &http.Cookie{ Name: cs.name, Value: encoded, MaxAge: cs.maxAge, HttpOnly: cs.http...
[ "func", "(", "cs", "*", "cookieStore", ")", "Save", "(", "token", "[", "]", "byte", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "// Generate an encoded cookie value with the CSRF token.", "encoded", ",", "err", ":=", "cs", ".", "sc", ".", "En...
// Save stores the CSRF token in the session cookie.
[ "Save", "stores", "the", "CSRF", "token", "in", "the", "session", "cookie", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/store.go#L53-L82
8,949
gorilla/csrf
options.go
RequestHeader
func RequestHeader(header string) Option { return func(cs *csrf) { cs.opts.RequestHeader = header } }
go
func RequestHeader(header string) Option { return func(cs *csrf) { cs.opts.RequestHeader = header } }
[ "func", "RequestHeader", "(", "header", "string", ")", "Option", "{", "return", "func", "(", "cs", "*", "csrf", ")", "{", "cs", ".", "opts", ".", "RequestHeader", "=", "header", "\n", "}", "\n", "}" ]
// RequestHeader allows you to change the request header the CSRF middleware // inspects. The default is X-CSRF-Token.
[ "RequestHeader", "allows", "you", "to", "change", "the", "request", "header", "the", "CSRF", "middleware", "inspects", ".", "The", "default", "is", "X", "-", "CSRF", "-", "Token", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/options.go#L76-L80
8,950
gorilla/csrf
options.go
CookieName
func CookieName(name string) Option { return func(cs *csrf) { cs.opts.CookieName = name } }
go
func CookieName(name string) Option { return func(cs *csrf) { cs.opts.CookieName = name } }
[ "func", "CookieName", "(", "name", "string", ")", "Option", "{", "return", "func", "(", "cs", "*", "csrf", ")", "{", "cs", ".", "opts", ".", "CookieName", "=", "name", "\n", "}", "\n", "}" ]
// CookieName changes the name of the CSRF cookie issued to clients. // // Note that cookie names should not contain whitespace, commas, semicolons, // backslashes or control characters as per RFC6265.
[ "CookieName", "changes", "the", "name", "of", "the", "CSRF", "cookie", "issued", "to", "clients", ".", "Note", "that", "cookie", "names", "should", "not", "contain", "whitespace", "commas", "semicolons", "backslashes", "or", "control", "characters", "as", "per",...
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/options.go#L94-L98
8,951
gorilla/csrf
options.go
parseOptions
func parseOptions(h http.Handler, opts ...Option) *csrf { // Set the handler to call after processing. cs := &csrf{ h: h, } // Default to true. See Secure & HttpOnly function comments for rationale. // Set here to allow package users to override the default. cs.opts.Secure = true cs.opts.HttpOnly = true // ...
go
func parseOptions(h http.Handler, opts ...Option) *csrf { // Set the handler to call after processing. cs := &csrf{ h: h, } // Default to true. See Secure & HttpOnly function comments for rationale. // Set here to allow package users to override the default. cs.opts.Secure = true cs.opts.HttpOnly = true // ...
[ "func", "parseOptions", "(", "h", "http", ".", "Handler", ",", "opts", "...", "Option", ")", "*", "csrf", "{", "// Set the handler to call after processing.", "cs", ":=", "&", "csrf", "{", "h", ":", "h", ",", "}", "\n\n", "// Default to true. See Secure & HttpOn...
// parseOptions parses the supplied options functions and returns a configured // csrf handler.
[ "parseOptions", "parses", "the", "supplied", "options", "functions", "and", "returns", "a", "configured", "csrf", "handler", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/options.go#L110-L130
8,952
gorilla/csrf
helpers.go
FailureReason
func FailureReason(r *http.Request) error { if val, err := contextGet(r, errorKey); err == nil { if err, ok := val.(error); ok { return err } } return nil }
go
func FailureReason(r *http.Request) error { if val, err := contextGet(r, errorKey); err == nil { if err, ok := val.(error); ok { return err } } return nil }
[ "func", "FailureReason", "(", "r", "*", "http", ".", "Request", ")", "error", "{", "if", "val", ",", "err", ":=", "contextGet", "(", "r", ",", "errorKey", ")", ";", "err", "==", "nil", "{", "if", "err", ",", "ok", ":=", "val", ".", "(", "error", ...
// FailureReason makes CSRF validation errors available in the request context. // This is useful when you want to log the cause of the error or report it to // client.
[ "FailureReason", "makes", "CSRF", "validation", "errors", "available", "in", "the", "request", "context", ".", "This", "is", "useful", "when", "you", "want", "to", "log", "the", "cause", "of", "the", "error", "or", "report", "it", "to", "client", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/helpers.go#L29-L37
8,953
gorilla/csrf
helpers.go
envError
func envError(r *http.Request, err error) *http.Request { return contextSave(r, errorKey, err) }
go
func envError(r *http.Request, err error) *http.Request { return contextSave(r, errorKey, err) }
[ "func", "envError", "(", "r", "*", "http", ".", "Request", ",", "err", "error", ")", "*", "http", ".", "Request", "{", "return", "contextSave", "(", "r", ",", "errorKey", ",", "err", ")", "\n", "}" ]
// envError stores a CSRF error in the request context.
[ "envError", "stores", "a", "CSRF", "error", "in", "the", "request", "context", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/helpers.go#L201-L203
8,954
gorilla/csrf
csrf.go
ServeHTTP
func (cs *csrf) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Skip the check if directed to. This should always be a bool. if val, err := contextGet(r, skipCheckKey); err == nil { if skip, ok := val.(bool); ok { if skip { cs.h.ServeHTTP(w, r) return } } } // Retrieve the token from the s...
go
func (cs *csrf) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Skip the check if directed to. This should always be a bool. if val, err := contextGet(r, skipCheckKey); err == nil { if skip, ok := val.(bool); ok { if skip { cs.h.ServeHTTP(w, r) return } } } // Retrieve the token from the s...
[ "func", "(", "cs", "*", "csrf", ")", "ServeHTTP", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "// Skip the check if directed to. This should always be a bool.", "if", "val", ",", "err", ":=", "contextGet", "(", "r"...
// Implements http.Handler for the csrf type.
[ "Implements", "http", ".", "Handler", "for", "the", "csrf", "type", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/csrf.go#L179-L270
8,955
gorilla/csrf
csrf.go
unauthorizedHandler
func unauthorizedHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("%s - %s", http.StatusText(http.StatusForbidden), FailureReason(r)), http.StatusForbidden) return }
go
func unauthorizedHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("%s - %s", http.StatusText(http.StatusForbidden), FailureReason(r)), http.StatusForbidden) return }
[ "func", "unauthorizedHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "http", ".", "Error", "(", "w", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "http", ".", "StatusText", "(", "http", ".", ...
// unauthorizedhandler sets a HTTP 403 Forbidden status and writes the // CSRF failure reason to the response.
[ "unauthorizedhandler", "sets", "a", "HTTP", "403", "Forbidden", "status", "and", "writes", "the", "CSRF", "failure", "reason", "to", "the", "response", "." ]
d1620373958b3d521d88c063d1c9b678e734e9df
https://github.com/gorilla/csrf/blob/d1620373958b3d521d88c063d1c9b678e734e9df/csrf.go#L274-L279
8,956
glycerine/zygomys
zygo/jsonmsgp.go
JsonToSexp
func JsonToSexp(json []byte, env *Zlisp) (Sexp, error) { iface, err := JsonToGo(json) if err != nil { return nil, err } return GoToSexp(iface, env) }
go
func JsonToSexp(json []byte, env *Zlisp) (Sexp, error) { iface, err := JsonToGo(json) if err != nil { return nil, err } return GoToSexp(iface, env) }
[ "func", "JsonToSexp", "(", "json", "[", "]", "byte", ",", "env", "*", "Zlisp", ")", "(", "Sexp", ",", "error", ")", "{", "iface", ",", "err", ":=", "JsonToGo", "(", "json", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", ...
// json -> sexp. env is needed to handle symbols correctly
[ "json", "-", ">", "sexp", ".", "env", "is", "needed", "to", "handle", "symbols", "correctly" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L82-L88
8,957
glycerine/zygomys
zygo/jsonmsgp.go
SexpToJson
func SexpToJson(exp Sexp) string { switch e := exp.(type) { case *SexpHash: return e.jsonHashHelper() case *SexpArray: return e.jsonArrayHelper() case *SexpSymbol: return `"` + e.name + `"` default: return exp.SexpString(nil) } }
go
func SexpToJson(exp Sexp) string { switch e := exp.(type) { case *SexpHash: return e.jsonHashHelper() case *SexpArray: return e.jsonArrayHelper() case *SexpSymbol: return `"` + e.name + `"` default: return exp.SexpString(nil) } }
[ "func", "SexpToJson", "(", "exp", "Sexp", ")", "string", "{", "switch", "e", ":=", "exp", ".", "(", "type", ")", "{", "case", "*", "SexpHash", ":", "return", "e", ".", "jsonHashHelper", "(", ")", "\n", "case", "*", "SexpArray", ":", "return", "e", ...
// sexp -> json
[ "sexp", "-", ">", "json" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L91-L102
8,958
glycerine/zygomys
zygo/jsonmsgp.go
JsonToGo
func JsonToGo(json []byte) (interface{}, error) { var iface interface{} decoder := codec.NewDecoderBytes(json, &msgpHelper.jh) err := decoder.Decode(&iface) if err != nil { panic(err) } VPrintf("\n decoded type : %T\n", iface) VPrintf("\n decoded value: %#v\n", iface) return iface, nil }
go
func JsonToGo(json []byte) (interface{}, error) { var iface interface{} decoder := codec.NewDecoderBytes(json, &msgpHelper.jh) err := decoder.Decode(&iface) if err != nil { panic(err) } VPrintf("\n decoded type : %T\n", iface) VPrintf("\n decoded value: %#v\n", iface) return iface, nil }
[ "func", "JsonToGo", "(", "json", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "var", "iface", "interface", "{", "}", "\n\n", "decoder", ":=", "codec", ".", "NewDecoderBytes", "(", "json", ",", "&", "msgpHelper", ".", "jh...
// json -> go
[ "json", "-", ">", "go" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L198-L209
8,959
glycerine/zygomys
zygo/jsonmsgp.go
GoToJson
func GoToJson(iface interface{}) []byte { var w bytes.Buffer encoder := codec.NewEncoder(&w, &msgpHelper.jh) err := encoder.Encode(&iface) if err != nil { panic(err) } return w.Bytes() }
go
func GoToJson(iface interface{}) []byte { var w bytes.Buffer encoder := codec.NewEncoder(&w, &msgpHelper.jh) err := encoder.Encode(&iface) if err != nil { panic(err) } return w.Bytes() }
[ "func", "GoToJson", "(", "iface", "interface", "{", "}", ")", "[", "]", "byte", "{", "var", "w", "bytes", ".", "Buffer", "\n", "encoder", ":=", "codec", ".", "NewEncoder", "(", "&", "w", ",", "&", "msgpHelper", ".", "jh", ")", "\n", "err", ":=", ...
// go -> json
[ "go", "-", ">", "json" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L222-L230
8,960
glycerine/zygomys
zygo/jsonmsgp.go
MsgpackToSexp
func MsgpackToSexp(msgp []byte, env *Zlisp) (Sexp, error) { iface, err := MsgpackToGo(msgp) if err != nil { return nil, fmt.Errorf("MsgpackToSexp failed at MsgpackToGo step: '%s", err) } sexp, err := GoToSexp(iface, env) if err != nil { return nil, fmt.Errorf("MsgpackToSexp failed at GoToSexp step: '%s", err) ...
go
func MsgpackToSexp(msgp []byte, env *Zlisp) (Sexp, error) { iface, err := MsgpackToGo(msgp) if err != nil { return nil, fmt.Errorf("MsgpackToSexp failed at MsgpackToGo step: '%s", err) } sexp, err := GoToSexp(iface, env) if err != nil { return nil, fmt.Errorf("MsgpackToSexp failed at GoToSexp step: '%s", err) ...
[ "func", "MsgpackToSexp", "(", "msgp", "[", "]", "byte", ",", "env", "*", "Zlisp", ")", "(", "Sexp", ",", "error", ")", "{", "iface", ",", "err", ":=", "MsgpackToGo", "(", "msgp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fm...
// msgpack -> sexp
[ "msgpack", "-", ">", "sexp" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L233-L243
8,961
glycerine/zygomys
zygo/jsonmsgp.go
MsgpackToGo
func MsgpackToGo(msgp []byte) (interface{}, error) { var iface interface{} dec := codec.NewDecoderBytes(msgp, &msgpHelper.mh) err := dec.Decode(&iface) if err != nil { return nil, err } //fmt.Printf("\n decoded type : %T\n", iface) //fmt.Printf("\n decoded value: %#v\n", iface) return iface, nil }
go
func MsgpackToGo(msgp []byte) (interface{}, error) { var iface interface{} dec := codec.NewDecoderBytes(msgp, &msgpHelper.mh) err := dec.Decode(&iface) if err != nil { return nil, err } //fmt.Printf("\n decoded type : %T\n", iface) //fmt.Printf("\n decoded value: %#v\n", iface) return iface, nil }
[ "func", "MsgpackToGo", "(", "msgp", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "var", "iface", "interface", "{", "}", "\n", "dec", ":=", "codec", ".", "NewDecoderBytes", "(", "msgp", ",", "&", "msgpHelper", ".", "mh", ...
// msgpack -> go
[ "msgpack", "-", ">", "go" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/jsonmsgp.go#L246-L258
8,962
glycerine/zygomys
slides/coro/lexer.go
dumpComment
func (lexer *Lexer) dumpComment() { str := lexer.buffer.String() lexer.buffer.Reset() lexer.AppendToken(lexer.Token(TokenComment, str)) }
go
func (lexer *Lexer) dumpComment() { str := lexer.buffer.String() lexer.buffer.Reset() lexer.AppendToken(lexer.Token(TokenComment, str)) }
[ "func", "(", "lexer", "*", "Lexer", ")", "dumpComment", "(", ")", "{", "str", ":=", "lexer", ".", "buffer", ".", "String", "(", ")", "\n", "lexer", ".", "buffer", ".", "Reset", "(", ")", "\n", "lexer", ".", "AppendToken", "(", "lexer", ".", "Token"...
// with block comments, we've got to tell // the parser about them, so it can recognize // when another line is needed to finish a // block comment.
[ "with", "block", "comments", "we", "ve", "got", "to", "tell", "the", "parser", "about", "them", "so", "it", "can", "recognize", "when", "another", "line", "is", "needed", "to", "finish", "a", "block", "comment", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/slides/coro/lexer.go#L332-L336
8,963
glycerine/zygomys
zygo/scopes.go
SexpString
func (s *Scope) SexpString(ps *PrintState) string { var label string head := "" if s.IsPackage { head = "(package " + s.PackageName } else { label = "scope " + s.Name if s.IsGlobal { label += " (global)" } } str, err := s.Show(s.env, ps, s.Name) if err != nil { return "(" + label + ")" } return ...
go
func (s *Scope) SexpString(ps *PrintState) string { var label string head := "" if s.IsPackage { head = "(package " + s.PackageName } else { label = "scope " + s.Name if s.IsGlobal { label += " (global)" } } str, err := s.Show(s.env, ps, s.Name) if err != nil { return "(" + label + ")" } return ...
[ "func", "(", "s", "*", "Scope", ")", "SexpString", "(", "ps", "*", "PrintState", ")", "string", "{", "var", "label", "string", "\n", "head", ":=", "\"", "\"", "\n", "if", "s", ".", "IsPackage", "{", "head", "=", "\"", "\"", "+", "s", ".", "Packag...
// SexpString satisfies the Sexp interface, producing a string presentation of the value.
[ "SexpString", "satisfies", "the", "Sexp", "interface", "producing", "a", "string", "presentation", "of", "the", "value", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/scopes.go#L27-L45
8,964
glycerine/zygomys
zygo/scopes.go
LookupSymbolNonGlobal
func (stack *Stack) LookupSymbolNonGlobal(sym *SexpSymbol) (Sexp, error, *Scope) { return stack.lookupSymbol(sym, 1, nil) }
go
func (stack *Stack) LookupSymbolNonGlobal(sym *SexpSymbol) (Sexp, error, *Scope) { return stack.lookupSymbol(sym, 1, nil) }
[ "func", "(", "stack", "*", "Stack", ")", "LookupSymbolNonGlobal", "(", "sym", "*", "SexpSymbol", ")", "(", "Sexp", ",", "error", ",", "*", "Scope", ")", "{", "return", "stack", ".", "lookupSymbol", "(", "sym", ",", "1", ",", "nil", ")", "\n", "}" ]
// LookupSymbolNonGlobal - closures use this to only find symbols below the global scope, to avoid copying globals it'll always be-able to ref
[ "LookupSymbolNonGlobal", "-", "closures", "use", "this", "to", "only", "find", "symbols", "below", "the", "global", "scope", "to", "avoid", "copying", "globals", "it", "ll", "always", "be", "-", "able", "to", "ref" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/scopes.go#L129-L131
8,965
glycerine/zygomys
zygo/msgpackmap.go
MsgpackMapMacro
func MsgpackMapMacro(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) < 1 { return SexpNull, fmt.Errorf("struct-name is missing. use: " + "(msgpack-map struct-name)\n") } return MakeList([]Sexp{ env.MakeSymbol("def"), args[0], MakeList([]Sexp{ env.MakeSymbol("quote"), env.MakeSy...
go
func MsgpackMapMacro(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) < 1 { return SexpNull, fmt.Errorf("struct-name is missing. use: " + "(msgpack-map struct-name)\n") } return MakeList([]Sexp{ env.MakeSymbol("def"), args[0], MakeList([]Sexp{ env.MakeSymbol("quote"), env.MakeSy...
[ "func", "MsgpackMapMacro", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "<", "1", "{", "return", "SexpNull", ",", "fmt", ".", "Errorf", "(...
// declare a new record type
[ "declare", "a", "new", "record", "type" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/msgpackmap.go#L14-L31
8,966
glycerine/zygomys
zygo/comment.go
RemoveEndsFilter
func RemoveEndsFilter(x Sexp) bool { switch n := x.(type) { case *SexpSentinel: if n.Val == SexpEnd.Val { return false } } return true }
go
func RemoveEndsFilter(x Sexp) bool { switch n := x.(type) { case *SexpSentinel: if n.Val == SexpEnd.Val { return false } } return true }
[ "func", "RemoveEndsFilter", "(", "x", "Sexp", ")", "bool", "{", "switch", "n", ":=", "x", ".", "(", "type", ")", "{", "case", "*", "SexpSentinel", ":", "if", "n", ".", "Val", "==", "SexpEnd", ".", "Val", "{", "return", "false", "\n", "}", "\n", "...
// detect SexpEnd values and return false on them to filter them out.
[ "detect", "SexpEnd", "values", "and", "return", "false", "on", "them", "to", "filter", "them", "out", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/comment.go#L31-L39
8,967
glycerine/zygomys
zygo/functions.go
MergeFuncMap
func MergeFuncMap(funcs ...map[string]ZlispUserFunction) map[string]ZlispUserFunction { n := make(map[string]ZlispUserFunction) for _, f := range funcs { for k, v := range f { // disallow dups, avoiding possible security implications and confusion generally. if _, dup := n[k]; dup { panic(fmt.Sprintf(" d...
go
func MergeFuncMap(funcs ...map[string]ZlispUserFunction) map[string]ZlispUserFunction { n := make(map[string]ZlispUserFunction) for _, f := range funcs { for k, v := range f { // disallow dups, avoiding possible security implications and confusion generally. if _, dup := n[k]; dup { panic(fmt.Sprintf(" d...
[ "func", "MergeFuncMap", "(", "funcs", "...", "map", "[", "string", "]", "ZlispUserFunction", ")", "map", "[", "string", "]", "ZlispUserFunction", "{", "n", ":=", "make", "(", "map", "[", "string", "]", "ZlispUserFunction", ")", "\n\n", "for", "_", ",", "...
// MergeFuncMap returns the union of the two given maps
[ "MergeFuncMap", "returns", "the", "union", "of", "the", "two", "given", "maps" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L903-L916
8,968
glycerine/zygomys
zygo/functions.go
CoreFunctions
func CoreFunctions() map[string]ZlispUserFunction { return map[string]ZlispUserFunction{ "pretty": SetPrettyPrintFlag, "<": CompareFunction, ">": CompareFunction, "<=": CompareFunction, ">=": CompareFunction, "==": CompareFunction, "!=": CompareFunction, "...
go
func CoreFunctions() map[string]ZlispUserFunction { return map[string]ZlispUserFunction{ "pretty": SetPrettyPrintFlag, "<": CompareFunction, ">": CompareFunction, "<=": CompareFunction, ">=": CompareFunction, "==": CompareFunction, "!=": CompareFunction, "...
[ "func", "CoreFunctions", "(", ")", "map", "[", "string", "]", "ZlispUserFunction", "{", "return", "map", "[", "string", "]", "ZlispUserFunction", "{", "\"", "\"", ":", "SetPrettyPrintFlag", ",", "\"", "\"", ":", "CompareFunction", ",", "\"", "\"", ":", "Co...
// CoreFunctions returns all of the core logic
[ "CoreFunctions", "returns", "all", "of", "the", "core", "logic" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L939-L1027
8,969
glycerine/zygomys
zygo/functions.go
GenericAccessFunction
func GenericAccessFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) < 1 || len(args) > 3 { return SexpNull, WrongNargs } // handle *SexpSelector container := args[0] var err error if ptr, isPtrLike := container.(Selector); isPtrLike { container, err = ptr.RHS(env) if err != nil { ...
go
func GenericAccessFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) < 1 || len(args) > 3 { return SexpNull, WrongNargs } // handle *SexpSelector container := args[0] var err error if ptr, isPtrLike := container.(Selector); isPtrLike { container, err = ptr.RHS(env) if err != nil { ...
[ "func", "GenericAccessFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "<", "1", "||", "len", "(", "args", ")", ">", "3", "{", "r...
// handles arrays or hashes
[ "handles", "arrays", "or", "hashes" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L1190-L1212
8,970
glycerine/zygomys
zygo/functions.go
AssignmentFunction
func AssignmentFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { Q("\n AssignmentFunction called with name ='%s'. args='%s'\n", name, env.NewSexpArray(args).SexpString(nil)) narg := len(args) if narg != 2 { return SexpNull, fmt.Errorf("assignment requires two arguments: a left-hand-side and a right...
go
func AssignmentFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { Q("\n AssignmentFunction called with name ='%s'. args='%s'\n", name, env.NewSexpArray(args).SexpString(nil)) narg := len(args) if narg != 2 { return SexpNull, fmt.Errorf("assignment requires two arguments: a left-hand-side and a right...
[ "func", "AssignmentFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "Q", "(", "\"", "\\n", "\\n", "\"", ",", "name", ",", "env", ".", "NewSexpArray", "(", "args", ...
// the assignment function, =
[ "the", "assignment", "function", "=" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L1234-L1268
8,971
glycerine/zygomys
zygo/functions.go
errIfPrivate
func errIfPrivate(pathPart string, pkg *Stack) error { noDot := stripAnyDotPrefix(pathPart) // references through a package must be Public if !unicode.IsUpper([]rune(noDot)[0]) { return fmt.Errorf("Cannot access private member '%s' of package '%s'", noDot, pkg.PackageName) } return nil }
go
func errIfPrivate(pathPart string, pkg *Stack) error { noDot := stripAnyDotPrefix(pathPart) // references through a package must be Public if !unicode.IsUpper([]rune(noDot)[0]) { return fmt.Errorf("Cannot access private member '%s' of package '%s'", noDot, pkg.PackageName) } return nil }
[ "func", "errIfPrivate", "(", "pathPart", "string", ",", "pkg", "*", "Stack", ")", "error", "{", "noDot", ":=", "stripAnyDotPrefix", "(", "pathPart", ")", "\n\n", "// references through a package must be Public", "if", "!", "unicode", ".", "IsUpper", "(", "[", "]...
// helper used by dotGetSetHelper and sub-calls to check for private
[ "helper", "used", "by", "dotGetSetHelper", "and", "sub", "-", "calls", "to", "check", "for", "private" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L1350-L1359
8,972
glycerine/zygomys
zygo/functions.go
DotFunction
func DotFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } P("in DotFunction(), name='%v', args[0] = '%v', args[1]= '%v'", name, args[0].SexpString(nil), args[1].SexpString(nil)) return SexpNull, nil /* var ret Sexp = SexpNull var err error ...
go
func DotFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } P("in DotFunction(), name='%v', args[0] = '%v', args[1]= '%v'", name, args[0].SexpString(nil), args[1].SexpString(nil)) return SexpNull, nil /* var ret Sexp = SexpNull var err error ...
[ "func", "DotFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "2", "{", "return", "SexpNull", ",", "WrongNargs", "\n", "}", "\...
// "." dot operator
[ ".", "dot", "operator" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L1659-L1704
8,973
glycerine/zygomys
zygo/functions.go
AsUint64Function
func AsUint64Function(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } var val uint64 switch x := args[0].(type) { case *SexpInt: val = uint64(x.Val) case *SexpFloat: val = uint64(x.Val) default: return SexpNull, fmt.Errorf("Cannot convert %s to uin...
go
func AsUint64Function(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } var val uint64 switch x := args[0].(type) { case *SexpInt: val = uint64(x.Val) case *SexpFloat: val = uint64(x.Val) default: return SexpNull, fmt.Errorf("Cannot convert %s to uin...
[ "func", "AsUint64Function", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "1", "{", "return", "SexpNull", ",", "WrongNargs", "\n", "}",...
// coerce numbers to uint64
[ "coerce", "numbers", "to", "uint64" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/functions.go#L1771-L1787
8,974
glycerine/zygomys
zygo/hashutils.go
GenericHpairFunction
func GenericHpairFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } posreq, isInt := args[1].(*SexpInt) if !isInt { return SexpNull, fmt.Errorf("hpair position request must be an integer") } pos := int(posreq.Val) switch seq := args[0].(type) { ...
go
func GenericHpairFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } posreq, isInt := args[1].(*SexpInt) if !isInt { return SexpNull, fmt.Errorf("hpair position request must be an integer") } pos := int(posreq.Val) switch seq := args[0].(type) { ...
[ "func", "GenericHpairFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "2", "{", "return", "SexpNull", ",", "WrongNargs", "\n", ...
// works over hashes and arrays
[ "works", "over", "hashes", "and", "arrays" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/hashutils.go#L618-L644
8,975
glycerine/zygomys
zygo/hashutils.go
CloneFrom
func (p *SexpHash) CloneFrom(src *SexpHash) { p.TypeName = src.TypeName p.Map = *(src.CopyMap()) p.KeyOrder = src.KeyOrder p.GoStructFactory = src.GoStructFactory p.NumKeys = src.NumKeys p.GoMethods = src.GoMethods p.GoFields = src.GoFields p.GoMethSx = src.GoMethSx p.GoFieldSx = src.GoFieldSx p.GoType = sr...
go
func (p *SexpHash) CloneFrom(src *SexpHash) { p.TypeName = src.TypeName p.Map = *(src.CopyMap()) p.KeyOrder = src.KeyOrder p.GoStructFactory = src.GoStructFactory p.NumKeys = src.NumKeys p.GoMethods = src.GoMethods p.GoFields = src.GoFields p.GoMethSx = src.GoMethSx p.GoFieldSx = src.GoFieldSx p.GoType = sr...
[ "func", "(", "p", "*", "SexpHash", ")", "CloneFrom", "(", "src", "*", "SexpHash", ")", "{", "p", ".", "TypeName", "=", "src", ".", "TypeName", "\n", "p", ".", "Map", "=", "*", "(", "src", ".", "CopyMap", "(", ")", ")", "\n\n", "p", ".", "KeyOrd...
// CloneFrom copys all the internals of src into p, effectively // blanking out whatever p held and replacing it with a copy of src.
[ "CloneFrom", "copys", "all", "the", "internals", "of", "src", "into", "p", "effectively", "blanking", "out", "whatever", "p", "held", "and", "replacing", "it", "with", "a", "copy", "of", "src", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/hashutils.go#L925-L959
8,976
glycerine/zygomys
zygo/parser.go
Start
func (p *Parser) Start() { go func() { defer close(p.Done) expressions := make([]Sexp, 0, SliceDefaultCap) // maybe we already have input, be optimistic! // no need to call p.GetMoreInput() before staring // our loop. for { expr, err := p.ParseExpression(0) if err != nil || expr == SexpEnd { if...
go
func (p *Parser) Start() { go func() { defer close(p.Done) expressions := make([]Sexp, 0, SliceDefaultCap) // maybe we already have input, be optimistic! // no need to call p.GetMoreInput() before staring // our loop. for { expr, err := p.ParseExpression(0) if err != nil || expr == SexpEnd { if...
[ "func", "(", "p", "*", "Parser", ")", "Start", "(", ")", "{", "go", "func", "(", ")", "{", "defer", "close", "(", "p", ".", "Done", ")", "\n", "expressions", ":=", "make", "(", "[", "]", "Sexp", ",", "0", ",", "SliceDefaultCap", ")", "\n\n", "/...
// Starts launches a background goroutine that runs an // infinite parsing loop.
[ "Starts", "launches", "a", "background", "goroutine", "that", "runs", "an", "infinite", "parsing", "loop", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/parser.go#L70-L98
8,977
glycerine/zygomys
slides/coro/repl.go
getExpressionWithLiner
func (pr *Prompter) getExpressionWithLiner(env *Glisp) (readin string, xs []Sexp, err error) { line, err := pr.Getline(nil) if err != nil { return "", nil, err } err = UnexpectedEnd var x []Sexp // parse and pause the parser if we need more input. env.parser.ResetAddNewInput(bytes.NewBuffer([]byte(line + "\...
go
func (pr *Prompter) getExpressionWithLiner(env *Glisp) (readin string, xs []Sexp, err error) { line, err := pr.Getline(nil) if err != nil { return "", nil, err } err = UnexpectedEnd var x []Sexp // parse and pause the parser if we need more input. env.parser.ResetAddNewInput(bytes.NewBuffer([]byte(line + "\...
[ "func", "(", "pr", "*", "Prompter", ")", "getExpressionWithLiner", "(", "env", "*", "Glisp", ")", "(", "readin", "string", ",", "xs", "[", "]", "Sexp", ",", "err", "error", ")", "{", "line", ",", "err", ":=", "pr", ".", "Getline", "(", "nil", ")", ...
// reads Stdin only
[ "reads", "Stdin", "only" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/slides/coro/repl.go#L74-L125
8,978
glycerine/zygomys
zygo/vprint.go
TSPrintf
func TSPrintf(format string, a ...interface{}) { fmt.Printf("%s ", ts()) fmt.Printf(format, a...) }
go
func TSPrintf(format string, a ...interface{}) { fmt.Printf("%s ", ts()) fmt.Printf(format, a...) }
[ "func", "TSPrintf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "ts", "(", ")", ")", "\n", "fmt", ".", "Printf", "(", "format", ",", "a", "...", ")", "\n", "}" ]
// time-stamped printf
[ "time", "-", "stamped", "printf" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/vprint.go#L27-L30
8,979
glycerine/zygomys
zygo/liner.go
MyWordCompleter
func MyWordCompleter(line string, pos int) (head string, c []string, tail string) { beg := []rune(line[:pos]) end := line[pos:] Q("\nline = '%s' pos=%v\n", line, pos) Q("\nbeg = '%v'\nend = '%s'\n", string(beg), end) // find most recent paren in beg n := len(beg) last := n - 1 var i int var p int = -1 outer: ...
go
func MyWordCompleter(line string, pos int) (head string, c []string, tail string) { beg := []rune(line[:pos]) end := line[pos:] Q("\nline = '%s' pos=%v\n", line, pos) Q("\nbeg = '%v'\nend = '%s'\n", string(beg), end) // find most recent paren in beg n := len(beg) last := n - 1 var i int var p int = -1 outer: ...
[ "func", "MyWordCompleter", "(", "line", "string", ",", "pos", "int", ")", "(", "head", "string", ",", "c", "[", "]", "string", ",", "tail", "string", ")", "{", "beg", ":=", "[", "]", "rune", "(", "line", "[", ":", "pos", "]", ")", "\n", "end", ...
// complete phrases that start with '('
[ "complete", "phrases", "that", "start", "with", "(" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/liner.go#L39-L82
8,980
glycerine/zygomys
zygo/pratt.go
Assignment
func (env *Zlisp) Assignment(op string, bp int) *InfixOp { oper := env.MakeSymbol(op) operSet := env.MakeSymbol("set") iop := &InfixOp{ Sym: oper, Bp: bp, MunchLeft: func(env *Zlisp, pr *Pratt, left Sexp) (Sexp, error) { // TODO: check that left is okay as an LVALUE. right, err := pr.Expression(env, bp...
go
func (env *Zlisp) Assignment(op string, bp int) *InfixOp { oper := env.MakeSymbol(op) operSet := env.MakeSymbol("set") iop := &InfixOp{ Sym: oper, Bp: bp, MunchLeft: func(env *Zlisp, pr *Pratt, left Sexp) (Sexp, error) { // TODO: check that left is okay as an LVALUE. right, err := pr.Expression(env, bp...
[ "func", "(", "env", "*", "Zlisp", ")", "Assignment", "(", "op", "string", ",", "bp", "int", ")", "*", "InfixOp", "{", "oper", ":=", "env", ".", "MakeSymbol", "(", "op", ")", "\n", "operSet", ":=", "env", ".", "MakeSymbol", "(", "\"", "\"", ")", "...
// Assignment creates a new assignment operator for infix // processing.
[ "Assignment", "creates", "a", "new", "assignment", "operator", "for", "infix", "processing", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/pratt.go#L113-L140
8,981
glycerine/zygomys
zygo/pratt.go
PostfixAssign
func (env *Zlisp) PostfixAssign(op string, bp int) *InfixOp { oper := env.MakeSymbol(op) iop := &InfixOp{ Sym: oper, Bp: bp, MunchLeft: func(env *Zlisp, pr *Pratt, left Sexp) (Sexp, error) { // TODO: check that left is okay as an LVALUE list := MakeList([]Sexp{ oper, left, }) Q("postfix assignm...
go
func (env *Zlisp) PostfixAssign(op string, bp int) *InfixOp { oper := env.MakeSymbol(op) iop := &InfixOp{ Sym: oper, Bp: bp, MunchLeft: func(env *Zlisp, pr *Pratt, left Sexp) (Sexp, error) { // TODO: check that left is okay as an LVALUE list := MakeList([]Sexp{ oper, left, }) Q("postfix assignm...
[ "func", "(", "env", "*", "Zlisp", ")", "PostfixAssign", "(", "op", "string", ",", "bp", "int", ")", "*", "InfixOp", "{", "oper", ":=", "env", ".", "MakeSymbol", "(", "op", ")", "\n", "iop", ":=", "&", "InfixOp", "{", "Sym", ":", "oper", ",", "Bp"...
// PostfixAssign creates a new postfix assignment operator for infix // processing.
[ "PostfixAssign", "creates", "a", "new", "postfix", "assignment", "operator", "for", "infix", "processing", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/pratt.go#L144-L160
8,982
glycerine/zygomys
zygo/pratt.go
Advance
func (p *Pratt) Advance() error { p.Pos++ if p.Pos >= len(p.Stream) { return io.EOF } p.NextToken = p.Stream[p.Pos] Q("end of Advance, p.NextToken = '%v'", p.NextToken.SexpString(nil)) return nil }
go
func (p *Pratt) Advance() error { p.Pos++ if p.Pos >= len(p.Stream) { return io.EOF } p.NextToken = p.Stream[p.Pos] Q("end of Advance, p.NextToken = '%v'", p.NextToken.SexpString(nil)) return nil }
[ "func", "(", "p", "*", "Pratt", ")", "Advance", "(", ")", "error", "{", "p", ".", "Pos", "++", "\n", "if", "p", ".", "Pos", ">=", "len", "(", "p", ".", "Stream", ")", "{", "return", "io", ".", "EOF", "\n", "}", "\n", "p", ".", "NextToken", ...
// Advance sets p.NextToken
[ "Advance", "sets", "p", ".", "NextToken" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/pratt.go#L591-L599
8,983
glycerine/zygomys
zygo/expressions.go
LookupSymbolInParentChainOfClosures
func (sf *SexpFunction) LookupSymbolInParentChainOfClosures(sym *SexpSymbol, setVal *Sexp, env *Zlisp) (Sexp, error, *Scope) { cur := sf par := sf.parent for par != nil { //fmt.Printf(" parent chain: cur:%v -> parent:%v\n", cur.name, par.name) //fmt.Printf(" cur.closures = %s", ClosureToString(cur, env))...
go
func (sf *SexpFunction) LookupSymbolInParentChainOfClosures(sym *SexpSymbol, setVal *Sexp, env *Zlisp) (Sexp, error, *Scope) { cur := sf par := sf.parent for par != nil { //fmt.Printf(" parent chain: cur:%v -> parent:%v\n", cur.name, par.name) //fmt.Printf(" cur.closures = %s", ClosureToString(cur, env))...
[ "func", "(", "sf", "*", "SexpFunction", ")", "LookupSymbolInParentChainOfClosures", "(", "sym", "*", "SexpSymbol", ",", "setVal", "*", "Sexp", ",", "env", "*", "Zlisp", ")", "(", "Sexp", ",", "error", ",", "*", "Scope", ")", "{", "cur", ":=", "sf", "\n...
// chase parent pointers up the chain and check each of their immediate closures.
[ "chase", "parent", "pointers", "up", "the", "chain", "and", "check", "each", "of", "their", "immediate", "closures", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/expressions.go#L632-L651
8,984
glycerine/zygomys
zygo/callgo.go
NilOrHoldsNil
func NilOrHoldsNil(iface interface{}) bool { if iface == nil { return true } return reflect.ValueOf(iface).IsNil() }
go
func NilOrHoldsNil(iface interface{}) bool { if iface == nil { return true } return reflect.ValueOf(iface).IsNil() }
[ "func", "NilOrHoldsNil", "(", "iface", "interface", "{", "}", ")", "bool", "{", "if", "iface", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "reflect", ".", "ValueOf", "(", "iface", ")", ".", "IsNil", "(", ")", "\n", "}" ]
// detect if inteface is holding anything
[ "detect", "if", "inteface", "is", "holding", "anything" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/callgo.go#L204-L209
8,985
glycerine/zygomys
zygo/import.go
ImportPackageBuilder
func ImportPackageBuilder(env *Zlisp, name string, args []Sexp) (Sexp, error) { //P("starting ImportPackageBuilder") n := len(args) if n != 1 && n != 2 { return SexpNull, WrongNargs } var path Sexp var alias string switch n { case 1: path = args[0] case 2: path = args[1] //P("import debug: alias posi...
go
func ImportPackageBuilder(env *Zlisp, name string, args []Sexp) (Sexp, error) { //P("starting ImportPackageBuilder") n := len(args) if n != 1 && n != 2 { return SexpNull, WrongNargs } var path Sexp var alias string switch n { case 1: path = args[0] case 2: path = args[1] //P("import debug: alias posi...
[ "func", "ImportPackageBuilder", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "//P(\"starting ImportPackageBuilder\")", "n", ":=", "len", "(", "args", ")", "\n", "if", "n", "!=",...
// import a package, analagous to Golang.
[ "import", "a", "package", "analagous", "to", "Golang", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/import.go#L8-L67
8,986
glycerine/zygomys
zygo/generator.go
GenerateNewScope
func (gen *Generator) GenerateNewScope(expressions []Sexp) error { size := len(expressions) oldtail := gen.Tail gen.Tail = false if size == 0 { return nil //return NoExpressionsFound } gen.AddInstruction(AddScopeInstr{Name: "newScope"}) for _, expr := range expressions[:size-1] { err := gen.Generate(expr)...
go
func (gen *Generator) GenerateNewScope(expressions []Sexp) error { size := len(expressions) oldtail := gen.Tail gen.Tail = false if size == 0 { return nil //return NoExpressionsFound } gen.AddInstruction(AddScopeInstr{Name: "newScope"}) for _, expr := range expressions[:size-1] { err := gen.Generate(expr)...
[ "func", "(", "gen", "*", "Generator", ")", "GenerateNewScope", "(", "expressions", "[", "]", "Sexp", ")", "error", "{", "size", ":=", "len", "(", "expressions", ")", "\n", "oldtail", ":=", "gen", ".", "Tail", "\n", "gen", ".", "Tail", "=", "false", "...
// like begin, but puts its contents in a new scope
[ "like", "begin", "but", "puts", "its", "contents", "in", "a", "new", "scope" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/generator.go#L1370-L1396
8,987
glycerine/zygomys
zygo/system.go
SetShellCmd
func SetShellCmd() { if runtime.GOOS == "windows" { ShellCmd = os.Getenv("COMSPEC") return } try := []string{"/usr/bin/bash"} if !FileExists(ShellCmd) { for i := range try { b := try[i] if FileExists(b) { ShellCmd = b return } } } }
go
func SetShellCmd() { if runtime.GOOS == "windows" { ShellCmd = os.Getenv("COMSPEC") return } try := []string{"/usr/bin/bash"} if !FileExists(ShellCmd) { for i := range try { b := try[i] if FileExists(b) { ShellCmd = b return } } } }
[ "func", "SetShellCmd", "(", ")", "{", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "ShellCmd", "=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "try", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n",...
// set ShellCmd as used by SystemFunction
[ "set", "ShellCmd", "as", "used", "by", "SystemFunction" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/system.go#L18-L33
8,988
glycerine/zygomys
zygo/system.go
SystemBuilder
func SystemBuilder(env *Zlisp, name string, args []Sexp) (Sexp, error) { //P("SystemBuilder called with args='%#v'", args) return SystemFunction(env, name, args) }
go
func SystemBuilder(env *Zlisp, name string, args []Sexp) (Sexp, error) { //P("SystemBuilder called with args='%#v'", args) return SystemFunction(env, name, args) }
[ "func", "SystemBuilder", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "//P(\"SystemBuilder called with args='%#v'\", args)", "return", "SystemFunction", "(", "env", ",", "name", ",", ...
// sys is a builder. shell out, return the combined output.
[ "sys", "is", "a", "builder", ".", "shell", "out", "return", "the", "combined", "output", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/system.go#L36-L39
8,989
glycerine/zygomys
zygo/environment.go
DumpFunction
func DumpFunction(fun ZlispFunction, pc int) { blank := " " extra := blank for i, instr := range fun { if i == pc { extra = " PC-> " } else { extra = blank } fmt.Printf("%s %d: %s\n", extra, i, instr.InstrString()) } if pc == len(fun) { fmt.Printf(" PC just past end at %d -----\n\n", pc) } }
go
func DumpFunction(fun ZlispFunction, pc int) { blank := " " extra := blank for i, instr := range fun { if i == pc { extra = " PC-> " } else { extra = blank } fmt.Printf("%s %d: %s\n", extra, i, instr.InstrString()) } if pc == len(fun) { fmt.Printf(" PC just past end at %d -----\n\n", pc) } }
[ "func", "DumpFunction", "(", "fun", "ZlispFunction", ",", "pc", "int", ")", "{", "blank", ":=", "\"", "\"", "\n", "extra", ":=", "blank", "\n", "for", "i", ",", "instr", ":=", "range", "fun", "{", "if", "i", "==", "pc", "{", "extra", "=", "\"", "...
// if pc is -1, don't show it.
[ "if", "pc", "is", "-", "1", "don", "t", "show", "it", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/environment.go#L536-L550
8,990
glycerine/zygomys
zygo/environment.go
FindLoop
func (env *Zlisp) FindLoop(target *Loop) (int, error) { if env.curfunc.user { panic(fmt.Errorf("impossible in user-defined-function to find a loop '%s'", target.stmtname.name)) } instruc := env.curfunc.fun for i := range instruc { switch loop := instruc[i].(type) { case LoopStartInstr: if loop.loop == targ...
go
func (env *Zlisp) FindLoop(target *Loop) (int, error) { if env.curfunc.user { panic(fmt.Errorf("impossible in user-defined-function to find a loop '%s'", target.stmtname.name)) } instruc := env.curfunc.fun for i := range instruc { switch loop := instruc[i].(type) { case LoopStartInstr: if loop.loop == targ...
[ "func", "(", "env", "*", "Zlisp", ")", "FindLoop", "(", "target", "*", "Loop", ")", "(", "int", ",", "error", ")", "{", "if", "env", ".", "curfunc", ".", "user", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "target", ".", "stm...
// scan the instruction stream to locate loop start
[ "scan", "the", "instruction", "stream", "to", "locate", "loop", "start" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/environment.go#L665-L679
8,991
glycerine/zygomys
zygo/slurp.go
SplitStringFunction
func SplitStringFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } // make sure the two args are strings s1, ok := args[0].(*SexpStr) if !ok { return SexpNull, fmt.Errorf("split requires a string to split, got %T", args[0]) } s2, ok := args[1].(*...
go
func SplitStringFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 2 { return SexpNull, WrongNargs } // make sure the two args are strings s1, ok := args[0].(*SexpStr) if !ok { return SexpNull, fmt.Errorf("split requires a string to split, got %T", args[0]) } s2, ok := args[1].(*...
[ "func", "SplitStringFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "2", "{", "return", "SexpNull", ",", "WrongNargs", "\n", "...
// SplitStringFunction splits a string based on an arbitrary delimiter
[ "SplitStringFunction", "splits", "a", "string", "based", "on", "an", "arbitrary", "delimiter" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/slurp.go#L134-L159
8,992
glycerine/zygomys
zygo/repl.go
isBalanced
func isBalanced(str string) bool { parens := 0 squares := 0 for _, c := range str { switch c { case '(': parens++ case ')': parens-- case '[': squares++ case ']': squares-- } } return parens == 0 && squares == 0 }
go
func isBalanced(str string) bool { parens := 0 squares := 0 for _, c := range str { switch c { case '(': parens++ case ')': parens-- case '[': squares++ case ']': squares-- } } return parens == 0 && squares == 0 }
[ "func", "isBalanced", "(", "str", "string", ")", "bool", "{", "parens", ":=", "0", "\n", "squares", ":=", "0", "\n\n", "for", "_", ",", "c", ":=", "range", "str", "{", "switch", "c", "{", "case", "'('", ":", "parens", "++", "\n", "case", "')'", "...
// NB at the moment this doesn't track comment and strings state, // so it will fail if unbalanced '(' are found in either.
[ "NB", "at", "the", "moment", "this", "doesn", "t", "track", "comment", "and", "strings", "state", "so", "it", "will", "fail", "if", "unbalanced", "(", "are", "found", "in", "either", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/repl.go#L43-L61
8,993
glycerine/zygomys
zygo/repl.go
getExpressionWithLiner
func (pr *Prompter) getExpressionWithLiner(env *Zlisp, reader *bufio.Reader, noLiner bool) (readin string, xs []Sexp, err error) { var line, nextline string if noLiner { fmt.Printf(pr.prompt) line, err = getLine(reader) } else { line, err = pr.Getline(nil) } if err != nil { return "", nil, err } err =...
go
func (pr *Prompter) getExpressionWithLiner(env *Zlisp, reader *bufio.Reader, noLiner bool) (readin string, xs []Sexp, err error) { var line, nextline string if noLiner { fmt.Printf(pr.prompt) line, err = getLine(reader) } else { line, err = pr.Getline(nil) } if err != nil { return "", nil, err } err =...
[ "func", "(", "pr", "*", "Prompter", ")", "getExpressionWithLiner", "(", "env", "*", "Zlisp", ",", "reader", "*", "bufio", ".", "Reader", ",", "noLiner", "bool", ")", "(", "readin", "string", ",", "xs", "[", "]", "Sexp", ",", "err", "error", ")", "{",...
// liner reads Stdin only. If noLiner, then we read from reader.
[ "liner", "reads", "Stdin", "only", ".", "If", "noLiner", "then", "we", "read", "from", "reader", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/repl.go#L83-L144
8,994
glycerine/zygomys
zygo/time.go
AsTmFunction
func AsTmFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } var str *SexpStr switch t := args[0].(type) { case *SexpStr: str = t default: return SexpNull, errors.New("argument of astm should be a string RFC3999Nano timestamp that we want to...
go
func AsTmFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } var str *SexpStr switch t := args[0].(type) { case *SexpStr: str = t default: return SexpNull, errors.New("argument of astm should be a string RFC3999Nano timestamp that we want to...
[ "func", "AsTmFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "1", "{", "return", "SexpNull", ",", "WrongNargs", "\n", "}", "...
// string -> time.Time
[ "string", "-", ">", "time", ".", "Time" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/time.go#L38-L59
8,995
glycerine/zygomys
zygo/source.go
SimpleSourceFunction
func SimpleSourceFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } src, isStr := args[0].(*SexpStr) if !isStr { return SexpNull, fmt.Errorf("-> error: first argument must be a string") } file := src.S if !FileExists(file) { return SexpNull, f...
go
func SimpleSourceFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) { if len(args) != 1 { return SexpNull, WrongNargs } src, isStr := args[0].(*SexpStr) if !isStr { return SexpNull, fmt.Errorf("-> error: first argument must be a string") } file := src.S if !FileExists(file) { return SexpNull, f...
[ "func", "SimpleSourceFunction", "(", "env", "*", "Zlisp", ",", "name", "string", ",", "args", "[", "]", "Sexp", ")", "(", "Sexp", ",", "error", ")", "{", "if", "len", "(", "args", ")", "!=", "1", "{", "return", "SexpNull", ",", "WrongNargs", "\n", ...
// alternative. simpler, currently panics.
[ "alternative", ".", "simpler", "currently", "panics", "." ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/source.go#L12-L43
8,996
glycerine/zygomys
zygo/source.go
SourceExpressions
func (env *Zlisp) SourceExpressions(expressions []Sexp) error { gen := NewGenerator(env) err := gen.GenerateBegin(expressions) if err != nil { return err } //P("debug: in SourceExpressions, FROM expressions='%s'", (&SexpArray{Val: expressions, Env: env}).SexpString(0)) //P("debug: in SourceExpressions, gen=") ...
go
func (env *Zlisp) SourceExpressions(expressions []Sexp) error { gen := NewGenerator(env) err := gen.GenerateBegin(expressions) if err != nil { return err } //P("debug: in SourceExpressions, FROM expressions='%s'", (&SexpArray{Val: expressions, Env: env}).SexpString(0)) //P("debug: in SourceExpressions, gen=") ...
[ "func", "(", "env", "*", "Zlisp", ")", "SourceExpressions", "(", "expressions", "[", "]", "Sexp", ")", "error", "{", "gen", ":=", "NewGenerator", "(", "env", ")", "\n\n", "err", ":=", "gen", ".", "GenerateBegin", "(", "expressions", ")", "\n", "if", "e...
// existing // SourceExpressions, this should be called from a user func context
[ "existing", "SourceExpressions", "this", "should", "be", "called", "from", "a", "user", "func", "context" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/source.go#L48-L80
8,997
glycerine/zygomys
zygo/source.go
sourceItem
func (env *Zlisp) sourceItem(item Sexp) error { switch t := item.(type) { case *SexpArray: for _, v := range t.Val { if err := env.sourceItem(v); err != nil { return err } } case *SexpPair: expr := item for expr != SexpNull { list := expr.(*SexpPair) if err := env.sourceItem(list.Head); err !...
go
func (env *Zlisp) sourceItem(item Sexp) error { switch t := item.(type) { case *SexpArray: for _, v := range t.Val { if err := env.sourceItem(v); err != nil { return err } } case *SexpPair: expr := item for expr != SexpNull { list := expr.(*SexpPair) if err := env.sourceItem(list.Head); err !...
[ "func", "(", "env", "*", "Zlisp", ")", "sourceItem", "(", "item", "Sexp", ")", "error", "{", "switch", "t", ":=", "item", ".", "(", "type", ")", "{", "case", "*", "SexpArray", ":", "for", "_", ",", "v", ":=", "range", "t", ".", "Val", "{", "if"...
// helper for SourceFileFunction recursion
[ "helper", "for", "SourceFileFunction", "recursion" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/source.go#L116-L150
8,998
glycerine/zygomys
zygo/builders.go
SexpString
func (p *RecordDefn) SexpString(ps *PrintState) string { Q("RecordDefn::SexpString() called!") if len(p.Fields) == 0 { return fmt.Sprintf("(struct %s)", p.Name) } s := fmt.Sprintf("(struct %s [\n", p.Name) w := make([][]int, len(p.Fields)) maxnfield := 0 for i, f := range p.Fields { w[i] = f.FieldWidths() ...
go
func (p *RecordDefn) SexpString(ps *PrintState) string { Q("RecordDefn::SexpString() called!") if len(p.Fields) == 0 { return fmt.Sprintf("(struct %s)", p.Name) } s := fmt.Sprintf("(struct %s [\n", p.Name) w := make([][]int, len(p.Fields)) maxnfield := 0 for i, f := range p.Fields { w[i] = f.FieldWidths() ...
[ "func", "(", "p", "*", "RecordDefn", ")", "SexpString", "(", "ps", "*", "PrintState", ")", "string", "{", "Q", "(", "\"", "\"", ")", "\n", "if", "len", "(", "p", ".", "Fields", ")", "==", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\...
// pretty print a struct
[ "pretty", "print", "a", "struct" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/builders.go#L90-L136
8,999
glycerine/zygomys
zygo/builders.go
FieldWidths
func (f *SexpField) FieldWidths() []int { hash := (*SexpHash)(f) wide := []int{} for _, key := range hash.KeyOrder { val, err := hash.HashGet(nil, key) str := "" if err == nil { switch s := key.(type) { case *SexpStr: str += s.S + ":" case *SexpSymbol: str += s.name + ":" default: str +...
go
func (f *SexpField) FieldWidths() []int { hash := (*SexpHash)(f) wide := []int{} for _, key := range hash.KeyOrder { val, err := hash.HashGet(nil, key) str := "" if err == nil { switch s := key.(type) { case *SexpStr: str += s.S + ":" case *SexpSymbol: str += s.name + ":" default: str +...
[ "func", "(", "f", "*", "SexpField", ")", "FieldWidths", "(", ")", "[", "]", "int", "{", "hash", ":=", "(", "*", "SexpHash", ")", "(", "f", ")", "\n", "wide", ":=", "[", "]", "int", "{", "}", "\n", "for", "_", ",", "key", ":=", "range", "hash"...
// compute key and value widths to assist alignment
[ "compute", "key", "and", "value", "widths", "to", "assist", "alignment" ]
36f1c7120ff2d831cebbb6f059ddc948273a8b56
https://github.com/glycerine/zygomys/blob/36f1c7120ff2d831cebbb6f059ddc948273a8b56/zygo/builders.go#L152-L174