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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
DataDog/datadog-go
statsd/statsd.go
send
func (c *Client) send(name string, value interface{}, suffix []byte, tags []string, rate float64) error { if c == nil { return fmt.Errorf("Client is nil") } if rate < 1 && rand.Float64() > rate { return nil } data := c.format(name, value, suffix, tags, rate) return c.sendMsg(data) }
go
func (c *Client) send(name string, value interface{}, suffix []byte, tags []string, rate float64) error { if c == nil { return fmt.Errorf("Client is nil") } if rate < 1 && rand.Float64() > rate { return nil } data := c.format(name, value, suffix, tags, rate) return c.sendMsg(data) }
[ "func", "(", "c", "*", "Client", ")", "send", "(", "name", "string", ",", "value", "interface", "{", "}", ",", "suffix", "[", "]", "byte", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "if", "c", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "rate", "<", "1", "&&", "rand", ".", "Float64", "(", ")", ">", "rate", "{", "return", "nil", "\n", "}", "\n", "data", ":=", "c", ".", "format", "(", "name", ",", "value", ",", "suffix", ",", "tags", ",", "rate", ")", "\n", "return", "c", ".", "sendMsg", "(", "data", ")", "\n", "}" ]
// send handles sampling and sends the message over UDP. It also adds global namespace prefixes and tags.
[ "send", "handles", "sampling", "and", "sends", "the", "message", "over", "UDP", ".", "It", "also", "adds", "global", "namespace", "prefixes", "and", "tags", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L362-L371
train
DataDog/datadog-go
statsd/statsd.go
Gauge
func (c *Client) Gauge(name string, value float64, tags []string, rate float64) error { return c.send(name, value, gaugeSuffix, tags, rate) }
go
func (c *Client) Gauge(name string, value float64, tags []string, rate float64) error { return c.send(name, value, gaugeSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Gauge", "(", "name", "string", ",", "value", "float64", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "value", ",", "gaugeSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Gauge measures the value of a metric at a particular time.
[ "Gauge", "measures", "the", "value", "of", "a", "metric", "at", "a", "particular", "time", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L374-L376
train
DataDog/datadog-go
statsd/statsd.go
Count
func (c *Client) Count(name string, value int64, tags []string, rate float64) error { return c.send(name, value, countSuffix, tags, rate) }
go
func (c *Client) Count(name string, value int64, tags []string, rate float64) error { return c.send(name, value, countSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Count", "(", "name", "string", ",", "value", "int64", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "value", ",", "countSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Count tracks how many times something happened per second.
[ "Count", "tracks", "how", "many", "times", "something", "happened", "per", "second", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L379-L381
train
DataDog/datadog-go
statsd/statsd.go
Histogram
func (c *Client) Histogram(name string, value float64, tags []string, rate float64) error { return c.send(name, value, histogramSuffix, tags, rate) }
go
func (c *Client) Histogram(name string, value float64, tags []string, rate float64) error { return c.send(name, value, histogramSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Histogram", "(", "name", "string", ",", "value", "float64", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "value", ",", "histogramSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Histogram tracks the statistical distribution of a set of values on each host.
[ "Histogram", "tracks", "the", "statistical", "distribution", "of", "a", "set", "of", "values", "on", "each", "host", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L384-L386
train
DataDog/datadog-go
statsd/statsd.go
Distribution
func (c *Client) Distribution(name string, value float64, tags []string, rate float64) error { return c.send(name, value, distributionSuffix, tags, rate) }
go
func (c *Client) Distribution(name string, value float64, tags []string, rate float64) error { return c.send(name, value, distributionSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Distribution", "(", "name", "string", ",", "value", "float64", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "value", ",", "distributionSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Distribution tracks the statistical distribution of a set of values across your infrastructure.
[ "Distribution", "tracks", "the", "statistical", "distribution", "of", "a", "set", "of", "values", "across", "your", "infrastructure", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L389-L391
train
DataDog/datadog-go
statsd/statsd.go
Decr
func (c *Client) Decr(name string, tags []string, rate float64) error { return c.send(name, nil, decrSuffix, tags, rate) }
go
func (c *Client) Decr(name string, tags []string, rate float64) error { return c.send(name, nil, decrSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Decr", "(", "name", "string", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "nil", ",", "decrSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Decr is just Count of -1
[ "Decr", "is", "just", "Count", "of", "-", "1" ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L394-L396
train
DataDog/datadog-go
statsd/statsd.go
Incr
func (c *Client) Incr(name string, tags []string, rate float64) error { return c.send(name, nil, incrSuffix, tags, rate) }
go
func (c *Client) Incr(name string, tags []string, rate float64) error { return c.send(name, nil, incrSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Incr", "(", "name", "string", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "nil", ",", "incrSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Incr is just Count of 1
[ "Incr", "is", "just", "Count", "of", "1" ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L399-L401
train
DataDog/datadog-go
statsd/statsd.go
Set
func (c *Client) Set(name string, value string, tags []string, rate float64) error { return c.send(name, value, setSuffix, tags, rate) }
go
func (c *Client) Set(name string, value string, tags []string, rate float64) error { return c.send(name, value, setSuffix, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Set", "(", "name", "string", ",", "value", "string", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "send", "(", "name", ",", "value", ",", "setSuffix", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Set counts the number of unique elements in a group.
[ "Set", "counts", "the", "number", "of", "unique", "elements", "in", "a", "group", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L404-L406
train
DataDog/datadog-go
statsd/statsd.go
Timing
func (c *Client) Timing(name string, value time.Duration, tags []string, rate float64) error { return c.TimeInMilliseconds(name, value.Seconds()*1000, tags, rate) }
go
func (c *Client) Timing(name string, value time.Duration, tags []string, rate float64) error { return c.TimeInMilliseconds(name, value.Seconds()*1000, tags, rate) }
[ "func", "(", "c", "*", "Client", ")", "Timing", "(", "name", "string", ",", "value", "time", ".", "Duration", ",", "tags", "[", "]", "string", ",", "rate", "float64", ")", "error", "{", "return", "c", ".", "TimeInMilliseconds", "(", "name", ",", "value", ".", "Seconds", "(", ")", "*", "1000", ",", "tags", ",", "rate", ")", "\n", "}" ]
// Timing sends timing information, it is an alias for TimeInMilliseconds
[ "Timing", "sends", "timing", "information", "it", "is", "an", "alias", "for", "TimeInMilliseconds" ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L409-L411
train
DataDog/datadog-go
statsd/statsd.go
Event
func (c *Client) Event(e *Event) error { if c == nil { return fmt.Errorf("Client is nil") } stat, err := e.Encode(c.Tags...) if err != nil { return err } return c.sendMsg([]byte(stat)) }
go
func (c *Client) Event(e *Event) error { if c == nil { return fmt.Errorf("Client is nil") } stat, err := e.Encode(c.Tags...) if err != nil { return err } return c.sendMsg([]byte(stat)) }
[ "func", "(", "c", "*", "Client", ")", "Event", "(", "e", "*", "Event", ")", "error", "{", "if", "c", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "stat", ",", "err", ":=", "e", ".", "Encode", "(", "c", ".", "Tags", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "c", ".", "sendMsg", "(", "[", "]", "byte", "(", "stat", ")", ")", "\n", "}" ]
// Event sends the provided Event.
[ "Event", "sends", "the", "provided", "Event", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L420-L429
train
DataDog/datadog-go
statsd/statsd.go
SimpleEvent
func (c *Client) SimpleEvent(title, text string) error { e := NewEvent(title, text) return c.Event(e) }
go
func (c *Client) SimpleEvent(title, text string) error { e := NewEvent(title, text) return c.Event(e) }
[ "func", "(", "c", "*", "Client", ")", "SimpleEvent", "(", "title", ",", "text", "string", ")", "error", "{", "e", ":=", "NewEvent", "(", "title", ",", "text", ")", "\n", "return", "c", ".", "Event", "(", "e", ")", "\n", "}" ]
// SimpleEvent sends an event with the provided title and text.
[ "SimpleEvent", "sends", "an", "event", "with", "the", "provided", "title", "and", "text", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L432-L435
train
DataDog/datadog-go
statsd/statsd.go
ServiceCheck
func (c *Client) ServiceCheck(sc *ServiceCheck) error { if c == nil { return fmt.Errorf("Client is nil") } stat, err := sc.Encode(c.Tags...) if err != nil { return err } return c.sendMsg([]byte(stat)) }
go
func (c *Client) ServiceCheck(sc *ServiceCheck) error { if c == nil { return fmt.Errorf("Client is nil") } stat, err := sc.Encode(c.Tags...) if err != nil { return err } return c.sendMsg([]byte(stat)) }
[ "func", "(", "c", "*", "Client", ")", "ServiceCheck", "(", "sc", "*", "ServiceCheck", ")", "error", "{", "if", "c", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "stat", ",", "err", ":=", "sc", ".", "Encode", "(", "c", ".", "Tags", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "c", ".", "sendMsg", "(", "[", "]", "byte", "(", "stat", ")", ")", "\n", "}" ]
// ServiceCheck sends the provided ServiceCheck.
[ "ServiceCheck", "sends", "the", "provided", "ServiceCheck", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L438-L447
train
DataDog/datadog-go
statsd/statsd.go
SimpleServiceCheck
func (c *Client) SimpleServiceCheck(name string, status ServiceCheckStatus) error { sc := NewServiceCheck(name, status) return c.ServiceCheck(sc) }
go
func (c *Client) SimpleServiceCheck(name string, status ServiceCheckStatus) error { sc := NewServiceCheck(name, status) return c.ServiceCheck(sc) }
[ "func", "(", "c", "*", "Client", ")", "SimpleServiceCheck", "(", "name", "string", ",", "status", "ServiceCheckStatus", ")", "error", "{", "sc", ":=", "NewServiceCheck", "(", "name", ",", "status", ")", "\n", "return", "c", ".", "ServiceCheck", "(", "sc", ")", "\n", "}" ]
// SimpleServiceCheck sends an serviceCheck with the provided name and status.
[ "SimpleServiceCheck", "sends", "an", "serviceCheck", "with", "the", "provided", "name", "and", "status", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L450-L453
train
DataDog/datadog-go
statsd/statsd.go
Close
func (c *Client) Close() error { if c == nil { return fmt.Errorf("Client is nil") } select { case c.stop <- struct{}{}: default: } // if this client is buffered, flush before closing the writer if c.bufferLength > 0 { if err := c.Flush(); err != nil { return err } } return c.writer.Close() }
go
func (c *Client) Close() error { if c == nil { return fmt.Errorf("Client is nil") } select { case c.stop <- struct{}{}: default: } // if this client is buffered, flush before closing the writer if c.bufferLength > 0 { if err := c.Flush(); err != nil { return err } } return c.writer.Close() }
[ "func", "(", "c", "*", "Client", ")", "Close", "(", ")", "error", "{", "if", "c", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "select", "{", "case", "c", ".", "stop", "<-", "struct", "{", "}", "{", "}", ":", "default", ":", "}", "\n\n", "// if this client is buffered, flush before closing the writer", "if", "c", ".", "bufferLength", ">", "0", "{", "if", "err", ":=", "c", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "c", ".", "writer", ".", "Close", "(", ")", "\n", "}" ]
// Close the client connection.
[ "Close", "the", "client", "connection", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L456-L473
train
DataDog/datadog-go
statsd/statsd.go
NewEvent
func NewEvent(title, text string) *Event { return &Event{ Title: title, Text: text, } }
go
func NewEvent(title, text string) *Event { return &Event{ Title: title, Text: text, } }
[ "func", "NewEvent", "(", "title", ",", "text", "string", ")", "*", "Event", "{", "return", "&", "Event", "{", "Title", ":", "title", ",", "Text", ":", "text", ",", "}", "\n", "}" ]
// NewEvent creates a new event with the given title and text. Error checking // against these values is done at send-time, or upon running e.Check.
[ "NewEvent", "creates", "a", "new", "event", "with", "the", "given", "title", "and", "text", ".", "Error", "checking", "against", "these", "values", "is", "done", "at", "send", "-", "time", "or", "upon", "running", "e", ".", "Check", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L529-L534
train
DataDog/datadog-go
statsd/statsd.go
Encode
func (e Event) Encode(tags ...string) (string, error) { err := e.Check() if err != nil { return "", err } text := e.escapedText() var buffer bytes.Buffer buffer.WriteString("_e{") buffer.WriteString(strconv.FormatInt(int64(len(e.Title)), 10)) buffer.WriteRune(',') buffer.WriteString(strconv.FormatInt(int64(len(text)), 10)) buffer.WriteString("}:") buffer.WriteString(e.Title) buffer.WriteRune('|') buffer.WriteString(text) if !e.Timestamp.IsZero() { buffer.WriteString("|d:") buffer.WriteString(strconv.FormatInt(int64(e.Timestamp.Unix()), 10)) } if len(e.Hostname) != 0 { buffer.WriteString("|h:") buffer.WriteString(e.Hostname) } if len(e.AggregationKey) != 0 { buffer.WriteString("|k:") buffer.WriteString(e.AggregationKey) } if len(e.Priority) != 0 { buffer.WriteString("|p:") buffer.WriteString(string(e.Priority)) } if len(e.SourceTypeName) != 0 { buffer.WriteString("|s:") buffer.WriteString(e.SourceTypeName) } if len(e.AlertType) != 0 { buffer.WriteString("|t:") buffer.WriteString(string(e.AlertType)) } writeTagString(&buffer, tags, e.Tags) return buffer.String(), nil }
go
func (e Event) Encode(tags ...string) (string, error) { err := e.Check() if err != nil { return "", err } text := e.escapedText() var buffer bytes.Buffer buffer.WriteString("_e{") buffer.WriteString(strconv.FormatInt(int64(len(e.Title)), 10)) buffer.WriteRune(',') buffer.WriteString(strconv.FormatInt(int64(len(text)), 10)) buffer.WriteString("}:") buffer.WriteString(e.Title) buffer.WriteRune('|') buffer.WriteString(text) if !e.Timestamp.IsZero() { buffer.WriteString("|d:") buffer.WriteString(strconv.FormatInt(int64(e.Timestamp.Unix()), 10)) } if len(e.Hostname) != 0 { buffer.WriteString("|h:") buffer.WriteString(e.Hostname) } if len(e.AggregationKey) != 0 { buffer.WriteString("|k:") buffer.WriteString(e.AggregationKey) } if len(e.Priority) != 0 { buffer.WriteString("|p:") buffer.WriteString(string(e.Priority)) } if len(e.SourceTypeName) != 0 { buffer.WriteString("|s:") buffer.WriteString(e.SourceTypeName) } if len(e.AlertType) != 0 { buffer.WriteString("|t:") buffer.WriteString(string(e.AlertType)) } writeTagString(&buffer, tags, e.Tags) return buffer.String(), nil }
[ "func", "(", "e", "Event", ")", "Encode", "(", "tags", "...", "string", ")", "(", "string", ",", "error", ")", "{", "err", ":=", "e", ".", "Check", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "text", ":=", "e", ".", "escapedText", "(", ")", "\n\n", "var", "buffer", "bytes", ".", "Buffer", "\n", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "strconv", ".", "FormatInt", "(", "int64", "(", "len", "(", "e", ".", "Title", ")", ")", ",", "10", ")", ")", "\n", "buffer", ".", "WriteRune", "(", "','", ")", "\n", "buffer", ".", "WriteString", "(", "strconv", ".", "FormatInt", "(", "int64", "(", "len", "(", "text", ")", ")", ",", "10", ")", ")", "\n", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "e", ".", "Title", ")", "\n", "buffer", ".", "WriteRune", "(", "'|'", ")", "\n", "buffer", ".", "WriteString", "(", "text", ")", "\n\n", "if", "!", "e", ".", "Timestamp", ".", "IsZero", "(", ")", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "strconv", ".", "FormatInt", "(", "int64", "(", "e", ".", "Timestamp", ".", "Unix", "(", ")", ")", ",", "10", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "e", ".", "Hostname", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "e", ".", "Hostname", ")", "\n", "}", "\n\n", "if", "len", "(", "e", ".", "AggregationKey", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "e", ".", "AggregationKey", ")", "\n\n", "}", "\n\n", "if", "len", "(", "e", ".", "Priority", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "string", "(", "e", ".", "Priority", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "e", ".", "SourceTypeName", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "e", ".", "SourceTypeName", ")", "\n", "}", "\n\n", "if", "len", "(", "e", ".", "AlertType", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "string", "(", "e", ".", "AlertType", ")", ")", "\n", "}", "\n\n", "writeTagString", "(", "&", "buffer", ",", "tags", ",", "e", ".", "Tags", ")", "\n\n", "return", "buffer", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// Encode returns the dogstatsd wire protocol representation for an event. // Tags may be passed which will be added to the encoded output but not to // the Event's list of tags, eg. for default tags.
[ "Encode", "returns", "the", "dogstatsd", "wire", "protocol", "representation", "for", "an", "event", ".", "Tags", "may", "be", "passed", "which", "will", "be", "added", "to", "the", "encoded", "output", "but", "not", "to", "the", "Event", "s", "list", "of", "tags", "eg", ".", "for", "default", "tags", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L550-L601
train
DataDog/datadog-go
statsd/statsd.go
NewServiceCheck
func NewServiceCheck(name string, status ServiceCheckStatus) *ServiceCheck { return &ServiceCheck{ Name: name, Status: status, } }
go
func NewServiceCheck(name string, status ServiceCheckStatus) *ServiceCheck { return &ServiceCheck{ Name: name, Status: status, } }
[ "func", "NewServiceCheck", "(", "name", "string", ",", "status", "ServiceCheckStatus", ")", "*", "ServiceCheck", "{", "return", "&", "ServiceCheck", "{", "Name", ":", "name", ",", "Status", ":", "status", ",", "}", "\n", "}" ]
// NewServiceCheck creates a new serviceCheck with the given name and status. Error checking // against these values is done at send-time, or upon running sc.Check.
[ "NewServiceCheck", "creates", "a", "new", "serviceCheck", "with", "the", "given", "name", "and", "status", ".", "Error", "checking", "against", "these", "values", "is", "done", "at", "send", "-", "time", "or", "upon", "running", "sc", ".", "Check", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L636-L641
train
DataDog/datadog-go
statsd/statsd.go
Encode
func (sc ServiceCheck) Encode(tags ...string) (string, error) { err := sc.Check() if err != nil { return "", err } message := sc.escapedMessage() var buffer bytes.Buffer buffer.WriteString("_sc|") buffer.WriteString(sc.Name) buffer.WriteRune('|') buffer.WriteString(strconv.FormatInt(int64(sc.Status), 10)) if !sc.Timestamp.IsZero() { buffer.WriteString("|d:") buffer.WriteString(strconv.FormatInt(int64(sc.Timestamp.Unix()), 10)) } if len(sc.Hostname) != 0 { buffer.WriteString("|h:") buffer.WriteString(sc.Hostname) } writeTagString(&buffer, tags, sc.Tags) if len(message) != 0 { buffer.WriteString("|m:") buffer.WriteString(message) } return buffer.String(), nil }
go
func (sc ServiceCheck) Encode(tags ...string) (string, error) { err := sc.Check() if err != nil { return "", err } message := sc.escapedMessage() var buffer bytes.Buffer buffer.WriteString("_sc|") buffer.WriteString(sc.Name) buffer.WriteRune('|') buffer.WriteString(strconv.FormatInt(int64(sc.Status), 10)) if !sc.Timestamp.IsZero() { buffer.WriteString("|d:") buffer.WriteString(strconv.FormatInt(int64(sc.Timestamp.Unix()), 10)) } if len(sc.Hostname) != 0 { buffer.WriteString("|h:") buffer.WriteString(sc.Hostname) } writeTagString(&buffer, tags, sc.Tags) if len(message) != 0 { buffer.WriteString("|m:") buffer.WriteString(message) } return buffer.String(), nil }
[ "func", "(", "sc", "ServiceCheck", ")", "Encode", "(", "tags", "...", "string", ")", "(", "string", ",", "error", ")", "{", "err", ":=", "sc", ".", "Check", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "message", ":=", "sc", ".", "escapedMessage", "(", ")", "\n\n", "var", "buffer", "bytes", ".", "Buffer", "\n", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "sc", ".", "Name", ")", "\n", "buffer", ".", "WriteRune", "(", "'|'", ")", "\n", "buffer", ".", "WriteString", "(", "strconv", ".", "FormatInt", "(", "int64", "(", "sc", ".", "Status", ")", ",", "10", ")", ")", "\n\n", "if", "!", "sc", ".", "Timestamp", ".", "IsZero", "(", ")", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "strconv", ".", "FormatInt", "(", "int64", "(", "sc", ".", "Timestamp", ".", "Unix", "(", ")", ")", ",", "10", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "sc", ".", "Hostname", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "sc", ".", "Hostname", ")", "\n", "}", "\n\n", "writeTagString", "(", "&", "buffer", ",", "tags", ",", "sc", ".", "Tags", ")", "\n\n", "if", "len", "(", "message", ")", "!=", "0", "{", "buffer", ".", "WriteString", "(", "\"", "\"", ")", "\n", "buffer", ".", "WriteString", "(", "message", ")", "\n", "}", "\n\n", "return", "buffer", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// Encode returns the dogstatsd wire protocol representation for an serviceCheck. // Tags may be passed which will be added to the encoded output but not to // the Event's list of tags, eg. for default tags.
[ "Encode", "returns", "the", "dogstatsd", "wire", "protocol", "representation", "for", "an", "serviceCheck", ".", "Tags", "may", "be", "passed", "which", "will", "be", "added", "to", "the", "encoded", "output", "but", "not", "to", "the", "Event", "s", "list", "of", "tags", "eg", ".", "for", "default", "tags", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/statsd.go#L657-L688
train
DataDog/datadog-go
statsd/uds_async.go
newAsyncUdsWriter
func newAsyncUdsWriter(addr string) (*asyncUdsWriter, error) { udsAddr, err := net.ResolveUnixAddr("unixgram", addr) if err != nil { return nil, err } writer := &asyncUdsWriter{ addr: udsAddr, conn: nil, writeTimeout: defaultUDSTimeout, // 8192 * 8KB = 65.5MB datagramQueue: make(chan []byte, 8192), stopChan: make(chan struct{}, 1), } go writer.sendLoop() return writer, nil }
go
func newAsyncUdsWriter(addr string) (*asyncUdsWriter, error) { udsAddr, err := net.ResolveUnixAddr("unixgram", addr) if err != nil { return nil, err } writer := &asyncUdsWriter{ addr: udsAddr, conn: nil, writeTimeout: defaultUDSTimeout, // 8192 * 8KB = 65.5MB datagramQueue: make(chan []byte, 8192), stopChan: make(chan struct{}, 1), } go writer.sendLoop() return writer, nil }
[ "func", "newAsyncUdsWriter", "(", "addr", "string", ")", "(", "*", "asyncUdsWriter", ",", "error", ")", "{", "udsAddr", ",", "err", ":=", "net", ".", "ResolveUnixAddr", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "writer", ":=", "&", "asyncUdsWriter", "{", "addr", ":", "udsAddr", ",", "conn", ":", "nil", ",", "writeTimeout", ":", "defaultUDSTimeout", ",", "// 8192 * 8KB = 65.5MB", "datagramQueue", ":", "make", "(", "chan", "[", "]", "byte", ",", "8192", ")", ",", "stopChan", ":", "make", "(", "chan", "struct", "{", "}", ",", "1", ")", ",", "}", "\n\n", "go", "writer", ".", "sendLoop", "(", ")", "\n", "return", "writer", ",", "nil", "\n", "}" ]
// New returns a pointer to a new asyncUdsWriter given a socket file path as addr.
[ "New", "returns", "a", "pointer", "to", "a", "new", "asyncUdsWriter", "given", "a", "socket", "file", "path", "as", "addr", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/uds_async.go#L23-L40
train
DataDog/datadog-go
statsd/uds_async.go
SetWriteTimeout
func (w *asyncUdsWriter) SetWriteTimeout(d time.Duration) error { w.writeTimeout = d return nil }
go
func (w *asyncUdsWriter) SetWriteTimeout(d time.Duration) error { w.writeTimeout = d return nil }
[ "func", "(", "w", "*", "asyncUdsWriter", ")", "SetWriteTimeout", "(", "d", "time", ".", "Duration", ")", "error", "{", "w", ".", "writeTimeout", "=", "d", "\n", "return", "nil", "\n", "}" ]
// SetWriteTimeout allows the user to set a custom write timeout
[ "SetWriteTimeout", "allows", "the", "user", "to", "set", "a", "custom", "write", "timeout" ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/uds_async.go#L54-L57
train
DataDog/datadog-go
statsd/udp.go
Write
func (w *udpWriter) Write(data []byte) (int, error) { return w.conn.Write(data) }
go
func (w *udpWriter) Write(data []byte) (int, error) { return w.conn.Write(data) }
[ "func", "(", "w", "*", "udpWriter", ")", "Write", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "return", "w", ".", "conn", ".", "Write", "(", "data", ")", "\n", "}" ]
// Write data to the UDP connection with no error handling
[ "Write", "data", "to", "the", "UDP", "connection", "with", "no", "error", "handling" ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/udp.go#L49-L51
train
DataDog/datadog-go
statsd/options.go
WithNamespace
func WithNamespace(namespace string) Option { return func(o *Options) error { o.Namespace = namespace return nil } }
go
func WithNamespace(namespace string) Option { return func(o *Options) error { o.Namespace = namespace return nil } }
[ "func", "WithNamespace", "(", "namespace", "string", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "Namespace", "=", "namespace", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithNamespace sets the Namespace option.
[ "WithNamespace", "sets", "the", "Namespace", "option", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/options.go#L64-L69
train
DataDog/datadog-go
statsd/options.go
WithTags
func WithTags(tags []string) Option { return func(o *Options) error { o.Tags = tags return nil } }
go
func WithTags(tags []string) Option { return func(o *Options) error { o.Tags = tags return nil } }
[ "func", "WithTags", "(", "tags", "[", "]", "string", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "Tags", "=", "tags", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithTags sets the Tags option.
[ "WithTags", "sets", "the", "Tags", "option", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/options.go#L72-L77
train
DataDog/datadog-go
statsd/options.go
WithMaxMessagesPerPayload
func WithMaxMessagesPerPayload(maxMessagesPerPayload int) Option { return func(o *Options) error { o.MaxMessagesPerPayload = maxMessagesPerPayload return nil } }
go
func WithMaxMessagesPerPayload(maxMessagesPerPayload int) Option { return func(o *Options) error { o.MaxMessagesPerPayload = maxMessagesPerPayload return nil } }
[ "func", "WithMaxMessagesPerPayload", "(", "maxMessagesPerPayload", "int", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "MaxMessagesPerPayload", "=", "maxMessagesPerPayload", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithMaxMessagesPerPayload sets the MaxMessagesPerPayload option.
[ "WithMaxMessagesPerPayload", "sets", "the", "MaxMessagesPerPayload", "option", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/options.go#L88-L93
train
DataDog/datadog-go
statsd/options.go
WithWriteTimeoutUDS
func WithWriteTimeoutUDS(writeTimeoutUDS time.Duration) Option { return func(o *Options) error { o.WriteTimeoutUDS = writeTimeoutUDS return nil } }
go
func WithWriteTimeoutUDS(writeTimeoutUDS time.Duration) Option { return func(o *Options) error { o.WriteTimeoutUDS = writeTimeoutUDS return nil } }
[ "func", "WithWriteTimeoutUDS", "(", "writeTimeoutUDS", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "o", "*", "Options", ")", "error", "{", "o", ".", "WriteTimeoutUDS", "=", "writeTimeoutUDS", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithWriteTimeoutUDS sets the WriteTimeoutUDS option.
[ "WithWriteTimeoutUDS", "sets", "the", "WriteTimeoutUDS", "option", "." ]
40bafcb5f6c1d49df36deaf4ab019e44961d5e36
https://github.com/DataDog/datadog-go/blob/40bafcb5f6c1d49df36deaf4ab019e44961d5e36/statsd/options.go#L104-L109
train
google/go-jsonnet
vm.go
MakeVM
func MakeVM() *VM { return &VM{ MaxStack: 500, ext: make(vmExtMap), tla: make(vmExtMap), nativeFuncs: make(map[string]*NativeFunction), ErrorFormatter: &termErrorFormatter{pretty: false, maxStackTraceSize: 20}, importer: &FileImporter{}, } }
go
func MakeVM() *VM { return &VM{ MaxStack: 500, ext: make(vmExtMap), tla: make(vmExtMap), nativeFuncs: make(map[string]*NativeFunction), ErrorFormatter: &termErrorFormatter{pretty: false, maxStackTraceSize: 20}, importer: &FileImporter{}, } }
[ "func", "MakeVM", "(", ")", "*", "VM", "{", "return", "&", "VM", "{", "MaxStack", ":", "500", ",", "ext", ":", "make", "(", "vmExtMap", ")", ",", "tla", ":", "make", "(", "vmExtMap", ")", ",", "nativeFuncs", ":", "make", "(", "map", "[", "string", "]", "*", "NativeFunction", ")", ",", "ErrorFormatter", ":", "&", "termErrorFormatter", "{", "pretty", ":", "false", ",", "maxStackTraceSize", ":", "20", "}", ",", "importer", ":", "&", "FileImporter", "{", "}", ",", "}", "\n", "}" ]
// MakeVM creates a new VM with default parameters.
[ "MakeVM", "creates", "a", "new", "VM", "with", "default", "parameters", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L55-L64
train
google/go-jsonnet
vm.go
ExtVar
func (vm *VM) ExtVar(key string, val string) { vm.ext[key] = vmExt{value: val, isCode: false} }
go
func (vm *VM) ExtVar(key string, val string) { vm.ext[key] = vmExt{value: val, isCode: false} }
[ "func", "(", "vm", "*", "VM", ")", "ExtVar", "(", "key", "string", ",", "val", "string", ")", "{", "vm", ".", "ext", "[", "key", "]", "=", "vmExt", "{", "value", ":", "val", ",", "isCode", ":", "false", "}", "\n", "}" ]
// ExtVar binds a Jsonnet external var to the given value.
[ "ExtVar", "binds", "a", "Jsonnet", "external", "var", "to", "the", "given", "value", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L67-L69
train
google/go-jsonnet
vm.go
ExtCode
func (vm *VM) ExtCode(key string, val string) { vm.ext[key] = vmExt{value: val, isCode: true} }
go
func (vm *VM) ExtCode(key string, val string) { vm.ext[key] = vmExt{value: val, isCode: true} }
[ "func", "(", "vm", "*", "VM", ")", "ExtCode", "(", "key", "string", ",", "val", "string", ")", "{", "vm", ".", "ext", "[", "key", "]", "=", "vmExt", "{", "value", ":", "val", ",", "isCode", ":", "true", "}", "\n", "}" ]
// ExtCode binds a Jsonnet external code var to the given code.
[ "ExtCode", "binds", "a", "Jsonnet", "external", "code", "var", "to", "the", "given", "code", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L72-L74
train
google/go-jsonnet
vm.go
TLAVar
func (vm *VM) TLAVar(key string, val string) { vm.tla[key] = vmExt{value: val, isCode: false} }
go
func (vm *VM) TLAVar(key string, val string) { vm.tla[key] = vmExt{value: val, isCode: false} }
[ "func", "(", "vm", "*", "VM", ")", "TLAVar", "(", "key", "string", ",", "val", "string", ")", "{", "vm", ".", "tla", "[", "key", "]", "=", "vmExt", "{", "value", ":", "val", ",", "isCode", ":", "false", "}", "\n", "}" ]
// TLAVar binds a Jsonnet top level argument to the given value.
[ "TLAVar", "binds", "a", "Jsonnet", "top", "level", "argument", "to", "the", "given", "value", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L77-L79
train
google/go-jsonnet
vm.go
TLACode
func (vm *VM) TLACode(key string, val string) { vm.tla[key] = vmExt{value: val, isCode: true} }
go
func (vm *VM) TLACode(key string, val string) { vm.tla[key] = vmExt{value: val, isCode: true} }
[ "func", "(", "vm", "*", "VM", ")", "TLACode", "(", "key", "string", ",", "val", "string", ")", "{", "vm", ".", "tla", "[", "key", "]", "=", "vmExt", "{", "value", ":", "val", ",", "isCode", ":", "true", "}", "\n", "}" ]
// TLACode binds a Jsonnet top level argument to the given code.
[ "TLACode", "binds", "a", "Jsonnet", "top", "level", "argument", "to", "the", "given", "code", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L82-L84
train
google/go-jsonnet
vm.go
NativeFunction
func (vm *VM) NativeFunction(f *NativeFunction) { vm.nativeFuncs[f.Name] = f }
go
func (vm *VM) NativeFunction(f *NativeFunction) { vm.nativeFuncs[f.Name] = f }
[ "func", "(", "vm", "*", "VM", ")", "NativeFunction", "(", "f", "*", "NativeFunction", ")", "{", "vm", ".", "nativeFuncs", "[", "f", ".", "Name", "]", "=", "f", "\n", "}" ]
// NativeFunction registers a native function.
[ "NativeFunction", "registers", "a", "native", "function", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L151-L153
train
google/go-jsonnet
vm.go
EvaluateSnippet
func (vm *VM) EvaluateSnippet(filename string, snippet string) (json string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindRegular) if err != nil { return "", errors.New(vm.ErrorFormatter.Format(err)) } json = output.(string) return }
go
func (vm *VM) EvaluateSnippet(filename string, snippet string) (json string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindRegular) if err != nil { return "", errors.New(vm.ErrorFormatter.Format(err)) } json = output.(string) return }
[ "func", "(", "vm", "*", "VM", ")", "EvaluateSnippet", "(", "filename", "string", ",", "snippet", "string", ")", "(", "json", "string", ",", "formattedErr", "error", ")", "{", "output", ",", "err", ":=", "vm", ".", "evaluateSnippet", "(", "filename", ",", "snippet", ",", "evalKindRegular", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "vm", ".", "ErrorFormatter", ".", "Format", "(", "err", ")", ")", "\n", "}", "\n", "json", "=", "output", ".", "(", "string", ")", "\n", "return", "\n", "}" ]
// EvaluateSnippet evaluates a string containing Jsonnet code, return a JSON // string. // // The filename parameter is only used for error messages.
[ "EvaluateSnippet", "evaluates", "a", "string", "containing", "Jsonnet", "code", "return", "a", "JSON", "string", ".", "The", "filename", "parameter", "is", "only", "used", "for", "error", "messages", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L159-L166
train
google/go-jsonnet
vm.go
EvaluateSnippetStream
func (vm *VM) EvaluateSnippetStream(filename string, snippet string) (docs []string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindStream) if err != nil { return nil, errors.New(vm.ErrorFormatter.Format(err)) } docs = output.([]string) return }
go
func (vm *VM) EvaluateSnippetStream(filename string, snippet string) (docs []string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindStream) if err != nil { return nil, errors.New(vm.ErrorFormatter.Format(err)) } docs = output.([]string) return }
[ "func", "(", "vm", "*", "VM", ")", "EvaluateSnippetStream", "(", "filename", "string", ",", "snippet", "string", ")", "(", "docs", "[", "]", "string", ",", "formattedErr", "error", ")", "{", "output", ",", "err", ":=", "vm", ".", "evaluateSnippet", "(", "filename", ",", "snippet", ",", "evalKindStream", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "vm", ".", "ErrorFormatter", ".", "Format", "(", "err", ")", ")", "\n", "}", "\n", "docs", "=", "output", ".", "(", "[", "]", "string", ")", "\n", "return", "\n", "}" ]
// EvaluateSnippetStream evaluates a string containing Jsonnet code to an array. // The array is returned as an array of JSON strings. // // The filename parameter is only used for error messages.
[ "EvaluateSnippetStream", "evaluates", "a", "string", "containing", "Jsonnet", "code", "to", "an", "array", ".", "The", "array", "is", "returned", "as", "an", "array", "of", "JSON", "strings", ".", "The", "filename", "parameter", "is", "only", "used", "for", "error", "messages", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L172-L179
train
google/go-jsonnet
vm.go
EvaluateSnippetMulti
func (vm *VM) EvaluateSnippetMulti(filename string, snippet string) (files map[string]string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindMulti) if err != nil { return nil, errors.New(vm.ErrorFormatter.Format(err)) } files = output.(map[string]string) return }
go
func (vm *VM) EvaluateSnippetMulti(filename string, snippet string) (files map[string]string, formattedErr error) { output, err := vm.evaluateSnippet(filename, snippet, evalKindMulti) if err != nil { return nil, errors.New(vm.ErrorFormatter.Format(err)) } files = output.(map[string]string) return }
[ "func", "(", "vm", "*", "VM", ")", "EvaluateSnippetMulti", "(", "filename", "string", ",", "snippet", "string", ")", "(", "files", "map", "[", "string", "]", "string", ",", "formattedErr", "error", ")", "{", "output", ",", "err", ":=", "vm", ".", "evaluateSnippet", "(", "filename", ",", "snippet", ",", "evalKindMulti", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "vm", ".", "ErrorFormatter", ".", "Format", "(", "err", ")", ")", "\n", "}", "\n", "files", "=", "output", ".", "(", "map", "[", "string", "]", "string", ")", "\n", "return", "\n", "}" ]
// EvaluateSnippetMulti evaluates a string containing Jsonnet code to key-value // pairs. The keys are field name strings and the values are JSON strings. // // The filename parameter is only used for error messages.
[ "EvaluateSnippetMulti", "evaluates", "a", "string", "containing", "Jsonnet", "code", "to", "key", "-", "value", "pairs", ".", "The", "keys", "are", "field", "name", "strings", "and", "the", "values", "are", "JSON", "strings", ".", "The", "filename", "parameter", "is", "only", "used", "for", "error", "messages", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L185-L192
train
google/go-jsonnet
vm.go
SnippetToAST
func SnippetToAST(filename string, snippet string) (ast.Node, error) { return snippetToAST(filename, snippet) }
go
func SnippetToAST(filename string, snippet string) (ast.Node, error) { return snippetToAST(filename, snippet) }
[ "func", "SnippetToAST", "(", "filename", "string", ",", "snippet", "string", ")", "(", "ast", ".", "Node", ",", "error", ")", "{", "return", "snippetToAST", "(", "filename", ",", "snippet", ")", "\n", "}" ]
// SnippetToAST parses a snippet and returns the resulting AST.
[ "SnippetToAST", "parses", "a", "snippet", "and", "returns", "the", "resulting", "AST", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/vm.go#L219-L221
train
google/go-jsonnet
value.go
findField
func findField(curr value, minSuperDepth int, f string) (bool, simpleObjectField, bindingFrame, int) { switch curr := curr.(type) { case *valueExtendedObject: if curr.right.inheritanceSize() > minSuperDepth { found, field, frame, counter := findField(curr.right, minSuperDepth, f) if found { return true, field, frame, counter } } found, field, frame, counter := findField(curr.left, minSuperDepth-curr.right.inheritanceSize(), f) return found, field, frame, counter + curr.right.inheritanceSize() case *valueSimpleObject: if minSuperDepth <= 0 { if field, ok := curr.fields[f]; ok { return true, field, curr.upValues, 0 } } return false, simpleObjectField{}, nil, 0 default: panic(fmt.Sprintf("Unknown object type %#v", curr)) } }
go
func findField(curr value, minSuperDepth int, f string) (bool, simpleObjectField, bindingFrame, int) { switch curr := curr.(type) { case *valueExtendedObject: if curr.right.inheritanceSize() > minSuperDepth { found, field, frame, counter := findField(curr.right, minSuperDepth, f) if found { return true, field, frame, counter } } found, field, frame, counter := findField(curr.left, minSuperDepth-curr.right.inheritanceSize(), f) return found, field, frame, counter + curr.right.inheritanceSize() case *valueSimpleObject: if minSuperDepth <= 0 { if field, ok := curr.fields[f]; ok { return true, field, curr.upValues, 0 } } return false, simpleObjectField{}, nil, 0 default: panic(fmt.Sprintf("Unknown object type %#v", curr)) } }
[ "func", "findField", "(", "curr", "value", ",", "minSuperDepth", "int", ",", "f", "string", ")", "(", "bool", ",", "simpleObjectField", ",", "bindingFrame", ",", "int", ")", "{", "switch", "curr", ":=", "curr", ".", "(", "type", ")", "{", "case", "*", "valueExtendedObject", ":", "if", "curr", ".", "right", ".", "inheritanceSize", "(", ")", ">", "minSuperDepth", "{", "found", ",", "field", ",", "frame", ",", "counter", ":=", "findField", "(", "curr", ".", "right", ",", "minSuperDepth", ",", "f", ")", "\n", "if", "found", "{", "return", "true", ",", "field", ",", "frame", ",", "counter", "\n", "}", "\n", "}", "\n", "found", ",", "field", ",", "frame", ",", "counter", ":=", "findField", "(", "curr", ".", "left", ",", "minSuperDepth", "-", "curr", ".", "right", ".", "inheritanceSize", "(", ")", ",", "f", ")", "\n", "return", "found", ",", "field", ",", "frame", ",", "counter", "+", "curr", ".", "right", ".", "inheritanceSize", "(", ")", "\n\n", "case", "*", "valueSimpleObject", ":", "if", "minSuperDepth", "<=", "0", "{", "if", "field", ",", "ok", ":=", "curr", ".", "fields", "[", "f", "]", ";", "ok", "{", "return", "true", ",", "field", ",", "curr", ".", "upValues", ",", "0", "\n", "}", "\n", "}", "\n", "return", "false", ",", "simpleObjectField", "{", "}", ",", "nil", ",", "0", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "curr", ")", ")", "\n", "}", "\n", "}" ]
// findField returns a field in object curr, with superDepth at least minSuperDepth // It also returns an associated bindingFrame and actual superDepth that the field // was found at.
[ "findField", "returns", "a", "field", "in", "object", "curr", "with", "superDepth", "at", "least", "minSuperDepth", "It", "also", "returns", "an", "associated", "bindingFrame", "and", "actual", "superDepth", "that", "the", "field", "was", "found", "at", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/value.go#L582-L604
train
google/go-jsonnet
dump/utils.go
deInterface
func deInterface(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } return v }
go
func deInterface(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } return v }
[ "func", "deInterface", "(", "v", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "&&", "!", "v", ".", "IsNil", "(", ")", "{", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// deInterface returns values inside of non-nil interfaces when possible. // This is useful for data types like structs, arrays, slices, and maps which // can contain varying types packed inside an interface.
[ "deInterface", "returns", "values", "inside", "of", "non", "-", "nil", "interfaces", "when", "possible", ".", "This", "is", "useful", "for", "data", "types", "like", "structs", "arrays", "slices", "and", "maps", "which", "can", "contain", "varying", "types", "packed", "inside", "an", "interface", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/dump/utils.go#L69-L74
train
google/go-jsonnet
parser/static_error.go
MakeStaticError
func MakeStaticError(msg string, lr ast.LocationRange) StaticError { return StaticError{Msg: msg, Loc: lr} }
go
func MakeStaticError(msg string, lr ast.LocationRange) StaticError { return StaticError{Msg: msg, Loc: lr} }
[ "func", "MakeStaticError", "(", "msg", "string", ",", "lr", "ast", ".", "LocationRange", ")", "StaticError", "{", "return", "StaticError", "{", "Msg", ":", "msg", ",", "Loc", ":", "lr", "}", "\n", "}" ]
// MakeStaticError returns a StaticError with a message and a LocationRange.
[ "MakeStaticError", "returns", "a", "StaticError", "with", "a", "message", "and", "a", "LocationRange", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/static_error.go#L41-L43
train
google/go-jsonnet
parser/static_error.go
Error
func (err StaticError) Error() string { loc := "" if err.Loc.IsSet() { loc = err.Loc.String() } return fmt.Sprintf("%v %v", loc, err.Msg) }
go
func (err StaticError) Error() string { loc := "" if err.Loc.IsSet() { loc = err.Loc.String() } return fmt.Sprintf("%v %v", loc, err.Msg) }
[ "func", "(", "err", "StaticError", ")", "Error", "(", ")", "string", "{", "loc", ":=", "\"", "\"", "\n", "if", "err", ".", "Loc", ".", "IsSet", "(", ")", "{", "loc", "=", "err", ".", "Loc", ".", "String", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "loc", ",", "err", ".", "Msg", ")", "\n", "}" ]
// Error returns the string representation of a StaticError.
[ "Error", "returns", "the", "string", "representation", "of", "a", "StaticError", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/static_error.go#L46-L52
train
google/go-jsonnet
linter/linter.go
Lint
func Lint(node ast.Node, e *ErrorWriter) { lintingInfo := LintingInfo{ variables: nil, } std := variable{ name: "std", declNode: nil, uses: nil, param: false, } findVariables(node, &lintingInfo, vScope{"std": &std}) for _, v := range lintingInfo.variables { if len(v.uses) == 0 && !v.param { e.writeError(parser.MakeStaticError("Unused variable: "+string(v.name), *v.declNode.Loc())) } } }
go
func Lint(node ast.Node, e *ErrorWriter) { lintingInfo := LintingInfo{ variables: nil, } std := variable{ name: "std", declNode: nil, uses: nil, param: false, } findVariables(node, &lintingInfo, vScope{"std": &std}) for _, v := range lintingInfo.variables { if len(v.uses) == 0 && !v.param { e.writeError(parser.MakeStaticError("Unused variable: "+string(v.name), *v.declNode.Loc())) } } }
[ "func", "Lint", "(", "node", "ast", ".", "Node", ",", "e", "*", "ErrorWriter", ")", "{", "lintingInfo", ":=", "LintingInfo", "{", "variables", ":", "nil", ",", "}", "\n", "std", ":=", "variable", "{", "name", ":", "\"", "\"", ",", "declNode", ":", "nil", ",", "uses", ":", "nil", ",", "param", ":", "false", ",", "}", "\n", "findVariables", "(", "node", ",", "&", "lintingInfo", ",", "vScope", "{", "\"", "\"", ":", "&", "std", "}", ")", "\n", "for", "_", ",", "v", ":=", "range", "lintingInfo", ".", "variables", "{", "if", "len", "(", "v", ".", "uses", ")", "==", "0", "&&", "!", "v", ".", "param", "{", "e", ".", "writeError", "(", "parser", ".", "MakeStaticError", "(", "\"", "\"", "+", "string", "(", "v", ".", "name", ")", ",", "*", "v", ".", "declNode", ".", "Loc", "(", ")", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Lint analyses a node and reports any issues it encounters to an error writer.
[ "Lint", "analyses", "a", "node", "and", "reports", "any", "issues", "it", "encounters", "to", "an", "error", "writer", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/linter/linter.go#L39-L55
train
google/go-jsonnet
imports.go
MakeImportCache
func MakeImportCache(importer Importer) *ImportCache { return &ImportCache{ importer: importer, foundAtVerification: make(map[string]Contents), codeCache: make(map[string]potentialValue), } }
go
func MakeImportCache(importer Importer) *ImportCache { return &ImportCache{ importer: importer, foundAtVerification: make(map[string]Contents), codeCache: make(map[string]potentialValue), } }
[ "func", "MakeImportCache", "(", "importer", "Importer", ")", "*", "ImportCache", "{", "return", "&", "ImportCache", "{", "importer", ":", "importer", ",", "foundAtVerification", ":", "make", "(", "map", "[", "string", "]", "Contents", ")", ",", "codeCache", ":", "make", "(", "map", "[", "string", "]", "potentialValue", ")", ",", "}", "\n", "}" ]
// MakeImportCache creates an ImportCache using an Importer.
[ "MakeImportCache", "creates", "an", "ImportCache", "using", "an", "Importer", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/imports.go#L77-L83
train
google/go-jsonnet
imports.go
ImportString
func (cache *ImportCache) ImportString(importedFrom, importedPath string, i *interpreter, trace TraceElement) (*valueString, error) { data, _, err := cache.importData(importedFrom, importedPath) if err != nil { return nil, i.Error(err.Error(), trace) } return makeValueString(data.String()), nil }
go
func (cache *ImportCache) ImportString(importedFrom, importedPath string, i *interpreter, trace TraceElement) (*valueString, error) { data, _, err := cache.importData(importedFrom, importedPath) if err != nil { return nil, i.Error(err.Error(), trace) } return makeValueString(data.String()), nil }
[ "func", "(", "cache", "*", "ImportCache", ")", "ImportString", "(", "importedFrom", ",", "importedPath", "string", ",", "i", "*", "interpreter", ",", "trace", "TraceElement", ")", "(", "*", "valueString", ",", "error", ")", "{", "data", ",", "_", ",", "err", ":=", "cache", ".", "importData", "(", "importedFrom", ",", "importedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "i", ".", "Error", "(", "err", ".", "Error", "(", ")", ",", "trace", ")", "\n", "}", "\n", "return", "makeValueString", "(", "data", ".", "String", "(", ")", ")", ",", "nil", "\n", "}" ]
// ImportString imports a string, caches it and then returns it.
[ "ImportString", "imports", "a", "string", "caches", "it", "and", "then", "returns", "it", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/imports.go#L101-L107
train
google/go-jsonnet
imports.go
ImportCode
func (cache *ImportCache) ImportCode(importedFrom, importedPath string, i *interpreter, trace TraceElement) (value, error) { contents, foundAt, err := cache.importData(importedFrom, importedPath) if err != nil { return nil, i.Error(err.Error(), trace) } var pv potentialValue if cachedPV, isCached := cache.codeCache[foundAt]; !isCached { // File hasn't been parsed and analyzed before, update the cache record. pv = codeToPV(i, foundAt, contents.String()) cache.codeCache[foundAt] = pv } else { pv = cachedPV } return i.evaluatePV(pv, trace) }
go
func (cache *ImportCache) ImportCode(importedFrom, importedPath string, i *interpreter, trace TraceElement) (value, error) { contents, foundAt, err := cache.importData(importedFrom, importedPath) if err != nil { return nil, i.Error(err.Error(), trace) } var pv potentialValue if cachedPV, isCached := cache.codeCache[foundAt]; !isCached { // File hasn't been parsed and analyzed before, update the cache record. pv = codeToPV(i, foundAt, contents.String()) cache.codeCache[foundAt] = pv } else { pv = cachedPV } return i.evaluatePV(pv, trace) }
[ "func", "(", "cache", "*", "ImportCache", ")", "ImportCode", "(", "importedFrom", ",", "importedPath", "string", ",", "i", "*", "interpreter", ",", "trace", "TraceElement", ")", "(", "value", ",", "error", ")", "{", "contents", ",", "foundAt", ",", "err", ":=", "cache", ".", "importData", "(", "importedFrom", ",", "importedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "i", ".", "Error", "(", "err", ".", "Error", "(", ")", ",", "trace", ")", "\n", "}", "\n", "var", "pv", "potentialValue", "\n", "if", "cachedPV", ",", "isCached", ":=", "cache", ".", "codeCache", "[", "foundAt", "]", ";", "!", "isCached", "{", "// File hasn't been parsed and analyzed before, update the cache record.", "pv", "=", "codeToPV", "(", "i", ",", "foundAt", ",", "contents", ".", "String", "(", ")", ")", "\n", "cache", ".", "codeCache", "[", "foundAt", "]", "=", "pv", "\n", "}", "else", "{", "pv", "=", "cachedPV", "\n", "}", "\n", "return", "i", ".", "evaluatePV", "(", "pv", ",", "trace", ")", "\n", "}" ]
// ImportCode imports code from a path.
[ "ImportCode", "imports", "code", "from", "a", "path", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/imports.go#L128-L142
train
google/go-jsonnet
imports.go
Import
func (importer *FileImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) { dir, _ := path.Split(importedFrom) found, content, foundHere, err := importer.tryPath(dir, importedPath) if err != nil { return Contents{}, "", err } for i := len(importer.JPaths) - 1; !found && i >= 0; i-- { found, content, foundHere, err = importer.tryPath(importer.JPaths[i], importedPath) if err != nil { return Contents{}, "", err } } if !found { return Contents{}, "", fmt.Errorf("couldn't open import %#v: no match locally or in the Jsonnet library paths", importedPath) } return content, foundHere, nil }
go
func (importer *FileImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) { dir, _ := path.Split(importedFrom) found, content, foundHere, err := importer.tryPath(dir, importedPath) if err != nil { return Contents{}, "", err } for i := len(importer.JPaths) - 1; !found && i >= 0; i-- { found, content, foundHere, err = importer.tryPath(importer.JPaths[i], importedPath) if err != nil { return Contents{}, "", err } } if !found { return Contents{}, "", fmt.Errorf("couldn't open import %#v: no match locally or in the Jsonnet library paths", importedPath) } return content, foundHere, nil }
[ "func", "(", "importer", "*", "FileImporter", ")", "Import", "(", "importedFrom", ",", "importedPath", "string", ")", "(", "contents", "Contents", ",", "foundAt", "string", ",", "err", "error", ")", "{", "dir", ",", "_", ":=", "path", ".", "Split", "(", "importedFrom", ")", "\n", "found", ",", "content", ",", "foundHere", ",", "err", ":=", "importer", ".", "tryPath", "(", "dir", ",", "importedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Contents", "{", "}", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "for", "i", ":=", "len", "(", "importer", ".", "JPaths", ")", "-", "1", ";", "!", "found", "&&", "i", ">=", "0", ";", "i", "--", "{", "found", ",", "content", ",", "foundHere", ",", "err", "=", "importer", ".", "tryPath", "(", "importer", ".", "JPaths", "[", "i", "]", ",", "importedPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Contents", "{", "}", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n\n", "if", "!", "found", "{", "return", "Contents", "{", "}", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "importedPath", ")", "\n", "}", "\n", "return", "content", ",", "foundHere", ",", "nil", "\n", "}" ]
// Import imports file from the filesystem.
[ "Import", "imports", "file", "from", "the", "filesystem", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/imports.go#L193-L211
train
google/go-jsonnet
imports.go
Import
func (importer *MemoryImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) { if content, ok := importer.Data[importedPath]; ok { return content, importedPath, nil } return Contents{}, "", fmt.Errorf("import not available %v", importedPath) }
go
func (importer *MemoryImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) { if content, ok := importer.Data[importedPath]; ok { return content, importedPath, nil } return Contents{}, "", fmt.Errorf("import not available %v", importedPath) }
[ "func", "(", "importer", "*", "MemoryImporter", ")", "Import", "(", "importedFrom", ",", "importedPath", "string", ")", "(", "contents", "Contents", ",", "foundAt", "string", ",", "err", "error", ")", "{", "if", "content", ",", "ok", ":=", "importer", ".", "Data", "[", "importedPath", "]", ";", "ok", "{", "return", "content", ",", "importedPath", ",", "nil", "\n", "}", "\n", "return", "Contents", "{", "}", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "importedPath", ")", "\n", "}" ]
// Import fetches data from a map entry. // All paths are treated as absolute keys.
[ "Import", "fetches", "data", "from", "a", "map", "entry", ".", "All", "paths", "are", "treated", "as", "absolute", "keys", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/imports.go#L220-L225
train
google/go-jsonnet
cmd/jsonnet/cmd.go
writeOutputStream
func writeOutputStream(output []string, outputFile string) error { var f *os.File if outputFile == "" { f = os.Stdout } else { var err error f, err = os.Create(outputFile) if err != nil { return err } defer f.Close() } for _, doc := range output { _, err := f.WriteString("---\n") if err != nil { return err } _, err = f.WriteString(doc) if err != nil { return err } } if len(output) > 0 { _, err := f.WriteString("...\n") if err != nil { return err } } return nil }
go
func writeOutputStream(output []string, outputFile string) error { var f *os.File if outputFile == "" { f = os.Stdout } else { var err error f, err = os.Create(outputFile) if err != nil { return err } defer f.Close() } for _, doc := range output { _, err := f.WriteString("---\n") if err != nil { return err } _, err = f.WriteString(doc) if err != nil { return err } } if len(output) > 0 { _, err := f.WriteString("...\n") if err != nil { return err } } return nil }
[ "func", "writeOutputStream", "(", "output", "[", "]", "string", ",", "outputFile", "string", ")", "error", "{", "var", "f", "*", "os", ".", "File", "\n\n", "if", "outputFile", "==", "\"", "\"", "{", "f", "=", "os", ".", "Stdout", "\n", "}", "else", "{", "var", "err", "error", "\n", "f", ",", "err", "=", "os", ".", "Create", "(", "outputFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "}", "\n\n", "for", "_", ",", "doc", ":=", "range", "output", "{", "_", ",", "err", ":=", "f", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "f", ".", "WriteString", "(", "doc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "output", ")", ">", "0", "{", "_", ",", "err", ":=", "f", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// writeOutputStream writes the output as a YAML stream.
[ "writeOutputStream", "writes", "the", "output", "as", "a", "YAML", "stream", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/cmd/jsonnet/cmd.go#L442-L475
train
google/go-jsonnet
parser/lexer.go
checkWhitespace
func checkWhitespace(a, b string) int { i := 0 for ; i < len(a); i++ { if a[i] != ' ' && a[i] != '\t' { // a has run out of whitespace and b matched up to this point. Return // result. return i } if i >= len(b) { // We ran off the edge of b while a still has whitespace. Return 0 as // failure. return 0 } if a[i] != b[i] { // a has whitespace but b does not. Return 0 as failure. return 0 } } // We ran off the end of a and b kept up return i }
go
func checkWhitespace(a, b string) int { i := 0 for ; i < len(a); i++ { if a[i] != ' ' && a[i] != '\t' { // a has run out of whitespace and b matched up to this point. Return // result. return i } if i >= len(b) { // We ran off the edge of b while a still has whitespace. Return 0 as // failure. return 0 } if a[i] != b[i] { // a has whitespace but b does not. Return 0 as failure. return 0 } } // We ran off the end of a and b kept up return i }
[ "func", "checkWhitespace", "(", "a", ",", "b", "string", ")", "int", "{", "i", ":=", "0", "\n", "for", ";", "i", "<", "len", "(", "a", ")", ";", "i", "++", "{", "if", "a", "[", "i", "]", "!=", "' '", "&&", "a", "[", "i", "]", "!=", "'\\t'", "{", "// a has run out of whitespace and b matched up to this point. Return", "// result.", "return", "i", "\n", "}", "\n", "if", "i", ">=", "len", "(", "b", ")", "{", "// We ran off the edge of b while a still has whitespace. Return 0 as", "// failure.", "return", "0", "\n", "}", "\n", "if", "a", "[", "i", "]", "!=", "b", "[", "i", "]", "{", "// a has whitespace but b does not. Return 0 as failure.", "return", "0", "\n", "}", "\n", "}", "\n", "// We ran off the end of a and b kept up", "return", "i", "\n", "}" ]
// Check that b has at least the same whitespace prefix as a and returns the // amount of this whitespace, otherwise returns 0. If a has no whitespace // prefix than return 0.
[ "Check", "that", "b", "has", "at", "least", "the", "same", "whitespace", "prefix", "as", "a", "and", "returns", "the", "amount", "of", "this", "whitespace", "otherwise", "returns", "0", ".", "If", "a", "has", "no", "whitespace", "prefix", "than", "return", "0", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L235-L255
train
google/go-jsonnet
parser/lexer.go
backup
func (l *lexer) backup() { if l.prev.byteNo == lexEOF { panic("backup called with no valid previous rune") } l.pos = l.prev l.prev = position{byteNo: lexEOF} }
go
func (l *lexer) backup() { if l.prev.byteNo == lexEOF { panic("backup called with no valid previous rune") } l.pos = l.prev l.prev = position{byteNo: lexEOF} }
[ "func", "(", "l", "*", "lexer", ")", "backup", "(", ")", "{", "if", "l", ".", "prev", ".", "byteNo", "==", "lexEOF", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "pos", "=", "l", ".", "prev", "\n", "l", ".", "prev", "=", "position", "{", "byteNo", ":", "lexEOF", "}", "\n", "}" ]
// backup steps back one rune. Can only be called once per call of next. // It also does not recover the previous value of freshLine.
[ "backup", "steps", "back", "one", "rune", ".", "Can", "only", "be", "called", "once", "per", "call", "of", "next", ".", "It", "also", "does", "not", "recover", "the", "previous", "value", "of", "freshLine", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L335-L341
train
google/go-jsonnet
parser/lexer.go
resetTokenStart
func (l *lexer) resetTokenStart() { l.tokenStart = l.pos.byteNo l.tokenStartLoc = l.location() }
go
func (l *lexer) resetTokenStart() { l.tokenStart = l.pos.byteNo l.tokenStartLoc = l.location() }
[ "func", "(", "l", "*", "lexer", ")", "resetTokenStart", "(", ")", "{", "l", ".", "tokenStart", "=", "l", ".", "pos", ".", "byteNo", "\n", "l", ".", "tokenStartLoc", "=", "l", ".", "location", "(", ")", "\n", "}" ]
// Reset the current working token start to the current cursor position. This // may throw away some characters. This does not throw away any accumulated // fodder.
[ "Reset", "the", "current", "working", "token", "start", "to", "the", "current", "cursor", "position", ".", "This", "may", "throw", "away", "some", "characters", ".", "This", "does", "not", "throw", "away", "any", "accumulated", "fodder", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L361-L364
train
google/go-jsonnet
parser/lexer.go
lexWhitespace
func (l *lexer) lexWhitespace() (int, int) { r := l.next() indent := 0 newLines := 0 for ; isWhitespace(r); r = l.next() { switch r { case '\r': // Ignore. break case '\n': indent = 0 newLines++ break case ' ': indent++ break // This only works for \t at the beginning of lines, but we strip it everywhere else // anyway. The only case where this will cause a problem is spaces followed by \t // at the beginning of a line. However that is rare, ill-advised, and if re-indentation // is enabled it will be fixed later. case '\t': indent += 8 break } } l.backup() return newLines, indent }
go
func (l *lexer) lexWhitespace() (int, int) { r := l.next() indent := 0 newLines := 0 for ; isWhitespace(r); r = l.next() { switch r { case '\r': // Ignore. break case '\n': indent = 0 newLines++ break case ' ': indent++ break // This only works for \t at the beginning of lines, but we strip it everywhere else // anyway. The only case where this will cause a problem is spaces followed by \t // at the beginning of a line. However that is rare, ill-advised, and if re-indentation // is enabled it will be fixed later. case '\t': indent += 8 break } } l.backup() return newLines, indent }
[ "func", "(", "l", "*", "lexer", ")", "lexWhitespace", "(", ")", "(", "int", ",", "int", ")", "{", "r", ":=", "l", ".", "next", "(", ")", "\n", "indent", ":=", "0", "\n", "newLines", ":=", "0", "\n", "for", ";", "isWhitespace", "(", "r", ")", ";", "r", "=", "l", ".", "next", "(", ")", "{", "switch", "r", "{", "case", "'\\r'", ":", "// Ignore.", "break", "\n\n", "case", "'\\n'", ":", "indent", "=", "0", "\n", "newLines", "++", "\n", "break", "\n\n", "case", "' '", ":", "indent", "++", "\n", "break", "\n\n", "// This only works for \\t at the beginning of lines, but we strip it everywhere else", "// anyway. The only case where this will cause a problem is spaces followed by \\t", "// at the beginning of a line. However that is rare, ill-advised, and if re-indentation", "// is enabled it will be fixed later.", "case", "'\\t'", ":", "indent", "+=", "8", "\n", "break", "\n", "}", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n", "return", "newLines", ",", "indent", "\n", "}" ]
// lexWhitespace consumes all whitespace and returns the number of \n and number of // spaces after last \n. It also converts \t to spaces. // The parameter 'r' is the rune that begins the whitespace.
[ "lexWhitespace", "consumes", "all", "whitespace", "and", "returns", "the", "number", "of", "\\", "n", "and", "number", "of", "spaces", "after", "last", "\\", "n", ".", "It", "also", "converts", "\\", "t", "to", "spaces", ".", "The", "parameter", "r", "is", "the", "rune", "that", "begins", "the", "whitespace", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L395-L425
train
google/go-jsonnet
parser/lexer.go
lexUntilNewline
func (l *lexer) lexUntilNewline() (string, int, int) { // Compute 'text'. var buf bytes.Buffer lastNonSpace := 0 for r := l.next(); r != lexEOF && r != '\n'; r = l.next() { buf.WriteRune(r) if !isHorizontalWhitespace(r) { lastNonSpace = buf.Len() } } l.backup() // Trim whitespace off the end. buf.Truncate(lastNonSpace) text := buf.String() // Consume the '\n' and following indent. var newLines int newLines, indent := l.lexWhitespace() blanks := 0 if newLines > 0 { blanks = newLines - 1 } return text, blanks, indent }
go
func (l *lexer) lexUntilNewline() (string, int, int) { // Compute 'text'. var buf bytes.Buffer lastNonSpace := 0 for r := l.next(); r != lexEOF && r != '\n'; r = l.next() { buf.WriteRune(r) if !isHorizontalWhitespace(r) { lastNonSpace = buf.Len() } } l.backup() // Trim whitespace off the end. buf.Truncate(lastNonSpace) text := buf.String() // Consume the '\n' and following indent. var newLines int newLines, indent := l.lexWhitespace() blanks := 0 if newLines > 0 { blanks = newLines - 1 } return text, blanks, indent }
[ "func", "(", "l", "*", "lexer", ")", "lexUntilNewline", "(", ")", "(", "string", ",", "int", ",", "int", ")", "{", "// Compute 'text'.", "var", "buf", "bytes", ".", "Buffer", "\n", "lastNonSpace", ":=", "0", "\n", "for", "r", ":=", "l", ".", "next", "(", ")", ";", "r", "!=", "lexEOF", "&&", "r", "!=", "'\\n'", ";", "r", "=", "l", ".", "next", "(", ")", "{", "buf", ".", "WriteRune", "(", "r", ")", "\n", "if", "!", "isHorizontalWhitespace", "(", "r", ")", "{", "lastNonSpace", "=", "buf", ".", "Len", "(", ")", "\n", "}", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n", "// Trim whitespace off the end.", "buf", ".", "Truncate", "(", "lastNonSpace", ")", "\n", "text", ":=", "buf", ".", "String", "(", ")", "\n\n", "// Consume the '\\n' and following indent.", "var", "newLines", "int", "\n", "newLines", ",", "indent", ":=", "l", ".", "lexWhitespace", "(", ")", "\n", "blanks", ":=", "0", "\n", "if", "newLines", ">", "0", "{", "blanks", "=", "newLines", "-", "1", "\n", "}", "\n", "return", "text", ",", "blanks", ",", "indent", "\n", "}" ]
// lexUntilNewLine consumes all text until the end of the line and returns the // number of newlines after that as well as the next indent.
[ "lexUntilNewLine", "consumes", "all", "text", "until", "the", "end", "of", "the", "line", "and", "returns", "the", "number", "of", "newlines", "after", "that", "as", "well", "as", "the", "next", "indent", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L429-L452
train
google/go-jsonnet
parser/lexer.go
lexNumber
func (l *lexer) lexNumber() error { // This function should be understood with reference to the linked image: // http://www.json.org/number.gif // Note, we deviate from the json.org documentation as follows: // There is no reason to lex negative numbers as atomic tokens, it is better to parse them // as a unary operator combined with a numeric literal. This avoids x-1 being tokenized as // <identifier> <number> instead of the intended <identifier> <binop> <number>. type numLexState int const ( numBegin numLexState = iota numAfterZero numAfterOneToNine numAfterDot numAfterDigit numAfterE numAfterExpSign numAfterExpDigit ) state := numBegin outerLoop: for true { r := l.next() switch state { case numBegin: switch { case r == '0': state = numAfterZero case r >= '1' && r <= '9': state = numAfterOneToNine default: // The caller should ensure the first rune is a digit. panic("Couldn't lex number") } case numAfterZero: switch r { case '.': state = numAfterDot case 'e', 'E': state = numAfterE default: break outerLoop } case numAfterOneToNine: switch { case r == '.': state = numAfterDot case r == 'e' || r == 'E': state = numAfterE case r >= '0' && r <= '9': state = numAfterOneToNine default: break outerLoop } case numAfterDot: switch { case r >= '0' && r <= '9': state = numAfterDigit default: return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after decimal point: %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterDigit: switch { case r == 'e' || r == 'E': state = numAfterE case r >= '0' && r <= '9': state = numAfterDigit default: break outerLoop } case numAfterE: switch { case r == '+' || r == '-': state = numAfterExpSign case r >= '0' && r <= '9': state = numAfterExpDigit default: return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after 'E': %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterExpSign: if r >= '0' && r <= '9' { state = numAfterExpDigit } else { return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after exponent sign: %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterExpDigit: if r >= '0' && r <= '9' { state = numAfterExpDigit } else { break outerLoop } } } l.backup() l.emitToken(tokenNumber) return nil }
go
func (l *lexer) lexNumber() error { // This function should be understood with reference to the linked image: // http://www.json.org/number.gif // Note, we deviate from the json.org documentation as follows: // There is no reason to lex negative numbers as atomic tokens, it is better to parse them // as a unary operator combined with a numeric literal. This avoids x-1 being tokenized as // <identifier> <number> instead of the intended <identifier> <binop> <number>. type numLexState int const ( numBegin numLexState = iota numAfterZero numAfterOneToNine numAfterDot numAfterDigit numAfterE numAfterExpSign numAfterExpDigit ) state := numBegin outerLoop: for true { r := l.next() switch state { case numBegin: switch { case r == '0': state = numAfterZero case r >= '1' && r <= '9': state = numAfterOneToNine default: // The caller should ensure the first rune is a digit. panic("Couldn't lex number") } case numAfterZero: switch r { case '.': state = numAfterDot case 'e', 'E': state = numAfterE default: break outerLoop } case numAfterOneToNine: switch { case r == '.': state = numAfterDot case r == 'e' || r == 'E': state = numAfterE case r >= '0' && r <= '9': state = numAfterOneToNine default: break outerLoop } case numAfterDot: switch { case r >= '0' && r <= '9': state = numAfterDigit default: return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after decimal point: %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterDigit: switch { case r == 'e' || r == 'E': state = numAfterE case r >= '0' && r <= '9': state = numAfterDigit default: break outerLoop } case numAfterE: switch { case r == '+' || r == '-': state = numAfterExpSign case r >= '0' && r <= '9': state = numAfterExpDigit default: return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after 'E': %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterExpSign: if r >= '0' && r <= '9' { state = numAfterExpDigit } else { return l.makeStaticErrorPoint( fmt.Sprintf("Couldn't lex number, junk after exponent sign: %v", strconv.QuoteRuneToASCII(r)), l.prevLocation()) } case numAfterExpDigit: if r >= '0' && r <= '9' { state = numAfterExpDigit } else { break outerLoop } } } l.backup() l.emitToken(tokenNumber) return nil }
[ "func", "(", "l", "*", "lexer", ")", "lexNumber", "(", ")", "error", "{", "// This function should be understood with reference to the linked image:", "// http://www.json.org/number.gif", "// Note, we deviate from the json.org documentation as follows:", "// There is no reason to lex negative numbers as atomic tokens, it is better to parse them", "// as a unary operator combined with a numeric literal. This avoids x-1 being tokenized as", "// <identifier> <number> instead of the intended <identifier> <binop> <number>.", "type", "numLexState", "int", "\n", "const", "(", "numBegin", "numLexState", "=", "iota", "\n", "numAfterZero", "\n", "numAfterOneToNine", "\n", "numAfterDot", "\n", "numAfterDigit", "\n", "numAfterE", "\n", "numAfterExpSign", "\n", "numAfterExpDigit", "\n", ")", "\n\n", "state", ":=", "numBegin", "\n\n", "outerLoop", ":", "for", "true", "{", "r", ":=", "l", ".", "next", "(", ")", "\n", "switch", "state", "{", "case", "numBegin", ":", "switch", "{", "case", "r", "==", "'0'", ":", "state", "=", "numAfterZero", "\n", "case", "r", ">=", "'1'", "&&", "r", "<=", "'9'", ":", "state", "=", "numAfterOneToNine", "\n", "default", ":", "// The caller should ensure the first rune is a digit.", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "case", "numAfterZero", ":", "switch", "r", "{", "case", "'.'", ":", "state", "=", "numAfterDot", "\n", "case", "'e'", ",", "'E'", ":", "state", "=", "numAfterE", "\n", "default", ":", "break", "outerLoop", "\n", "}", "\n", "case", "numAfterOneToNine", ":", "switch", "{", "case", "r", "==", "'.'", ":", "state", "=", "numAfterDot", "\n", "case", "r", "==", "'e'", "||", "r", "==", "'E'", ":", "state", "=", "numAfterE", "\n", "case", "r", ">=", "'0'", "&&", "r", "<=", "'9'", ":", "state", "=", "numAfterOneToNine", "\n", "default", ":", "break", "outerLoop", "\n", "}", "\n", "case", "numAfterDot", ":", "switch", "{", "case", "r", ">=", "'0'", "&&", "r", "<=", "'9'", ":", "state", "=", "numAfterDigit", "\n", "default", ":", "return", "l", ".", "makeStaticErrorPoint", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strconv", ".", "QuoteRuneToASCII", "(", "r", ")", ")", ",", "l", ".", "prevLocation", "(", ")", ")", "\n", "}", "\n", "case", "numAfterDigit", ":", "switch", "{", "case", "r", "==", "'e'", "||", "r", "==", "'E'", ":", "state", "=", "numAfterE", "\n", "case", "r", ">=", "'0'", "&&", "r", "<=", "'9'", ":", "state", "=", "numAfterDigit", "\n", "default", ":", "break", "outerLoop", "\n", "}", "\n", "case", "numAfterE", ":", "switch", "{", "case", "r", "==", "'+'", "||", "r", "==", "'-'", ":", "state", "=", "numAfterExpSign", "\n", "case", "r", ">=", "'0'", "&&", "r", "<=", "'9'", ":", "state", "=", "numAfterExpDigit", "\n", "default", ":", "return", "l", ".", "makeStaticErrorPoint", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strconv", ".", "QuoteRuneToASCII", "(", "r", ")", ")", ",", "l", ".", "prevLocation", "(", ")", ")", "\n", "}", "\n", "case", "numAfterExpSign", ":", "if", "r", ">=", "'0'", "&&", "r", "<=", "'9'", "{", "state", "=", "numAfterExpDigit", "\n", "}", "else", "{", "return", "l", ".", "makeStaticErrorPoint", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strconv", ".", "QuoteRuneToASCII", "(", "r", ")", ")", ",", "l", ".", "prevLocation", "(", ")", ")", "\n", "}", "\n\n", "case", "numAfterExpDigit", ":", "if", "r", ">=", "'0'", "&&", "r", "<=", "'9'", "{", "state", "=", "numAfterExpDigit", "\n", "}", "else", "{", "break", "outerLoop", "\n", "}", "\n", "}", "\n", "}", "\n\n", "l", ".", "backup", "(", ")", "\n", "l", ".", "emitToken", "(", "tokenNumber", ")", "\n", "return", "nil", "\n", "}" ]
// lexNumber will consume a number and emit a token. It is assumed // that the next rune to be served by the lexer will be a leading digit.
[ "lexNumber", "will", "consume", "a", "number", "and", "emit", "a", "token", ".", "It", "is", "assumed", "that", "the", "next", "rune", "to", "be", "served", "by", "the", "lexer", "will", "be", "a", "leading", "digit", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L456-L563
train
google/go-jsonnet
parser/lexer.go
lexIdentifier
func (l *lexer) lexIdentifier() { r := l.next() if !isIdentifierFirst(r) { panic("Unexpected character in lexIdentifier") } for ; r != lexEOF; r = l.next() { if !isIdentifier(r) { break } } l.backup() switch l.input[l.tokenStart:l.pos.byteNo] { case "assert": l.emitToken(tokenAssert) case "else": l.emitToken(tokenElse) case "error": l.emitToken(tokenError) case "false": l.emitToken(tokenFalse) case "for": l.emitToken(tokenFor) case "function": l.emitToken(tokenFunction) case "if": l.emitToken(tokenIf) case "import": l.emitToken(tokenImport) case "importstr": l.emitToken(tokenImportStr) case "in": l.emitToken(tokenIn) case "local": l.emitToken(tokenLocal) case "null": l.emitToken(tokenNullLit) case "self": l.emitToken(tokenSelf) case "super": l.emitToken(tokenSuper) case "tailstrict": l.emitToken(tokenTailStrict) case "then": l.emitToken(tokenThen) case "true": l.emitToken(tokenTrue) default: // Not a keyword, assume it is an identifier l.emitToken(tokenIdentifier) } }
go
func (l *lexer) lexIdentifier() { r := l.next() if !isIdentifierFirst(r) { panic("Unexpected character in lexIdentifier") } for ; r != lexEOF; r = l.next() { if !isIdentifier(r) { break } } l.backup() switch l.input[l.tokenStart:l.pos.byteNo] { case "assert": l.emitToken(tokenAssert) case "else": l.emitToken(tokenElse) case "error": l.emitToken(tokenError) case "false": l.emitToken(tokenFalse) case "for": l.emitToken(tokenFor) case "function": l.emitToken(tokenFunction) case "if": l.emitToken(tokenIf) case "import": l.emitToken(tokenImport) case "importstr": l.emitToken(tokenImportStr) case "in": l.emitToken(tokenIn) case "local": l.emitToken(tokenLocal) case "null": l.emitToken(tokenNullLit) case "self": l.emitToken(tokenSelf) case "super": l.emitToken(tokenSuper) case "tailstrict": l.emitToken(tokenTailStrict) case "then": l.emitToken(tokenThen) case "true": l.emitToken(tokenTrue) default: // Not a keyword, assume it is an identifier l.emitToken(tokenIdentifier) } }
[ "func", "(", "l", "*", "lexer", ")", "lexIdentifier", "(", ")", "{", "r", ":=", "l", ".", "next", "(", ")", "\n", "if", "!", "isIdentifierFirst", "(", "r", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "for", ";", "r", "!=", "lexEOF", ";", "r", "=", "l", ".", "next", "(", ")", "{", "if", "!", "isIdentifier", "(", "r", ")", "{", "break", "\n", "}", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n\n", "switch", "l", ".", "input", "[", "l", ".", "tokenStart", ":", "l", ".", "pos", ".", "byteNo", "]", "{", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenAssert", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenElse", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenError", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenFalse", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenFor", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenFunction", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenIf", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenImport", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenImportStr", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenIn", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenLocal", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenNullLit", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenSelf", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenSuper", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenTailStrict", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenThen", ")", "\n", "case", "\"", "\"", ":", "l", ".", "emitToken", "(", "tokenTrue", ")", "\n", "default", ":", "// Not a keyword, assume it is an identifier", "l", ".", "emitToken", "(", "tokenIdentifier", ")", "\n", "}", "\n", "}" ]
// lexIdentifier will consume a identifer and emit a token. It is assumed // that the next rune to be served by the lexer will be a leading digit. This // may emit a keyword or an identifier.
[ "lexIdentifier", "will", "consume", "a", "identifer", "and", "emit", "a", "token", ".", "It", "is", "assumed", "that", "the", "next", "rune", "to", "be", "served", "by", "the", "lexer", "will", "be", "a", "leading", "digit", ".", "This", "may", "emit", "a", "keyword", "or", "an", "identifier", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/lexer.go#L568-L619
train
google/go-jsonnet
thunks.go
EvalCall
func (native *NativeFunction) EvalCall(arguments callArguments, i *interpreter, trace TraceElement) (value, error) { flatArgs := flattenArgs(arguments, native.Parameters()) nativeArgs := make([]interface{}, 0, len(flatArgs)) for _, arg := range flatArgs { v, err := i.evaluatePV(arg, trace) if err != nil { return nil, err } json, err := i.manifestJSON(trace, v) if err != nil { return nil, err } nativeArgs = append(nativeArgs, json) } resultJSON, err := native.Func(nativeArgs) if err != nil { return nil, i.Error(err.Error(), trace) } return jsonToValue(i, trace, resultJSON) }
go
func (native *NativeFunction) EvalCall(arguments callArguments, i *interpreter, trace TraceElement) (value, error) { flatArgs := flattenArgs(arguments, native.Parameters()) nativeArgs := make([]interface{}, 0, len(flatArgs)) for _, arg := range flatArgs { v, err := i.evaluatePV(arg, trace) if err != nil { return nil, err } json, err := i.manifestJSON(trace, v) if err != nil { return nil, err } nativeArgs = append(nativeArgs, json) } resultJSON, err := native.Func(nativeArgs) if err != nil { return nil, i.Error(err.Error(), trace) } return jsonToValue(i, trace, resultJSON) }
[ "func", "(", "native", "*", "NativeFunction", ")", "EvalCall", "(", "arguments", "callArguments", ",", "i", "*", "interpreter", ",", "trace", "TraceElement", ")", "(", "value", ",", "error", ")", "{", "flatArgs", ":=", "flattenArgs", "(", "arguments", ",", "native", ".", "Parameters", "(", ")", ")", "\n", "nativeArgs", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "0", ",", "len", "(", "flatArgs", ")", ")", "\n", "for", "_", ",", "arg", ":=", "range", "flatArgs", "{", "v", ",", "err", ":=", "i", ".", "evaluatePV", "(", "arg", ",", "trace", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "json", ",", "err", ":=", "i", ".", "manifestJSON", "(", "trace", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "nativeArgs", "=", "append", "(", "nativeArgs", ",", "json", ")", "\n", "}", "\n", "resultJSON", ",", "err", ":=", "native", ".", "Func", "(", "nativeArgs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "i", ".", "Error", "(", "err", ".", "Error", "(", ")", ",", "trace", ")", "\n", "}", "\n", "return", "jsonToValue", "(", "i", ",", "trace", ",", "resultJSON", ")", "\n", "}" ]
// EvalCall evaluates a call to a NativeFunction and returns the result.
[ "EvalCall", "evaluates", "a", "call", "to", "a", "NativeFunction", "and", "returns", "the", "result", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/thunks.go#L242-L261
train
google/go-jsonnet
ast/util.go
AddIdentifiers
func (i IdentifierSet) AddIdentifiers(idents Identifiers) { for _, ident := range idents { i.Add(ident) } }
go
func (i IdentifierSet) AddIdentifiers(idents Identifiers) { for _, ident := range idents { i.Add(ident) } }
[ "func", "(", "i", "IdentifierSet", ")", "AddIdentifiers", "(", "idents", "Identifiers", ")", "{", "for", "_", ",", "ident", ":=", "range", "idents", "{", "i", ".", "Add", "(", "ident", ")", "\n", "}", "\n", "}" ]
// AddIdentifiers adds a slice of identifiers to an identifier set.
[ "AddIdentifiers", "adds", "a", "slice", "of", "identifiers", "to", "an", "identifier", "set", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/util.go#L22-L26
train
google/go-jsonnet
ast/util.go
ToOrderedSlice
func (i IdentifierSet) ToOrderedSlice() []Identifier { var s []Identifier for v := range i { s = append(s, v) } sort.Sort(identifierSorter(s)) return s }
go
func (i IdentifierSet) ToOrderedSlice() []Identifier { var s []Identifier for v := range i { s = append(s, v) } sort.Sort(identifierSorter(s)) return s }
[ "func", "(", "i", "IdentifierSet", ")", "ToOrderedSlice", "(", ")", "[", "]", "Identifier", "{", "var", "s", "[", "]", "Identifier", "\n", "for", "v", ":=", "range", "i", "{", "s", "=", "append", "(", "s", ",", "v", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "identifierSorter", "(", "s", ")", ")", "\n", "return", "s", "\n", "}" ]
// ToOrderedSlice returns the elements of the current set as an ordered slice.
[ "ToOrderedSlice", "returns", "the", "elements", "of", "the", "current", "set", "as", "an", "ordered", "slice", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/util.go#L29-L36
train
google/go-jsonnet
ast/identifier_set.go
NewIdentifierSet
func NewIdentifierSet(a ...Identifier) IdentifierSet { s := make(IdentifierSet) for _, i := range a { s.Add(i) } return s }
go
func NewIdentifierSet(a ...Identifier) IdentifierSet { s := make(IdentifierSet) for _, i := range a { s.Add(i) } return s }
[ "func", "NewIdentifierSet", "(", "a", "...", "Identifier", ")", "IdentifierSet", "{", "s", ":=", "make", "(", "IdentifierSet", ")", "\n", "for", "_", ",", "i", ":=", "range", "a", "{", "s", ".", "Add", "(", "i", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// NewIdentifierSet creates and returns a reference to an empty set.
[ "NewIdentifierSet", "creates", "and", "returns", "a", "reference", "to", "an", "empty", "set", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/identifier_set.go#L15-L21
train
google/go-jsonnet
ast/identifier_set.go
Iter
func (set IdentifierSet) Iter() <-chan Identifier { ch := make(chan Identifier) go func() { for elem := range set { ch <- elem } close(ch) }() return ch }
go
func (set IdentifierSet) Iter() <-chan Identifier { ch := make(chan Identifier) go func() { for elem := range set { ch <- elem } close(ch) }() return ch }
[ "func", "(", "set", "IdentifierSet", ")", "Iter", "(", ")", "<-", "chan", "Identifier", "{", "ch", ":=", "make", "(", "chan", "Identifier", ")", "\n", "go", "func", "(", ")", "{", "for", "elem", ":=", "range", "set", "{", "ch", "<-", "elem", "\n", "}", "\n", "close", "(", "ch", ")", "\n", "}", "(", ")", "\n\n", "return", "ch", "\n", "}" ]
// Iter returns a channel of type identifier that you can range over.
[ "Iter", "returns", "a", "channel", "of", "type", "identifier", "that", "you", "can", "range", "over", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/identifier_set.go#L137-L147
train
google/go-jsonnet
parser/context.go
Children
func Children(node ast.Node) []ast.Node { var result []ast.Node result = append(result, directChildren(node)...) result = append(result, thunkChildren(node)...) result = append(result, specialChildren(node)...) return result }
go
func Children(node ast.Node) []ast.Node { var result []ast.Node result = append(result, directChildren(node)...) result = append(result, thunkChildren(node)...) result = append(result, specialChildren(node)...) return result }
[ "func", "Children", "(", "node", "ast", ".", "Node", ")", "[", "]", "ast", ".", "Node", "{", "var", "result", "[", "]", "ast", ".", "Node", "\n", "result", "=", "append", "(", "result", ",", "directChildren", "(", "node", ")", "...", ")", "\n", "result", "=", "append", "(", "result", ",", "thunkChildren", "(", "node", ")", "...", ")", "\n", "result", "=", "append", "(", "result", ",", "specialChildren", "(", "node", ")", "...", ")", "\n", "return", "result", "\n", "}" ]
// Children returns all children of a node. It supports ASTs before and after desugaring.
[ "Children", "returns", "all", "children", "of", "a", "node", ".", "It", "supports", "ASTs", "before", "and", "after", "desugaring", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/context.go#L339-L345
train
google/go-jsonnet
ast/fodder.go
MakeFodderElement
func MakeFodderElement(kind FodderKind, blanks int, indent int, comment []string) FodderElement { if kind == FodderLineEnd && len(comment) > 1 { panic(fmt.Sprintf("FodderLineEnd but comment == %v.", comment)) } if kind == FodderInterstitial && blanks > 0 { panic(fmt.Sprintf("FodderInterstitial but blanks == %d", blanks)) } if kind == FodderInterstitial && indent > 0 { panic(fmt.Sprintf("FodderInterstitial but indent == %d", blanks)) } if kind == FodderInterstitial && len(comment) != 1 { panic(fmt.Sprintf("FodderInterstitial but comment == %v.", comment)) } if kind == FodderParagraph && len(comment) == 0 { panic(fmt.Sprintf("FodderParagraph but comment was empty")) } return FodderElement{Kind: kind, Blanks: blanks, Indent: indent, Comment: comment} }
go
func MakeFodderElement(kind FodderKind, blanks int, indent int, comment []string) FodderElement { if kind == FodderLineEnd && len(comment) > 1 { panic(fmt.Sprintf("FodderLineEnd but comment == %v.", comment)) } if kind == FodderInterstitial && blanks > 0 { panic(fmt.Sprintf("FodderInterstitial but blanks == %d", blanks)) } if kind == FodderInterstitial && indent > 0 { panic(fmt.Sprintf("FodderInterstitial but indent == %d", blanks)) } if kind == FodderInterstitial && len(comment) != 1 { panic(fmt.Sprintf("FodderInterstitial but comment == %v.", comment)) } if kind == FodderParagraph && len(comment) == 0 { panic(fmt.Sprintf("FodderParagraph but comment was empty")) } return FodderElement{Kind: kind, Blanks: blanks, Indent: indent, Comment: comment} }
[ "func", "MakeFodderElement", "(", "kind", "FodderKind", ",", "blanks", "int", ",", "indent", "int", ",", "comment", "[", "]", "string", ")", "FodderElement", "{", "if", "kind", "==", "FodderLineEnd", "&&", "len", "(", "comment", ")", ">", "1", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "comment", ")", ")", "\n", "}", "\n", "if", "kind", "==", "FodderInterstitial", "&&", "blanks", ">", "0", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "blanks", ")", ")", "\n", "}", "\n", "if", "kind", "==", "FodderInterstitial", "&&", "indent", ">", "0", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "blanks", ")", ")", "\n", "}", "\n", "if", "kind", "==", "FodderInterstitial", "&&", "len", "(", "comment", ")", "!=", "1", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "comment", ")", ")", "\n", "}", "\n", "if", "kind", "==", "FodderParagraph", "&&", "len", "(", "comment", ")", "==", "0", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "return", "FodderElement", "{", "Kind", ":", "kind", ",", "Blanks", ":", "blanks", ",", "Indent", ":", "indent", ",", "Comment", ":", "comment", "}", "\n", "}" ]
// MakeFodderElement is a helper function that checks some preconditions.
[ "MakeFodderElement", "is", "a", "helper", "function", "that", "checks", "some", "preconditions", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L76-L93
train
google/go-jsonnet
ast/fodder.go
FodderHasCleanEndline
func FodderHasCleanEndline(fodder Fodder) bool { return len(fodder) > 0 && fodder[len(fodder)-1].Kind != FodderInterstitial }
go
func FodderHasCleanEndline(fodder Fodder) bool { return len(fodder) > 0 && fodder[len(fodder)-1].Kind != FodderInterstitial }
[ "func", "FodderHasCleanEndline", "(", "fodder", "Fodder", ")", "bool", "{", "return", "len", "(", "fodder", ")", ">", "0", "&&", "fodder", "[", "len", "(", "fodder", ")", "-", "1", "]", ".", "Kind", "!=", "FodderInterstitial", "\n", "}" ]
// FodderHasCleanEndline is true if the fodder doesn't end with an interstitial.
[ "FodderHasCleanEndline", "is", "true", "if", "the", "fodder", "doesn", "t", "end", "with", "an", "interstitial", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L100-L102
train
google/go-jsonnet
ast/fodder.go
FodderAppend
func FodderAppend(a *Fodder, elem FodderElement) { if FodderHasCleanEndline(*a) && elem.Kind == FodderLineEnd { if len(elem.Comment) > 0 { // The line end had a comment, so create a single line paragraph for it. *a = append(*a, MakeFodderElement(FodderParagraph, elem.Blanks, elem.Indent, elem.Comment)) } else { back := &(*a)[len(*a)-1] // Merge it into the previous line end. back.Indent = elem.Indent back.Blanks += elem.Blanks } } else { if !FodderHasCleanEndline(*a) && elem.Kind == FodderParagraph { *a = append(*a, MakeFodderElement(FodderLineEnd, 0, elem.Indent, []string{})) } *a = append(*a, elem) } }
go
func FodderAppend(a *Fodder, elem FodderElement) { if FodderHasCleanEndline(*a) && elem.Kind == FodderLineEnd { if len(elem.Comment) > 0 { // The line end had a comment, so create a single line paragraph for it. *a = append(*a, MakeFodderElement(FodderParagraph, elem.Blanks, elem.Indent, elem.Comment)) } else { back := &(*a)[len(*a)-1] // Merge it into the previous line end. back.Indent = elem.Indent back.Blanks += elem.Blanks } } else { if !FodderHasCleanEndline(*a) && elem.Kind == FodderParagraph { *a = append(*a, MakeFodderElement(FodderLineEnd, 0, elem.Indent, []string{})) } *a = append(*a, elem) } }
[ "func", "FodderAppend", "(", "a", "*", "Fodder", ",", "elem", "FodderElement", ")", "{", "if", "FodderHasCleanEndline", "(", "*", "a", ")", "&&", "elem", ".", "Kind", "==", "FodderLineEnd", "{", "if", "len", "(", "elem", ".", "Comment", ")", ">", "0", "{", "// The line end had a comment, so create a single line paragraph for it.", "*", "a", "=", "append", "(", "*", "a", ",", "MakeFodderElement", "(", "FodderParagraph", ",", "elem", ".", "Blanks", ",", "elem", ".", "Indent", ",", "elem", ".", "Comment", ")", ")", "\n", "}", "else", "{", "back", ":=", "&", "(", "*", "a", ")", "[", "len", "(", "*", "a", ")", "-", "1", "]", "\n", "// Merge it into the previous line end.", "back", ".", "Indent", "=", "elem", ".", "Indent", "\n", "back", ".", "Blanks", "+=", "elem", ".", "Blanks", "\n", "}", "\n", "}", "else", "{", "if", "!", "FodderHasCleanEndline", "(", "*", "a", ")", "&&", "elem", ".", "Kind", "==", "FodderParagraph", "{", "*", "a", "=", "append", "(", "*", "a", ",", "MakeFodderElement", "(", "FodderLineEnd", ",", "0", ",", "elem", ".", "Indent", ",", "[", "]", "string", "{", "}", ")", ")", "\n", "}", "\n", "*", "a", "=", "append", "(", "*", "a", ",", "elem", ")", "\n", "}", "\n", "}" ]
// FodderAppend appends to the fodder but preserves constraints. // // See FodderConcat below.
[ "FodderAppend", "appends", "to", "the", "fodder", "but", "preserves", "constraints", ".", "See", "FodderConcat", "below", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L107-L124
train
google/go-jsonnet
ast/fodder.go
FodderConcat
func FodderConcat(a Fodder, b Fodder) Fodder { if len(a) == 0 { return b } if len(b) == 0 { return a } r := a // Carefully add the first element of b. FodderAppend(&r, b[0]) // Add the rest of b. for i := 1; i < len(b); i++ { r = append(r, b[i]) } return r }
go
func FodderConcat(a Fodder, b Fodder) Fodder { if len(a) == 0 { return b } if len(b) == 0 { return a } r := a // Carefully add the first element of b. FodderAppend(&r, b[0]) // Add the rest of b. for i := 1; i < len(b); i++ { r = append(r, b[i]) } return r }
[ "func", "FodderConcat", "(", "a", "Fodder", ",", "b", "Fodder", ")", "Fodder", "{", "if", "len", "(", "a", ")", "==", "0", "{", "return", "b", "\n", "}", "\n", "if", "len", "(", "b", ")", "==", "0", "{", "return", "a", "\n", "}", "\n", "r", ":=", "a", "\n", "// Carefully add the first element of b.", "FodderAppend", "(", "&", "r", ",", "b", "[", "0", "]", ")", "\n", "// Add the rest of b.", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "b", ")", ";", "i", "++", "{", "r", "=", "append", "(", "r", ",", "b", "[", "i", "]", ")", "\n", "}", "\n", "return", "r", "\n", "}" ]
// FodderConcat concats the two fodders but also preserves constraints. // // Namely, a FodderLineEnd is not allowed to follow a FodderParagraph or a FodderLineEnd.
[ "FodderConcat", "concats", "the", "two", "fodders", "but", "also", "preserves", "constraints", ".", "Namely", "a", "FodderLineEnd", "is", "not", "allowed", "to", "follow", "a", "FodderParagraph", "or", "a", "FodderLineEnd", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L129-L144
train
google/go-jsonnet
ast/fodder.go
FodderMoveFront
func FodderMoveFront(a *Fodder, b *Fodder) { *a = FodderConcat(*b, *a) *b = Fodder{} }
go
func FodderMoveFront(a *Fodder, b *Fodder) { *a = FodderConcat(*b, *a) *b = Fodder{} }
[ "func", "FodderMoveFront", "(", "a", "*", "Fodder", ",", "b", "*", "Fodder", ")", "{", "*", "a", "=", "FodderConcat", "(", "*", "b", ",", "*", "a", ")", "\n", "*", "b", "=", "Fodder", "{", "}", "\n", "}" ]
// FodderMoveFront moves b to the front of a.
[ "FodderMoveFront", "moves", "b", "to", "the", "front", "of", "a", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L147-L150
train
google/go-jsonnet
ast/fodder.go
FodderEnsureCleanNewline
func FodderEnsureCleanNewline(fodder *Fodder) { if !FodderHasCleanEndline(*fodder) { FodderAppend(fodder, MakeFodderElement(FodderLineEnd, 0, 0, []string{})) } }
go
func FodderEnsureCleanNewline(fodder *Fodder) { if !FodderHasCleanEndline(*fodder) { FodderAppend(fodder, MakeFodderElement(FodderLineEnd, 0, 0, []string{})) } }
[ "func", "FodderEnsureCleanNewline", "(", "fodder", "*", "Fodder", ")", "{", "if", "!", "FodderHasCleanEndline", "(", "*", "fodder", ")", "{", "FodderAppend", "(", "fodder", ",", "MakeFodderElement", "(", "FodderLineEnd", ",", "0", ",", "0", ",", "[", "]", "string", "{", "}", ")", ")", "\n", "}", "\n", "}" ]
// FodderEnsureCleanNewline adds a LineEnd to the fodder if necessary.
[ "FodderEnsureCleanNewline", "adds", "a", "LineEnd", "to", "the", "fodder", "if", "necessary", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L153-L157
train
google/go-jsonnet
ast/fodder.go
FodderElementCountNewlines
func FodderElementCountNewlines(elem FodderElement) int { switch elem.Kind { case FodderInterstitial: return 0 case FodderLineEnd: return 1 case FodderParagraph: return len(elem.Comment) + elem.Blanks } panic(fmt.Sprintf("Unknown FodderElement kind %d", elem.Kind)) }
go
func FodderElementCountNewlines(elem FodderElement) int { switch elem.Kind { case FodderInterstitial: return 0 case FodderLineEnd: return 1 case FodderParagraph: return len(elem.Comment) + elem.Blanks } panic(fmt.Sprintf("Unknown FodderElement kind %d", elem.Kind)) }
[ "func", "FodderElementCountNewlines", "(", "elem", "FodderElement", ")", "int", "{", "switch", "elem", ".", "Kind", "{", "case", "FodderInterstitial", ":", "return", "0", "\n", "case", "FodderLineEnd", ":", "return", "1", "\n", "case", "FodderParagraph", ":", "return", "len", "(", "elem", ".", "Comment", ")", "+", "elem", ".", "Blanks", "\n", "}", "\n", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "elem", ".", "Kind", ")", ")", "\n", "}" ]
// FodderElementCountNewlines returns the number of new line chars represented by the fodder element
[ "FodderElementCountNewlines", "returns", "the", "number", "of", "new", "line", "chars", "represented", "by", "the", "fodder", "element" ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L160-L170
train
google/go-jsonnet
ast/fodder.go
FodderCountNewlines
func FodderCountNewlines(fodder Fodder) int { sum := 0 for _, elem := range fodder { sum += FodderElementCountNewlines(elem) } return sum }
go
func FodderCountNewlines(fodder Fodder) int { sum := 0 for _, elem := range fodder { sum += FodderElementCountNewlines(elem) } return sum }
[ "func", "FodderCountNewlines", "(", "fodder", "Fodder", ")", "int", "{", "sum", ":=", "0", "\n", "for", "_", ",", "elem", ":=", "range", "fodder", "{", "sum", "+=", "FodderElementCountNewlines", "(", "elem", ")", "\n", "}", "\n", "return", "sum", "\n", "}" ]
// FodderCountNewlines returns the number of new line chars represented by the fodder.
[ "FodderCountNewlines", "returns", "the", "number", "of", "new", "line", "chars", "represented", "by", "the", "fodder", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/fodder.go#L173-L179
train
google/go-jsonnet
parser/literalfield_set.go
NewLiteralFieldSet
func NewLiteralFieldSet(a ...LiteralField) LiteralFieldSet { s := make(LiteralFieldSet) for _, i := range a { s.Add(i) } return s }
go
func NewLiteralFieldSet(a ...LiteralField) LiteralFieldSet { s := make(LiteralFieldSet) for _, i := range a { s.Add(i) } return s }
[ "func", "NewLiteralFieldSet", "(", "a", "...", "LiteralField", ")", "LiteralFieldSet", "{", "s", ":=", "make", "(", "LiteralFieldSet", ")", "\n", "for", "_", ",", "i", ":=", "range", "a", "{", "s", ".", "Add", "(", "i", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// NewLiteralFieldSet creates and returns a reference to an empty set.
[ "NewLiteralFieldSet", "creates", "and", "returns", "a", "reference", "to", "an", "empty", "set", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/literalfield_set.go#L15-L21
train
google/go-jsonnet
parser/literalfield_set.go
Iter
func (set LiteralFieldSet) Iter() <-chan LiteralField { ch := make(chan LiteralField) go func() { for elem := range set { ch <- elem } close(ch) }() return ch }
go
func (set LiteralFieldSet) Iter() <-chan LiteralField { ch := make(chan LiteralField) go func() { for elem := range set { ch <- elem } close(ch) }() return ch }
[ "func", "(", "set", "LiteralFieldSet", ")", "Iter", "(", ")", "<-", "chan", "LiteralField", "{", "ch", ":=", "make", "(", "chan", "LiteralField", ")", "\n", "go", "func", "(", ")", "{", "for", "elem", ":=", "range", "set", "{", "ch", "<-", "elem", "\n", "}", "\n", "close", "(", "ch", ")", "\n", "}", "(", ")", "\n\n", "return", "ch", "\n", "}" ]
// Iter returns a channel of type LiteralField that you can range over.
[ "Iter", "returns", "a", "channel", "of", "type", "LiteralField", "that", "you", "can", "range", "over", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/literalfield_set.go#L137-L147
train
google/go-jsonnet
parser/parser.go
astVarToIdentifier
func astVarToIdentifier(node ast.Node) (*ast.Identifier, bool) { v, ok := node.(*ast.Var) if ok { return &v.Id, true } return nil, false }
go
func astVarToIdentifier(node ast.Node) (*ast.Identifier, bool) { v, ok := node.(*ast.Var) if ok { return &v.Id, true } return nil, false }
[ "func", "astVarToIdentifier", "(", "node", "ast", ".", "Node", ")", "(", "*", "ast", ".", "Identifier", ",", "bool", ")", "{", "v", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "Var", ")", "\n", "if", "ok", "{", "return", "&", "v", ".", "Id", ",", "true", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// in some cases it's convenient to parse something as an expression, and later // decide that it should be just an identifer
[ "in", "some", "cases", "it", "s", "convenient", "to", "parse", "something", "as", "an", "expression", "and", "later", "decide", "that", "it", "should", "be", "just", "an", "identifer" ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/parser/parser.go#L125-L131
train
google/go-jsonnet
interpreter.go
popIfExists
func (s *callStack) popIfExists(whichFrame int) { if len(s.stack) == whichFrame { if s.top().isCall { s.calls-- } s.stack = s.stack[:len(s.stack)-1] } }
go
func (s *callStack) popIfExists(whichFrame int) { if len(s.stack) == whichFrame { if s.top().isCall { s.calls-- } s.stack = s.stack[:len(s.stack)-1] } }
[ "func", "(", "s", "*", "callStack", ")", "popIfExists", "(", "whichFrame", "int", ")", "{", "if", "len", "(", "s", ".", "stack", ")", "==", "whichFrame", "{", "if", "s", ".", "top", "(", ")", ".", "isCall", "{", "s", ".", "calls", "--", "\n", "}", "\n", "s", ".", "stack", "=", "s", ".", "stack", "[", ":", "len", "(", "s", ".", "stack", ")", "-", "1", "]", "\n", "}", "\n", "}" ]
// It might've been popped already by tail call optimization. // We check if it was trimmed by comparing the current stack size to the position // of the frame we want to pop.
[ "It", "might", "ve", "been", "popped", "already", "by", "tail", "call", "optimization", ".", "We", "check", "if", "it", "was", "trimmed", "by", "comparing", "the", "current", "stack", "size", "to", "the", "position", "of", "the", "frame", "we", "want", "to", "pop", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L119-L126
train
google/go-jsonnet
interpreter.go
tailCallTrimStack
func (s *callStack) tailCallTrimStack() { for i := len(s.stack) - 1; i >= 0; i-- { if s.stack[i].isCall { if !s.stack[i].trimmable { return } // Remove this stack frame and everything above it s.stack = s.stack[:i] s.calls-- return } } }
go
func (s *callStack) tailCallTrimStack() { for i := len(s.stack) - 1; i >= 0; i-- { if s.stack[i].isCall { if !s.stack[i].trimmable { return } // Remove this stack frame and everything above it s.stack = s.stack[:i] s.calls-- return } } }
[ "func", "(", "s", "*", "callStack", ")", "tailCallTrimStack", "(", ")", "{", "for", "i", ":=", "len", "(", "s", ".", "stack", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "s", ".", "stack", "[", "i", "]", ".", "isCall", "{", "if", "!", "s", ".", "stack", "[", "i", "]", ".", "trimmable", "{", "return", "\n", "}", "\n", "// Remove this stack frame and everything above it", "s", ".", "stack", "=", "s", ".", "stack", "[", ":", "i", "]", "\n", "s", ".", "calls", "--", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
/** If there is a trimmable frame followed by some locals, pop them all. */
[ "If", "there", "is", "a", "trimmable", "frame", "followed", "by", "some", "locals", "pop", "them", "all", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L129-L141
train
google/go-jsonnet
interpreter.go
getSelfBinding
func (s *callStack) getSelfBinding() selfBinding { for i := len(s.stack) - 1; i >= 0; i-- { if s.stack[i].isCall { return s.stack[i].env.selfBinding } } panic(fmt.Sprintf("malformed stack %v", dumpCallStack(s))) }
go
func (s *callStack) getSelfBinding() selfBinding { for i := len(s.stack) - 1; i >= 0; i-- { if s.stack[i].isCall { return s.stack[i].env.selfBinding } } panic(fmt.Sprintf("malformed stack %v", dumpCallStack(s))) }
[ "func", "(", "s", "*", "callStack", ")", "getSelfBinding", "(", ")", "selfBinding", "{", "for", "i", ":=", "len", "(", "s", ".", "stack", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "s", ".", "stack", "[", "i", "]", ".", "isCall", "{", "return", "s", ".", "stack", "[", "i", "]", ".", "env", ".", "selfBinding", "\n", "}", "\n", "}", "\n", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dumpCallStack", "(", "s", ")", ")", ")", "\n", "}" ]
// getSelfBinding resolves the self construct
[ "getSelfBinding", "resolves", "the", "self", "construct" ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L167-L174
train
google/go-jsonnet
interpreter.go
lookUpVar
func (s *callStack) lookUpVar(id ast.Identifier) *cachedThunk { for i := len(s.stack) - 1; i >= 0; i-- { bind, present := s.stack[i].env.upValues[id] if present { return bind } if s.stack[i].isCall { // Nothing beyond the captured environment of the thunk / closure. break } } return nil }
go
func (s *callStack) lookUpVar(id ast.Identifier) *cachedThunk { for i := len(s.stack) - 1; i >= 0; i-- { bind, present := s.stack[i].env.upValues[id] if present { return bind } if s.stack[i].isCall { // Nothing beyond the captured environment of the thunk / closure. break } } return nil }
[ "func", "(", "s", "*", "callStack", ")", "lookUpVar", "(", "id", "ast", ".", "Identifier", ")", "*", "cachedThunk", "{", "for", "i", ":=", "len", "(", "s", ".", "stack", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "bind", ",", "present", ":=", "s", ".", "stack", "[", "i", "]", ".", "env", ".", "upValues", "[", "id", "]", "\n", "if", "present", "{", "return", "bind", "\n", "}", "\n", "if", "s", ".", "stack", "[", "i", "]", ".", "isCall", "{", "// Nothing beyond the captured environment of the thunk / closure.", "break", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// lookUpVar finds for the closest variable in scope that matches the given name.
[ "lookUpVar", "finds", "for", "the", "closest", "variable", "in", "scope", "that", "matches", "the", "given", "name", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L177-L189
train
google/go-jsonnet
interpreter.go
capture
func (s *callStack) capture(freeVars ast.Identifiers) bindingFrame { env := make(bindingFrame) for _, fv := range freeVars { env[fv] = s.lookUpVarOrPanic(fv) } return env }
go
func (s *callStack) capture(freeVars ast.Identifiers) bindingFrame { env := make(bindingFrame) for _, fv := range freeVars { env[fv] = s.lookUpVarOrPanic(fv) } return env }
[ "func", "(", "s", "*", "callStack", ")", "capture", "(", "freeVars", "ast", ".", "Identifiers", ")", "bindingFrame", "{", "env", ":=", "make", "(", "bindingFrame", ")", "\n", "for", "_", ",", "fv", ":=", "range", "freeVars", "{", "env", "[", "fv", "]", "=", "s", ".", "lookUpVarOrPanic", "(", "fv", ")", "\n", "}", "\n", "return", "env", "\n", "}" ]
// Build a binding frame containing specified variables.
[ "Build", "a", "binding", "frame", "containing", "specified", "variables", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L207-L213
train
google/go-jsonnet
interpreter.go
addBindings
func addBindings(a, b bindingFrame) bindingFrame { result := make(bindingFrame) for k, v := range a { result[k] = v } for k, v := range b { result[k] = v } return result }
go
func addBindings(a, b bindingFrame) bindingFrame { result := make(bindingFrame) for k, v := range a { result[k] = v } for k, v := range b { result[k] = v } return result }
[ "func", "addBindings", "(", "a", ",", "b", "bindingFrame", ")", "bindingFrame", "{", "result", ":=", "make", "(", "bindingFrame", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "a", "{", "result", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "for", "k", ",", "v", ":=", "range", "b", "{", "result", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "return", "result", "\n", "}" ]
// Map union, b takes precedence when keys collide.
[ "Map", "union", "b", "takes", "precedence", "when", "keys", "collide", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L243-L255
train
google/go-jsonnet
interpreter.go
unparseString
func unparseString(v string) string { var buf bytes.Buffer buf.WriteString("\"") for _, c := range v { switch c { case '"': buf.WriteString("\\\"") case '\\': buf.WriteString("\\\\") case '\b': buf.WriteString("\\b") case '\f': buf.WriteString("\\f") case '\n': buf.WriteString("\\n") case '\r': buf.WriteString("\\r") case '\t': buf.WriteString("\\t") case 0: buf.WriteString("\\u0000") default: if c < 0x20 || (c >= 0x7f && c <= 0x9f) { buf.WriteString(fmt.Sprintf("\\u%04x", int(c))) } else { buf.WriteRune(c) } } } buf.WriteString("\"") return buf.String() }
go
func unparseString(v string) string { var buf bytes.Buffer buf.WriteString("\"") for _, c := range v { switch c { case '"': buf.WriteString("\\\"") case '\\': buf.WriteString("\\\\") case '\b': buf.WriteString("\\b") case '\f': buf.WriteString("\\f") case '\n': buf.WriteString("\\n") case '\r': buf.WriteString("\\r") case '\t': buf.WriteString("\\t") case 0: buf.WriteString("\\u0000") default: if c < 0x20 || (c >= 0x7f && c <= 0x9f) { buf.WriteString(fmt.Sprintf("\\u%04x", int(c))) } else { buf.WriteRune(c) } } } buf.WriteString("\"") return buf.String() }
[ "func", "unparseString", "(", "v", "string", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "buf", ".", "WriteString", "(", "\"", "\\\"", "\"", ")", "\n", "for", "_", ",", "c", ":=", "range", "v", "{", "switch", "c", "{", "case", "'\"'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\\\"", "\"", ")", "\n", "case", "'\\\\'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "case", "'\\b'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "case", "'\\f'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "case", "'\\n'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "case", "'\\r'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "case", "'\\t'", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "case", "0", ":", "buf", ".", "WriteString", "(", "\"", "\\\\", "\"", ")", "\n", "default", ":", "if", "c", "<", "0x20", "||", "(", "c", ">=", "0x7f", "&&", "c", "<=", "0x9f", ")", "{", "buf", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\\\", "\"", ",", "int", "(", "c", ")", ")", ")", "\n", "}", "else", "{", "buf", ".", "WriteRune", "(", "c", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "buf", ".", "WriteString", "(", "\"", "\\\"", "\"", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// unparseString Wraps in "" and escapes stuff to make the string JSON-compliant and human-readable.
[ "unparseString", "Wraps", "in", "and", "escapes", "stuff", "to", "make", "the", "string", "JSON", "-", "compliant", "and", "human", "-", "readable", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L569-L600
train
google/go-jsonnet
interpreter.go
manifestString
func (i *interpreter) manifestString(buf *bytes.Buffer, trace TraceElement, v value) error { switch v := v.(type) { case *valueString: buf.WriteString(v.getString()) return nil default: return makeRuntimeError(fmt.Sprintf("expected string result, got: %s", v.getType().name), i.getCurrentStackTrace(trace)) } }
go
func (i *interpreter) manifestString(buf *bytes.Buffer, trace TraceElement, v value) error { switch v := v.(type) { case *valueString: buf.WriteString(v.getString()) return nil default: return makeRuntimeError(fmt.Sprintf("expected string result, got: %s", v.getType().name), i.getCurrentStackTrace(trace)) } }
[ "func", "(", "i", "*", "interpreter", ")", "manifestString", "(", "buf", "*", "bytes", ".", "Buffer", ",", "trace", "TraceElement", ",", "v", "value", ")", "error", "{", "switch", "v", ":=", "v", ".", "(", "type", ")", "{", "case", "*", "valueString", ":", "buf", ".", "WriteString", "(", "v", ".", "getString", "(", ")", ")", "\n", "return", "nil", "\n", "default", ":", "return", "makeRuntimeError", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ".", "getType", "(", ")", ".", "name", ")", ",", "i", ".", "getCurrentStackTrace", "(", "trace", ")", ")", "\n", "}", "\n", "}" ]
// manifestString expects the value to be a string and returns it.
[ "manifestString", "expects", "the", "value", "to", "be", "a", "string", "and", "returns", "it", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/interpreter.go#L790-L798
train
google/go-jsonnet
ast/location.go
LocationRangeBetween
func LocationRangeBetween(a, b *LocationRange) LocationRange { if a.file != b.file { panic("Cannot create a LocationRange between different files") } return MakeLocationRange(a.FileName, a.file, a.Begin, b.End) }
go
func LocationRangeBetween(a, b *LocationRange) LocationRange { if a.file != b.file { panic("Cannot create a LocationRange between different files") } return MakeLocationRange(a.FileName, a.file, a.Begin, b.End) }
[ "func", "LocationRangeBetween", "(", "a", ",", "b", "*", "LocationRange", ")", "LocationRange", "{", "if", "a", ".", "file", "!=", "b", ".", "file", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "MakeLocationRange", "(", "a", ".", "FileName", ",", "a", ".", "file", ",", "a", ".", "Begin", ",", "b", ".", "End", ")", "\n", "}" ]
// LocationRangeBetween returns a LocationRange containing both a and b.
[ "LocationRangeBetween", "returns", "a", "LocationRange", "containing", "both", "a", "and", "b", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L67-L72
train
google/go-jsonnet
ast/location.go
MakeLocationRange
func MakeLocationRange(fn string, fc *Source, begin Location, end Location) LocationRange { return LocationRange{FileName: fn, file: fc, Begin: begin, End: end} }
go
func MakeLocationRange(fn string, fc *Source, begin Location, end Location) LocationRange { return LocationRange{FileName: fn, file: fc, Begin: begin, End: end} }
[ "func", "MakeLocationRange", "(", "fn", "string", ",", "fc", "*", "Source", ",", "begin", "Location", ",", "end", "Location", ")", "LocationRange", "{", "return", "LocationRange", "{", "FileName", ":", "fn", ",", "file", ":", "fc", ",", "Begin", ":", "begin", ",", "End", ":", "end", "}", "\n", "}" ]
// MakeLocationRange creates a LocationRange.
[ "MakeLocationRange", "creates", "a", "LocationRange", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L112-L114
train
google/go-jsonnet
ast/location.go
GetSnippet
func (sp *SourceProvider) GetSnippet(loc LocationRange) string { var result bytes.Buffer if loc.Begin.Line == 0 { return "" } for i := loc.Begin.Line; i <= loc.End.Line; i++ { inLineRange := trimToLine(loc, i) for j := inLineRange.Begin.Column; j < inLineRange.End.Column; j++ { result.WriteByte(loc.file.lines[i-1][j-1]) } if i != loc.End.Line { result.WriteByte('\n') } } return result.String() }
go
func (sp *SourceProvider) GetSnippet(loc LocationRange) string { var result bytes.Buffer if loc.Begin.Line == 0 { return "" } for i := loc.Begin.Line; i <= loc.End.Line; i++ { inLineRange := trimToLine(loc, i) for j := inLineRange.Begin.Column; j < inLineRange.End.Column; j++ { result.WriteByte(loc.file.lines[i-1][j-1]) } if i != loc.End.Line { result.WriteByte('\n') } } return result.String() }
[ "func", "(", "sp", "*", "SourceProvider", ")", "GetSnippet", "(", "loc", "LocationRange", ")", "string", "{", "var", "result", "bytes", ".", "Buffer", "\n", "if", "loc", ".", "Begin", ".", "Line", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "for", "i", ":=", "loc", ".", "Begin", ".", "Line", ";", "i", "<=", "loc", ".", "End", ".", "Line", ";", "i", "++", "{", "inLineRange", ":=", "trimToLine", "(", "loc", ",", "i", ")", "\n", "for", "j", ":=", "inLineRange", ".", "Begin", ".", "Column", ";", "j", "<", "inLineRange", ".", "End", ".", "Column", ";", "j", "++", "{", "result", ".", "WriteByte", "(", "loc", ".", "file", ".", "lines", "[", "i", "-", "1", "]", "[", "j", "-", "1", "]", ")", "\n", "}", "\n", "if", "i", "!=", "loc", ".", "End", ".", "Line", "{", "result", ".", "WriteByte", "(", "'\\n'", ")", "\n", "}", "\n", "}", "\n", "return", "result", ".", "String", "(", ")", "\n", "}" ]
// GetSnippet returns a code snippet corresponding to loc.
[ "GetSnippet", "returns", "a", "code", "snippet", "corresponding", "to", "loc", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L122-L137
train
google/go-jsonnet
ast/ast.go
NewNodeBase
func NewNodeBase(loc LocationRange, freeVariables Identifiers) NodeBase { return NodeBase{ loc: loc, freeVariables: freeVariables, } }
go
func NewNodeBase(loc LocationRange, freeVariables Identifiers) NodeBase { return NodeBase{ loc: loc, freeVariables: freeVariables, } }
[ "func", "NewNodeBase", "(", "loc", "LocationRange", ",", "freeVariables", "Identifiers", ")", "NodeBase", "{", "return", "NodeBase", "{", "loc", ":", "loc", ",", "freeVariables", ":", "freeVariables", ",", "}", "\n", "}" ]
// NewNodeBase creates a new NodeBase from initial LocationRange and // Identifiers.
[ "NewNodeBase", "creates", "a", "new", "NodeBase", "from", "initial", "LocationRange", "and", "Identifiers", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L62-L67
train
google/go-jsonnet
ast/ast.go
FullyEscaped
func (k LiteralStringKind) FullyEscaped() bool { switch k { case StringSingle, StringDouble: return true case StringBlock, VerbatimStringDouble, VerbatimStringSingle: return false } panic(fmt.Sprintf("Unknown string kind: %v", k)) }
go
func (k LiteralStringKind) FullyEscaped() bool { switch k { case StringSingle, StringDouble: return true case StringBlock, VerbatimStringDouble, VerbatimStringSingle: return false } panic(fmt.Sprintf("Unknown string kind: %v", k)) }
[ "func", "(", "k", "LiteralStringKind", ")", "FullyEscaped", "(", ")", "bool", "{", "switch", "k", "{", "case", "StringSingle", ",", "StringDouble", ":", "return", "true", "\n", "case", "StringBlock", ",", "VerbatimStringDouble", ",", "VerbatimStringSingle", ":", "return", "false", "\n", "}", "\n", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ")", ")", "\n", "}" ]
// FullyEscaped returns true iff the literal string kind may contain escape // sequences that require unescaping.
[ "FullyEscaped", "returns", "true", "iff", "the", "literal", "string", "kind", "may", "contain", "escape", "sequences", "that", "require", "unescaping", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L453-L461
train
google/go-jsonnet
ast/ast.go
ObjectFieldLocalNoMethod
func ObjectFieldLocalNoMethod(id *Identifier, body Node) ObjectField { return ObjectField{ObjectLocal, ObjectFieldVisible, false, false, nil, nil, id, nil, false, body, nil} }
go
func ObjectFieldLocalNoMethod(id *Identifier, body Node) ObjectField { return ObjectField{ObjectLocal, ObjectFieldVisible, false, false, nil, nil, id, nil, false, body, nil} }
[ "func", "ObjectFieldLocalNoMethod", "(", "id", "*", "Identifier", ",", "body", "Node", ")", "ObjectField", "{", "return", "ObjectField", "{", "ObjectLocal", ",", "ObjectFieldVisible", ",", "false", ",", "false", ",", "nil", ",", "nil", ",", "id", ",", "nil", ",", "false", ",", "body", ",", "nil", "}", "\n", "}" ]
// ObjectFieldLocalNoMethod creates a non-method local object field.
[ "ObjectFieldLocalNoMethod", "creates", "a", "non", "-", "method", "local", "object", "field", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L514-L516
train
google/go-jsonnet
ast/clone.go
cloneForSpec
func cloneForSpec(specPtr *ForSpec) { clone(&specPtr.Expr) oldOuter := specPtr.Outer if oldOuter != nil { specPtr.Outer = new(ForSpec) *specPtr.Outer = *oldOuter cloneForSpec(specPtr.Outer) } for i := range specPtr.Conditions { clone(&specPtr.Conditions[i].Expr) } }
go
func cloneForSpec(specPtr *ForSpec) { clone(&specPtr.Expr) oldOuter := specPtr.Outer if oldOuter != nil { specPtr.Outer = new(ForSpec) *specPtr.Outer = *oldOuter cloneForSpec(specPtr.Outer) } for i := range specPtr.Conditions { clone(&specPtr.Conditions[i].Expr) } }
[ "func", "cloneForSpec", "(", "specPtr", "*", "ForSpec", ")", "{", "clone", "(", "&", "specPtr", ".", "Expr", ")", "\n", "oldOuter", ":=", "specPtr", ".", "Outer", "\n", "if", "oldOuter", "!=", "nil", "{", "specPtr", ".", "Outer", "=", "new", "(", "ForSpec", ")", "\n", "*", "specPtr", ".", "Outer", "=", "*", "oldOuter", "\n", "cloneForSpec", "(", "specPtr", ".", "Outer", ")", "\n", "}", "\n", "for", "i", ":=", "range", "specPtr", ".", "Conditions", "{", "clone", "(", "&", "specPtr", ".", "Conditions", "[", "i", "]", ".", "Expr", ")", "\n", "}", "\n", "}" ]
// Updates fields of specPtr to point to deep clones.
[ "Updates", "fields", "of", "specPtr", "to", "point", "to", "deep", "clones", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L25-L36
train
google/go-jsonnet
ast/clone.go
cloneParameters
func cloneParameters(params *Parameters) { if params == nil { return } params.Optional = append(make([]NamedParameter, 0), params.Optional...) for i := range params.Optional { clone(&params.Optional[i].DefaultArg) } }
go
func cloneParameters(params *Parameters) { if params == nil { return } params.Optional = append(make([]NamedParameter, 0), params.Optional...) for i := range params.Optional { clone(&params.Optional[i].DefaultArg) } }
[ "func", "cloneParameters", "(", "params", "*", "Parameters", ")", "{", "if", "params", "==", "nil", "{", "return", "\n", "}", "\n", "params", ".", "Optional", "=", "append", "(", "make", "(", "[", "]", "NamedParameter", ",", "0", ")", ",", "params", ".", "Optional", "...", ")", "\n", "for", "i", ":=", "range", "params", ".", "Optional", "{", "clone", "(", "&", "params", ".", "Optional", "[", "i", "]", ".", "DefaultArg", ")", "\n", "}", "\n", "}" ]
// Updates fields of params to point to deep clones.
[ "Updates", "fields", "of", "params", "to", "point", "to", "deep", "clones", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L39-L47
train
google/go-jsonnet
ast/clone.go
cloneField
func cloneField(field *ObjectField) { if field.Method != nil { field.Method = Clone(field.Method).(*Function) } oldParams := field.Params if oldParams != nil { field.Params = new(Parameters) *field.Params = *oldParams } cloneParameters(field.Params) clone(&field.Expr1) clone(&field.Expr2) clone(&field.Expr3) }
go
func cloneField(field *ObjectField) { if field.Method != nil { field.Method = Clone(field.Method).(*Function) } oldParams := field.Params if oldParams != nil { field.Params = new(Parameters) *field.Params = *oldParams } cloneParameters(field.Params) clone(&field.Expr1) clone(&field.Expr2) clone(&field.Expr3) }
[ "func", "cloneField", "(", "field", "*", "ObjectField", ")", "{", "if", "field", ".", "Method", "!=", "nil", "{", "field", ".", "Method", "=", "Clone", "(", "field", ".", "Method", ")", ".", "(", "*", "Function", ")", "\n", "}", "\n\n", "oldParams", ":=", "field", ".", "Params", "\n", "if", "oldParams", "!=", "nil", "{", "field", ".", "Params", "=", "new", "(", "Parameters", ")", "\n", "*", "field", ".", "Params", "=", "*", "oldParams", "\n", "}", "\n", "cloneParameters", "(", "field", ".", "Params", ")", "\n\n", "clone", "(", "&", "field", ".", "Expr1", ")", "\n", "clone", "(", "&", "field", ".", "Expr2", ")", "\n", "clone", "(", "&", "field", ".", "Expr3", ")", "\n", "}" ]
// Updates fields of field to point to deep clones.
[ "Updates", "fields", "of", "field", "to", "point", "to", "deep", "clones", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L50-L65
train
google/go-jsonnet
ast/clone.go
cloneNodeBase
func cloneNodeBase(astPtr Node) { if astPtr.Context() != nil { newContext := new(string) *newContext = *astPtr.Context() astPtr.SetContext(newContext) } astPtr.SetFreeVariables(append(make(Identifiers, 0), astPtr.FreeVariables()...)) }
go
func cloneNodeBase(astPtr Node) { if astPtr.Context() != nil { newContext := new(string) *newContext = *astPtr.Context() astPtr.SetContext(newContext) } astPtr.SetFreeVariables(append(make(Identifiers, 0), astPtr.FreeVariables()...)) }
[ "func", "cloneNodeBase", "(", "astPtr", "Node", ")", "{", "if", "astPtr", ".", "Context", "(", ")", "!=", "nil", "{", "newContext", ":=", "new", "(", "string", ")", "\n", "*", "newContext", "=", "*", "astPtr", ".", "Context", "(", ")", "\n", "astPtr", ".", "SetContext", "(", "newContext", ")", "\n", "}", "\n", "astPtr", ".", "SetFreeVariables", "(", "append", "(", "make", "(", "Identifiers", ",", "0", ")", ",", "astPtr", ".", "FreeVariables", "(", ")", "...", ")", ")", "\n", "}" ]
// Updates the NodeBase fields of astPtr to point to deep clones.
[ "Updates", "the", "NodeBase", "fields", "of", "astPtr", "to", "point", "to", "deep", "clones", "." ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L74-L81
train
google/go-jsonnet
dump/pointermap.go
getAllAndReusedPointers
func (pm *pointerMap) getAllAndReusedPointers(v reflect.Value) { if v.Kind() == reflect.Invalid { return } if isPointerValue(v) && v.Pointer() != 0 { // pointer is 0 for unexported fields reused := pm.addPointer(v.Pointer()) if reused { // No use descending inside this value, since it have been seen before and all its descendants // have been considered return } } // Now descend into any children of this value switch v.Kind() { case reflect.Slice, reflect.Array: numEntries := v.Len() for i := 0; i < numEntries; i++ { pm.getAllAndReusedPointers(v.Index(i)) } case reflect.Interface: pm.getAllAndReusedPointers(v.Elem()) case reflect.Ptr: pm.getAllAndReusedPointers(v.Elem()) case reflect.Map: for _, key := range v.MapKeys() { pm.getAllAndReusedPointers(v.MapIndex(key)) } case reflect.Struct: numFields := v.NumField() for i := 0; i < numFields; i++ { pm.getAllAndReusedPointers(v.Field(i)) } } }
go
func (pm *pointerMap) getAllAndReusedPointers(v reflect.Value) { if v.Kind() == reflect.Invalid { return } if isPointerValue(v) && v.Pointer() != 0 { // pointer is 0 for unexported fields reused := pm.addPointer(v.Pointer()) if reused { // No use descending inside this value, since it have been seen before and all its descendants // have been considered return } } // Now descend into any children of this value switch v.Kind() { case reflect.Slice, reflect.Array: numEntries := v.Len() for i := 0; i < numEntries; i++ { pm.getAllAndReusedPointers(v.Index(i)) } case reflect.Interface: pm.getAllAndReusedPointers(v.Elem()) case reflect.Ptr: pm.getAllAndReusedPointers(v.Elem()) case reflect.Map: for _, key := range v.MapKeys() { pm.getAllAndReusedPointers(v.MapIndex(key)) } case reflect.Struct: numFields := v.NumField() for i := 0; i < numFields; i++ { pm.getAllAndReusedPointers(v.Field(i)) } } }
[ "func", "(", "pm", "*", "pointerMap", ")", "getAllAndReusedPointers", "(", "v", "reflect", ".", "Value", ")", "{", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Invalid", "{", "return", "\n", "}", "\n", "if", "isPointerValue", "(", "v", ")", "&&", "v", ".", "Pointer", "(", ")", "!=", "0", "{", "// pointer is 0 for unexported fields", "reused", ":=", "pm", ".", "addPointer", "(", "v", ".", "Pointer", "(", ")", ")", "\n", "if", "reused", "{", "// No use descending inside this value, since it have been seen before and all its descendants", "// have been considered", "return", "\n", "}", "\n", "}", "\n\n", "// Now descend into any children of this value", "switch", "v", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Slice", ",", "reflect", ".", "Array", ":", "numEntries", ":=", "v", ".", "Len", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "numEntries", ";", "i", "++", "{", "pm", ".", "getAllAndReusedPointers", "(", "v", ".", "Index", "(", "i", ")", ")", "\n", "}", "\n\n", "case", "reflect", ".", "Interface", ":", "pm", ".", "getAllAndReusedPointers", "(", "v", ".", "Elem", "(", ")", ")", "\n\n", "case", "reflect", ".", "Ptr", ":", "pm", ".", "getAllAndReusedPointers", "(", "v", ".", "Elem", "(", ")", ")", "\n\n", "case", "reflect", ".", "Map", ":", "for", "_", ",", "key", ":=", "range", "v", ".", "MapKeys", "(", ")", "{", "pm", ".", "getAllAndReusedPointers", "(", "v", ".", "MapIndex", "(", "key", ")", ")", "\n", "}", "\n\n", "case", "reflect", ".", "Struct", ":", "numFields", ":=", "v", ".", "NumField", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "numFields", ";", "i", "++", "{", "pm", ".", "getAllAndReusedPointers", "(", "v", ".", "Field", "(", "i", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Recursively consider v and each of its children, updating pointer information
[ "Recursively", "consider", "v", "and", "each", "of", "its", "children", "updating", "pointer", "information" ]
181c86d8157c7de54d052305b318be18b34d27d0
https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/dump/pointermap.go#L81-L119
train
gobuffalo/pop
associations/associations_for_struct.go
ForStruct
func ForStruct(s interface{}, fields ...string) (Associations, error) { associations := Associations{} innerAssociations := InnerAssociations{} t, v := getModelDefinition(s) fields = trimFields(fields) // validate if fields contains a non existing field in struct. // and vefiry is it has inner associations. for i := range fields { var innerField, field string if !validAssociationExpRegexp.MatchString(fields[i]) { return associations, fmt.Errorf("association '%s' does not match the format %s", fields[i], "'<field>' or '<field>.<nested-field>'") } if strings.Contains(fields[i], ".") { field = fields[i][:strings.Index(fields[i], ".")] innerField = fields[i][strings.Index(fields[i], ".")+1:] fields[i] = field } if _, ok := t.FieldByName(fields[i]); !ok { return associations, fmt.Errorf("field %s does not exist in model %s", fields[i], t.Name()) } if innerField != "" { innerAssociations = append(innerAssociations, InnerAssociation{fields[i], innerField}) } } for i := 0; i < t.NumField(); i++ { f := t.Field(i) // ignores those fields not included in fields list. if len(fields) > 0 && fieldIgnoredIn(fields, f.Name) { continue } tags := columns.TagsFor(f) for name, builder := range associationBuilders { tag := tags.Find(name) if !tag.Empty() { params := associationParams{ field: f, model: s, modelType: t, modelValue: v, popTags: tags, innerAssociations: innerAssociations, } a, err := builder(params) if err != nil { return associations, err } associations = append(associations, a) break } } } return associations, nil }
go
func ForStruct(s interface{}, fields ...string) (Associations, error) { associations := Associations{} innerAssociations := InnerAssociations{} t, v := getModelDefinition(s) fields = trimFields(fields) // validate if fields contains a non existing field in struct. // and vefiry is it has inner associations. for i := range fields { var innerField, field string if !validAssociationExpRegexp.MatchString(fields[i]) { return associations, fmt.Errorf("association '%s' does not match the format %s", fields[i], "'<field>' or '<field>.<nested-field>'") } if strings.Contains(fields[i], ".") { field = fields[i][:strings.Index(fields[i], ".")] innerField = fields[i][strings.Index(fields[i], ".")+1:] fields[i] = field } if _, ok := t.FieldByName(fields[i]); !ok { return associations, fmt.Errorf("field %s does not exist in model %s", fields[i], t.Name()) } if innerField != "" { innerAssociations = append(innerAssociations, InnerAssociation{fields[i], innerField}) } } for i := 0; i < t.NumField(); i++ { f := t.Field(i) // ignores those fields not included in fields list. if len(fields) > 0 && fieldIgnoredIn(fields, f.Name) { continue } tags := columns.TagsFor(f) for name, builder := range associationBuilders { tag := tags.Find(name) if !tag.Empty() { params := associationParams{ field: f, model: s, modelType: t, modelValue: v, popTags: tags, innerAssociations: innerAssociations, } a, err := builder(params) if err != nil { return associations, err } associations = append(associations, a) break } } } return associations, nil }
[ "func", "ForStruct", "(", "s", "interface", "{", "}", ",", "fields", "...", "string", ")", "(", "Associations", ",", "error", ")", "{", "associations", ":=", "Associations", "{", "}", "\n", "innerAssociations", ":=", "InnerAssociations", "{", "}", "\n\n", "t", ",", "v", ":=", "getModelDefinition", "(", "s", ")", "\n", "fields", "=", "trimFields", "(", "fields", ")", "\n\n", "// validate if fields contains a non existing field in struct.", "// and vefiry is it has inner associations.", "for", "i", ":=", "range", "fields", "{", "var", "innerField", ",", "field", "string", "\n\n", "if", "!", "validAssociationExpRegexp", ".", "MatchString", "(", "fields", "[", "i", "]", ")", "{", "return", "associations", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "fields", "[", "i", "]", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "fields", "[", "i", "]", ",", "\"", "\"", ")", "{", "field", "=", "fields", "[", "i", "]", "[", ":", "strings", ".", "Index", "(", "fields", "[", "i", "]", ",", "\"", "\"", ")", "]", "\n", "innerField", "=", "fields", "[", "i", "]", "[", "strings", ".", "Index", "(", "fields", "[", "i", "]", ",", "\"", "\"", ")", "+", "1", ":", "]", "\n", "fields", "[", "i", "]", "=", "field", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "t", ".", "FieldByName", "(", "fields", "[", "i", "]", ")", ";", "!", "ok", "{", "return", "associations", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "fields", "[", "i", "]", ",", "t", ".", "Name", "(", ")", ")", "\n", "}", "\n\n", "if", "innerField", "!=", "\"", "\"", "{", "innerAssociations", "=", "append", "(", "innerAssociations", ",", "InnerAssociation", "{", "fields", "[", "i", "]", ",", "innerField", "}", ")", "\n", "}", "\n", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "t", ".", "NumField", "(", ")", ";", "i", "++", "{", "f", ":=", "t", ".", "Field", "(", "i", ")", "\n\n", "// ignores those fields not included in fields list.", "if", "len", "(", "fields", ")", ">", "0", "&&", "fieldIgnoredIn", "(", "fields", ",", "f", ".", "Name", ")", "{", "continue", "\n", "}", "\n\n", "tags", ":=", "columns", ".", "TagsFor", "(", "f", ")", "\n\n", "for", "name", ",", "builder", ":=", "range", "associationBuilders", "{", "tag", ":=", "tags", ".", "Find", "(", "name", ")", "\n", "if", "!", "tag", ".", "Empty", "(", ")", "{", "params", ":=", "associationParams", "{", "field", ":", "f", ",", "model", ":", "s", ",", "modelType", ":", "t", ",", "modelValue", ":", "v", ",", "popTags", ":", "tags", ",", "innerAssociations", ":", "innerAssociations", ",", "}", "\n\n", "a", ",", "err", ":=", "builder", "(", "params", ")", "\n", "if", "err", "!=", "nil", "{", "return", "associations", ",", "err", "\n", "}", "\n\n", "associations", "=", "append", "(", "associations", ",", "a", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "associations", ",", "nil", "\n", "}" ]
// ForStruct returns all associations for // the struct specified. It takes into account tags // associations like has_many, belongs_to, has_one. // it throws an error when it finds a field that does // not exist for a model.
[ "ForStruct", "returns", "all", "associations", "for", "the", "struct", "specified", ".", "It", "takes", "into", "account", "tags", "associations", "like", "has_many", "belongs_to", "has_one", ".", "it", "throws", "an", "error", "when", "it", "finds", "a", "field", "that", "does", "not", "exist", "for", "a", "model", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/associations_for_struct.go#L42-L106
train
gobuffalo/pop
slices/uuid.go
Scan
func (s *UUID) Scan(src interface{}) error { b, ok := src.([]byte) if !ok { return errors.New("Scan source was not []byte") } us, err := strSliceToUUIDSlice(strToUUID(string(b))) if err != nil { return errors.WithStack(err) } *s = us return nil }
go
func (s *UUID) Scan(src interface{}) error { b, ok := src.([]byte) if !ok { return errors.New("Scan source was not []byte") } us, err := strSliceToUUIDSlice(strToUUID(string(b))) if err != nil { return errors.WithStack(err) } *s = us return nil }
[ "func", "(", "s", "*", "UUID", ")", "Scan", "(", "src", "interface", "{", "}", ")", "error", "{", "b", ",", "ok", ":=", "src", ".", "(", "[", "]", "byte", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "us", ",", "err", ":=", "strSliceToUUIDSlice", "(", "strToUUID", "(", "string", "(", "b", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "*", "s", "=", "us", "\n", "return", "nil", "\n", "}" ]
// Scan implements the sql.Scanner interface. // It allows to read the UUID slice from the database value.
[ "Scan", "implements", "the", "sql", ".", "Scanner", "interface", ".", "It", "allows", "to", "read", "the", "UUID", "slice", "from", "the", "database", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L25-L36
train
gobuffalo/pop
slices/uuid.go
Value
func (s UUID) Value() (driver.Value, error) { ss := make([]string, len(s)) for i, u := range s { ss[i] = u.String() } return fmt.Sprintf("{%s}", strings.Join(ss, ",")), nil }
go
func (s UUID) Value() (driver.Value, error) { ss := make([]string, len(s)) for i, u := range s { ss[i] = u.String() } return fmt.Sprintf("{%s}", strings.Join(ss, ",")), nil }
[ "func", "(", "s", "UUID", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "ss", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "s", ")", ")", "\n", "for", "i", ",", "u", ":=", "range", "s", "{", "ss", "[", "i", "]", "=", "u", ".", "String", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "ss", ",", "\"", "\"", ")", ")", ",", "nil", "\n", "}" ]
// Value implements the driver.Valuer interface. // It allows to convert the UUID slice to a driver.value.
[ "Value", "implements", "the", "driver", ".", "Valuer", "interface", ".", "It", "allows", "to", "convert", "the", "UUID", "slice", "to", "a", "driver", ".", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L40-L46
train
gobuffalo/pop
slices/uuid.go
UnmarshalJSON
func (s *UUID) UnmarshalJSON(data []byte) error { var ss []string if err := json.Unmarshal(data, &ss); err != nil { return err } us, err := strSliceToUUIDSlice(ss) if err != nil { return errors.WithStack(err) } *s = us return nil }
go
func (s *UUID) UnmarshalJSON(data []byte) error { var ss []string if err := json.Unmarshal(data, &ss); err != nil { return err } us, err := strSliceToUUIDSlice(ss) if err != nil { return errors.WithStack(err) } *s = us return nil }
[ "func", "(", "s", "*", "UUID", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "var", "ss", "[", "]", "string", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "ss", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "us", ",", "err", ":=", "strSliceToUUIDSlice", "(", "ss", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "*", "s", "=", "us", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON will unmarshall JSON value into // the UUID slice representation of this value.
[ "UnmarshalJSON", "will", "unmarshall", "JSON", "value", "into", "the", "UUID", "slice", "representation", "of", "this", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L50-L61
train
gobuffalo/pop
slices/uuid.go
UnmarshalText
func (s *UUID) UnmarshalText(text []byte) error { var ss []string for _, x := range strings.Split(string(text), ",") { ss = append(ss, strings.TrimSpace(x)) } us, err := strSliceToUUIDSlice(ss) if err != nil { return errors.WithStack(err) } *s = us return nil }
go
func (s *UUID) UnmarshalText(text []byte) error { var ss []string for _, x := range strings.Split(string(text), ",") { ss = append(ss, strings.TrimSpace(x)) } us, err := strSliceToUUIDSlice(ss) if err != nil { return errors.WithStack(err) } *s = us return nil }
[ "func", "(", "s", "*", "UUID", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "var", "ss", "[", "]", "string", "\n", "for", "_", ",", "x", ":=", "range", "strings", ".", "Split", "(", "string", "(", "text", ")", ",", "\"", "\"", ")", "{", "ss", "=", "append", "(", "ss", ",", "strings", ".", "TrimSpace", "(", "x", ")", ")", "\n", "}", "\n", "us", ",", "err", ":=", "strSliceToUUIDSlice", "(", "ss", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "*", "s", "=", "us", "\n", "return", "nil", "\n", "}" ]
// UnmarshalText will unmarshall text value into // the UUID slice representation of this value.
[ "UnmarshalText", "will", "unmarshall", "text", "value", "into", "the", "UUID", "slice", "representation", "of", "this", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L65-L76
train
gobuffalo/pop
migration.go
MigrationCreate
func MigrationCreate(path, name, ext string, up, down []byte) error { g := makr.New() n := time.Now().UTC() s := n.Format("20060102150405") upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext)) g.Add(makr.NewFile(upf, string(up))) downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name, ext)) g.Add(makr.NewFile(downf, string(down))) return g.Run(".", makr.Data{}) }
go
func MigrationCreate(path, name, ext string, up, down []byte) error { g := makr.New() n := time.Now().UTC() s := n.Format("20060102150405") upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext)) g.Add(makr.NewFile(upf, string(up))) downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name, ext)) g.Add(makr.NewFile(downf, string(down))) return g.Run(".", makr.Data{}) }
[ "func", "MigrationCreate", "(", "path", ",", "name", ",", "ext", "string", ",", "up", ",", "down", "[", "]", "byte", ")", "error", "{", "g", ":=", "makr", ".", "New", "(", ")", "\n", "n", ":=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "s", ":=", "n", ".", "Format", "(", "\"", "\"", ")", "\n\n", "upf", ":=", "filepath", ".", "Join", "(", "path", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "name", ",", "ext", ")", ")", "\n", "g", ".", "Add", "(", "makr", ".", "NewFile", "(", "upf", ",", "string", "(", "up", ")", ")", ")", "\n\n", "downf", ":=", "filepath", ".", "Join", "(", "path", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "name", ",", "ext", ")", ")", "\n", "g", ".", "Add", "(", "makr", ".", "NewFile", "(", "downf", ",", "string", "(", "down", ")", ")", ")", "\n\n", "return", "g", ".", "Run", "(", "\"", "\"", ",", "makr", ".", "Data", "{", "}", ")", "\n", "}" ]
// MigrationCreate writes contents for a given migration in normalized files
[ "MigrationCreate", "writes", "contents", "for", "a", "given", "migration", "in", "normalized", "files" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration.go#L14-L26
train
gobuffalo/pop
migrator.go
NewMigrator
func NewMigrator(c *Connection) Migrator { return Migrator{ Connection: c, Migrations: map[string]Migrations{ "up": {}, "down": {}, }, } }
go
func NewMigrator(c *Connection) Migrator { return Migrator{ Connection: c, Migrations: map[string]Migrations{ "up": {}, "down": {}, }, } }
[ "func", "NewMigrator", "(", "c", "*", "Connection", ")", "Migrator", "{", "return", "Migrator", "{", "Connection", ":", "c", ",", "Migrations", ":", "map", "[", "string", "]", "Migrations", "{", "\"", "\"", ":", "{", "}", ",", "\"", "\"", ":", "{", "}", ",", "}", ",", "}", "\n", "}" ]
// NewMigrator returns a new "blank" migrator. It is recommended // to use something like MigrationBox or FileMigrator. A "blank" // Migrator should only be used as the basis for a new type of // migration system.
[ "NewMigrator", "returns", "a", "new", "blank", "migrator", ".", "It", "is", "recommended", "to", "use", "something", "like", "MigrationBox", "or", "FileMigrator", ".", "A", "blank", "Migrator", "should", "only", "be", "used", "as", "the", "basis", "for", "a", "new", "type", "of", "migration", "system", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L22-L30
train
gobuffalo/pop
migrator.go
UpLogOnly
func (m Migrator) UpLogOnly() error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() mfs := m.Migrations["up"] sort.Sort(mfs) return c.Transaction(func(tx *Connection) error { for _, mi := range mfs { if mi.DBType != "all" && mi.DBType != c.Dialect.Name() { // Skip migration for non-matching dialect continue } exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } if exists { continue } _, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version)) if err != nil { return errors.Wrapf(err, "problem inserting migration version %s", mi.Version) } } return nil }) }) }
go
func (m Migrator) UpLogOnly() error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() mfs := m.Migrations["up"] sort.Sort(mfs) return c.Transaction(func(tx *Connection) error { for _, mi := range mfs { if mi.DBType != "all" && mi.DBType != c.Dialect.Name() { // Skip migration for non-matching dialect continue } exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } if exists { continue } _, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version)) if err != nil { return errors.Wrapf(err, "problem inserting migration version %s", mi.Version) } } return nil }) }) }
[ "func", "(", "m", "Migrator", ")", "UpLogOnly", "(", ")", "error", "{", "c", ":=", "m", ".", "Connection", "\n", "return", "m", ".", "exec", "(", "func", "(", ")", "error", "{", "mtn", ":=", "c", ".", "MigrationTableName", "(", ")", "\n", "mfs", ":=", "m", ".", "Migrations", "[", "\"", "\"", "]", "\n", "sort", ".", "Sort", "(", "mfs", ")", "\n", "return", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "Connection", ")", "error", "{", "for", "_", ",", "mi", ":=", "range", "mfs", "{", "if", "mi", ".", "DBType", "!=", "\"", "\"", "&&", "mi", ".", "DBType", "!=", "c", ".", "Dialect", ".", "Name", "(", ")", "{", "// Skip migration for non-matching dialect", "continue", "\n", "}", "\n", "exists", ",", "err", ":=", "c", ".", "Where", "(", "\"", "\"", ",", "mi", ".", "Version", ")", ".", "Exists", "(", "mtn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", "\n", "if", "exists", "{", "continue", "\n", "}", "\n", "_", ",", "err", "=", "tx", ".", "Store", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mtn", ",", "mi", ".", "Version", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}", ")", "\n", "}" ]
// UpLogOnly insert pending "up" migrations logs only, without applying the patch. // It's used when loading the schema dump, instead of the migrations.
[ "UpLogOnly", "insert", "pending", "up", "migrations", "logs", "only", "without", "applying", "the", "patch", ".", "It", "s", "used", "when", "loading", "the", "schema", "dump", "instead", "of", "the", "migrations", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L44-L71
train
gobuffalo/pop
migrator.go
Up
func (m Migrator) Up() error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() mfs := m.Migrations["up"] sort.Sort(mfs) applied := 0 for _, mi := range mfs { if mi.DBType != "all" && mi.DBType != c.Dialect.Name() { // Skip migration for non-matching dialect continue } exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } if exists { continue } err = c.Transaction(func(tx *Connection) error { err := mi.Run(tx) if err != nil { return err } _, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version)) return errors.Wrapf(err, "problem inserting migration version %s", mi.Version) }) if err != nil { return errors.WithStack(err) } log(logging.Info, "> %s", mi.Name) applied++ } if applied == 0 { log(logging.Info, "Migrations already up to date, nothing to apply") } return nil }) }
go
func (m Migrator) Up() error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() mfs := m.Migrations["up"] sort.Sort(mfs) applied := 0 for _, mi := range mfs { if mi.DBType != "all" && mi.DBType != c.Dialect.Name() { // Skip migration for non-matching dialect continue } exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } if exists { continue } err = c.Transaction(func(tx *Connection) error { err := mi.Run(tx) if err != nil { return err } _, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version)) return errors.Wrapf(err, "problem inserting migration version %s", mi.Version) }) if err != nil { return errors.WithStack(err) } log(logging.Info, "> %s", mi.Name) applied++ } if applied == 0 { log(logging.Info, "Migrations already up to date, nothing to apply") } return nil }) }
[ "func", "(", "m", "Migrator", ")", "Up", "(", ")", "error", "{", "c", ":=", "m", ".", "Connection", "\n", "return", "m", ".", "exec", "(", "func", "(", ")", "error", "{", "mtn", ":=", "c", ".", "MigrationTableName", "(", ")", "\n", "mfs", ":=", "m", ".", "Migrations", "[", "\"", "\"", "]", "\n", "sort", ".", "Sort", "(", "mfs", ")", "\n", "applied", ":=", "0", "\n", "for", "_", ",", "mi", ":=", "range", "mfs", "{", "if", "mi", ".", "DBType", "!=", "\"", "\"", "&&", "mi", ".", "DBType", "!=", "c", ".", "Dialect", ".", "Name", "(", ")", "{", "// Skip migration for non-matching dialect", "continue", "\n", "}", "\n", "exists", ",", "err", ":=", "c", ".", "Where", "(", "\"", "\"", ",", "mi", ".", "Version", ")", ".", "Exists", "(", "mtn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", "\n", "if", "exists", "{", "continue", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "Connection", ")", "error", "{", "err", ":=", "mi", ".", "Run", "(", "tx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "tx", ".", "Store", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mtn", ",", "mi", ".", "Version", ")", ")", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "log", "(", "logging", ".", "Info", ",", "\"", "\"", ",", "mi", ".", "Name", ")", "\n", "applied", "++", "\n", "}", "\n", "if", "applied", "==", "0", "{", "log", "(", "logging", ".", "Info", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// Up runs pending "up" migrations and applies them to the database.
[ "Up", "runs", "pending", "up", "migrations", "and", "applies", "them", "to", "the", "database", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L74-L112
train
gobuffalo/pop
migrator.go
Down
func (m Migrator) Down(step int) error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() count, err := c.Count(mtn) if err != nil { return errors.Wrap(err, "migration down: unable count existing migration") } mfs := m.Migrations["down"] sort.Sort(sort.Reverse(mfs)) // skip all runned migration if len(mfs) > count { mfs = mfs[len(mfs)-count:] } // run only required steps if step > 0 && len(mfs) >= step { mfs = mfs[:step] } for _, mi := range mfs { exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil || !exists { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } err = c.Transaction(func(tx *Connection) error { err := mi.Run(tx) if err != nil { return err } err = tx.RawQuery(fmt.Sprintf("delete from %s where version = ?", mtn), mi.Version).Exec() return errors.Wrapf(err, "problem deleting migration version %s", mi.Version) }) if err != nil { return err } log(logging.Info, "< %s", mi.Name) } return nil }) }
go
func (m Migrator) Down(step int) error { c := m.Connection return m.exec(func() error { mtn := c.MigrationTableName() count, err := c.Count(mtn) if err != nil { return errors.Wrap(err, "migration down: unable count existing migration") } mfs := m.Migrations["down"] sort.Sort(sort.Reverse(mfs)) // skip all runned migration if len(mfs) > count { mfs = mfs[len(mfs)-count:] } // run only required steps if step > 0 && len(mfs) >= step { mfs = mfs[:step] } for _, mi := range mfs { exists, err := c.Where("version = ?", mi.Version).Exists(mtn) if err != nil || !exists { return errors.Wrapf(err, "problem checking for migration version %s", mi.Version) } err = c.Transaction(func(tx *Connection) error { err := mi.Run(tx) if err != nil { return err } err = tx.RawQuery(fmt.Sprintf("delete from %s where version = ?", mtn), mi.Version).Exec() return errors.Wrapf(err, "problem deleting migration version %s", mi.Version) }) if err != nil { return err } log(logging.Info, "< %s", mi.Name) } return nil }) }
[ "func", "(", "m", "Migrator", ")", "Down", "(", "step", "int", ")", "error", "{", "c", ":=", "m", ".", "Connection", "\n", "return", "m", ".", "exec", "(", "func", "(", ")", "error", "{", "mtn", ":=", "c", ".", "MigrationTableName", "(", ")", "\n", "count", ",", "err", ":=", "c", ".", "Count", "(", "mtn", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "mfs", ":=", "m", ".", "Migrations", "[", "\"", "\"", "]", "\n", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "mfs", ")", ")", "\n", "// skip all runned migration", "if", "len", "(", "mfs", ")", ">", "count", "{", "mfs", "=", "mfs", "[", "len", "(", "mfs", ")", "-", "count", ":", "]", "\n", "}", "\n", "// run only required steps", "if", "step", ">", "0", "&&", "len", "(", "mfs", ")", ">=", "step", "{", "mfs", "=", "mfs", "[", ":", "step", "]", "\n", "}", "\n", "for", "_", ",", "mi", ":=", "range", "mfs", "{", "exists", ",", "err", ":=", "c", ".", "Where", "(", "\"", "\"", ",", "mi", ".", "Version", ")", ".", "Exists", "(", "mtn", ")", "\n", "if", "err", "!=", "nil", "||", "!", "exists", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "Connection", ")", "error", "{", "err", ":=", "mi", ".", "Run", "(", "tx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "tx", ".", "RawQuery", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mtn", ")", ",", "mi", ".", "Version", ")", ".", "Exec", "(", ")", "\n", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "mi", ".", "Version", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "log", "(", "logging", ".", "Info", ",", "\"", "\"", ",", "mi", ".", "Name", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// Down runs pending "down" migrations and rolls back the // database by the specified number of steps.
[ "Down", "runs", "pending", "down", "migrations", "and", "rolls", "back", "the", "database", "by", "the", "specified", "number", "of", "steps", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L116-L155
train
gobuffalo/pop
migrator.go
Reset
func (m Migrator) Reset() error { err := m.Down(-1) if err != nil { return errors.WithStack(err) } return m.Up() }
go
func (m Migrator) Reset() error { err := m.Down(-1) if err != nil { return errors.WithStack(err) } return m.Up() }
[ "func", "(", "m", "Migrator", ")", "Reset", "(", ")", "error", "{", "err", ":=", "m", ".", "Down", "(", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "m", ".", "Up", "(", ")", "\n", "}" ]
// Reset the database by running the down migrations followed by the up migrations.
[ "Reset", "the", "database", "by", "running", "the", "down", "migrations", "followed", "by", "the", "up", "migrations", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L158-L164
train