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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
open-policy-agent/opa | server/authorizer/authorizer.go | Decision | func Decision(ref func() ast.Ref) func(*Basic) {
return func(b *Basic) {
b.decision = ref
}
} | go | func Decision(ref func() ast.Ref) func(*Basic) {
return func(b *Basic) {
b.decision = ref
}
} | [
"func",
"Decision",
"(",
"ref",
"func",
"(",
")",
"ast",
".",
"Ref",
")",
"func",
"(",
"*",
"Basic",
")",
"{",
"return",
"func",
"(",
"b",
"*",
"Basic",
")",
"{",
"b",
".",
"decision",
"=",
"ref",
"\n",
"}",
"\n",
"}"
] | // Decision returns an argument that sets the path of the authorization decision
// to query. | [
"Decision",
"returns",
"an",
"argument",
"that",
"sets",
"the",
"path",
"of",
"the",
"authorization",
"decision",
"to",
"query",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/authorizer/authorizer.go#L39-L43 | train |
open-policy-agent/opa | server/authorizer/authorizer.go | NewBasic | func NewBasic(inner http.Handler, compiler func() *ast.Compiler, store storage.Store, opts ...func(*Basic)) http.Handler {
b := &Basic{
inner: inner,
compiler: compiler,
store: store,
}
for _, opt := range opts {
opt(b)
}
return b
} | go | func NewBasic(inner http.Handler, compiler func() *ast.Compiler, store storage.Store, opts ...func(*Basic)) http.Handler {
b := &Basic{
inner: inner,
compiler: compiler,
store: store,
}
for _, opt := range opts {
opt(b)
}
return b
} | [
"func",
"NewBasic",
"(",
"inner",
"http",
".",
"Handler",
",",
"compiler",
"func",
"(",
")",
"*",
"ast",
".",
"Compiler",
",",
"store",
"storage",
".",
"Store",
",",
"opts",
"...",
"func",
"(",
"*",
"Basic",
")",
")",
"http",
".",
"Handler",
"{",
"b",
":=",
"&",
"Basic",
"{",
"inner",
":",
"inner",
",",
"compiler",
":",
"compiler",
",",
"store",
":",
"store",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"return",
"b",
"\n",
"}"
] | // NewBasic returns a new Basic object. | [
"NewBasic",
"returns",
"a",
"new",
"Basic",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/server/authorizer/authorizer.go#L46-L58 | train |
open-policy-agent/opa | util/backoff.go | DefaultBackoff | func DefaultBackoff(base, max float64, retries int) time.Duration {
return Backoff(base, max, .2, 1.6, retries)
} | go | func DefaultBackoff(base, max float64, retries int) time.Duration {
return Backoff(base, max, .2, 1.6, retries)
} | [
"func",
"DefaultBackoff",
"(",
"base",
",",
"max",
"float64",
",",
"retries",
"int",
")",
"time",
".",
"Duration",
"{",
"return",
"Backoff",
"(",
"base",
",",
"max",
",",
".2",
",",
"1.6",
",",
"retries",
")",
"\n",
"}"
] | // DefaultBackoff returns a delay with an expontential backoff based on the
// number of retries. | [
"DefaultBackoff",
"returns",
"a",
"delay",
"with",
"an",
"expontential",
"backoff",
"based",
"on",
"the",
"number",
"of",
"retries",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/backoff.go#L14-L16 | train |
open-policy-agent/opa | util/backoff.go | Backoff | func Backoff(base, max, jitter, factor float64, retries int) time.Duration {
if retries == 0 {
return 0
}
backoff, max := float64(base), float64(max)
for backoff < max && retries > 0 {
backoff *= factor
retries--
}
if backoff > max {
backoff = max
}
// Randomize backoff delays so that if a cluster of requests start at
// the same time, they won't operate in lockstep.
backoff *= 1 + jitter*(rand.Float64()*2-1)
if backoff < 0 {
return 0
}
return time.Duration(backoff)
} | go | func Backoff(base, max, jitter, factor float64, retries int) time.Duration {
if retries == 0 {
return 0
}
backoff, max := float64(base), float64(max)
for backoff < max && retries > 0 {
backoff *= factor
retries--
}
if backoff > max {
backoff = max
}
// Randomize backoff delays so that if a cluster of requests start at
// the same time, they won't operate in lockstep.
backoff *= 1 + jitter*(rand.Float64()*2-1)
if backoff < 0 {
return 0
}
return time.Duration(backoff)
} | [
"func",
"Backoff",
"(",
"base",
",",
"max",
",",
"jitter",
",",
"factor",
"float64",
",",
"retries",
"int",
")",
"time",
".",
"Duration",
"{",
"if",
"retries",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"backoff",
",",
"max",
":=",
"float64",
"(",
"base",
")",
",",
"float64",
"(",
"max",
")",
"\n",
"for",
"backoff",
"<",
"max",
"&&",
"retries",
">",
"0",
"{",
"backoff",
"*=",
"factor",
"\n",
"retries",
"--",
"\n",
"}",
"\n",
"if",
"backoff",
">",
"max",
"{",
"backoff",
"=",
"max",
"\n",
"}",
"\n\n",
"// Randomize backoff delays so that if a cluster of requests start at",
"// the same time, they won't operate in lockstep.",
"backoff",
"*=",
"1",
"+",
"jitter",
"*",
"(",
"rand",
".",
"Float64",
"(",
")",
"*",
"2",
"-",
"1",
")",
"\n",
"if",
"backoff",
"<",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"return",
"time",
".",
"Duration",
"(",
"backoff",
")",
"\n",
"}"
] | // Backoff returns a delay with an expontential backoff based on the number of
// retries. Same algorithm used in gRPC. | [
"Backoff",
"returns",
"a",
"delay",
"with",
"an",
"expontential",
"backoff",
"based",
"on",
"the",
"number",
"of",
"retries",
".",
"Same",
"algorithm",
"used",
"in",
"gRPC",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/util/backoff.go#L20-L42 | train |
open-policy-agent/opa | internal/manifest/manifest.go | Write | func Write(ctx context.Context, store storage.Store, txn storage.Transaction, m bundle.Manifest) error {
var value interface{} = m
if err := util.RoundTrip(&value); err != nil {
return err
}
if err := storage.MakeDir(ctx, store, txn, bundlePath); err != nil {
return err
}
return store.Write(ctx, txn, storage.AddOp, manifestPath, value)
} | go | func Write(ctx context.Context, store storage.Store, txn storage.Transaction, m bundle.Manifest) error {
var value interface{} = m
if err := util.RoundTrip(&value); err != nil {
return err
}
if err := storage.MakeDir(ctx, store, txn, bundlePath); err != nil {
return err
}
return store.Write(ctx, txn, storage.AddOp, manifestPath, value)
} | [
"func",
"Write",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"storage",
".",
"Store",
",",
"txn",
"storage",
".",
"Transaction",
",",
"m",
"bundle",
".",
"Manifest",
")",
"error",
"{",
"var",
"value",
"interface",
"{",
"}",
"=",
"m",
"\n\n",
"if",
"err",
":=",
"util",
".",
"RoundTrip",
"(",
"&",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"storage",
".",
"MakeDir",
"(",
"ctx",
",",
"store",
",",
"txn",
",",
"bundlePath",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"store",
".",
"Write",
"(",
"ctx",
",",
"txn",
",",
"storage",
".",
"AddOp",
",",
"manifestPath",
",",
"value",
")",
"\n",
"}"
] | // Write the manifest into the storage. This function is called when
// the bundle is activated. | [
"Write",
"the",
"manifest",
"into",
"the",
"storage",
".",
"This",
"function",
"is",
"called",
"when",
"the",
"bundle",
"is",
"activated",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/manifest/manifest.go#L24-L37 | train |
open-policy-agent/opa | internal/manifest/manifest.go | ReadBundleRoots | func ReadBundleRoots(ctx context.Context, store storage.Store, txn storage.Transaction) ([]string, error) {
value, err := store.Read(ctx, txn, rootsPath)
if err != nil {
return nil, err
}
sl, ok := value.([]interface{})
if !ok {
return nil, fmt.Errorf("corrupt manifest roots")
}
roots := make([]string, len(sl))
for i := range sl {
roots[i], ok = sl[i].(string)
if !ok {
return nil, fmt.Errorf("corrupt manifest root")
}
}
return roots, nil
} | go | func ReadBundleRoots(ctx context.Context, store storage.Store, txn storage.Transaction) ([]string, error) {
value, err := store.Read(ctx, txn, rootsPath)
if err != nil {
return nil, err
}
sl, ok := value.([]interface{})
if !ok {
return nil, fmt.Errorf("corrupt manifest roots")
}
roots := make([]string, len(sl))
for i := range sl {
roots[i], ok = sl[i].(string)
if !ok {
return nil, fmt.Errorf("corrupt manifest root")
}
}
return roots, nil
} | [
"func",
"ReadBundleRoots",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"storage",
".",
"Store",
",",
"txn",
"storage",
".",
"Transaction",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"value",
",",
"err",
":=",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"rootsPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"sl",
",",
"ok",
":=",
"value",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"roots",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"sl",
")",
")",
"\n\n",
"for",
"i",
":=",
"range",
"sl",
"{",
"roots",
"[",
"i",
"]",
",",
"ok",
"=",
"sl",
"[",
"i",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"roots",
",",
"nil",
"\n",
"}"
] | // ReadBundleRoots returns the roots specified in the currently
// activated bundle. If there is no activated bundle, this function
// will return storage NotFound error. | [
"ReadBundleRoots",
"returns",
"the",
"roots",
"specified",
"in",
"the",
"currently",
"activated",
"bundle",
".",
"If",
"there",
"is",
"no",
"activated",
"bundle",
"this",
"function",
"will",
"return",
"storage",
"NotFound",
"error",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/manifest/manifest.go#L42-L64 | train |
open-policy-agent/opa | internal/manifest/manifest.go | ReadBundleRevision | func ReadBundleRevision(ctx context.Context, store storage.Store, txn storage.Transaction) (string, error) {
value, err := store.Read(ctx, txn, revisionPath)
if err != nil {
return "", err
}
str, ok := value.(string)
if !ok {
return "", fmt.Errorf("corrupt manifest revision")
}
return str, nil
} | go | func ReadBundleRevision(ctx context.Context, store storage.Store, txn storage.Transaction) (string, error) {
value, err := store.Read(ctx, txn, revisionPath)
if err != nil {
return "", err
}
str, ok := value.(string)
if !ok {
return "", fmt.Errorf("corrupt manifest revision")
}
return str, nil
} | [
"func",
"ReadBundleRevision",
"(",
"ctx",
"context",
".",
"Context",
",",
"store",
"storage",
".",
"Store",
",",
"txn",
"storage",
".",
"Transaction",
")",
"(",
"string",
",",
"error",
")",
"{",
"value",
",",
"err",
":=",
"store",
".",
"Read",
"(",
"ctx",
",",
"txn",
",",
"revisionPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"str",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"str",
",",
"nil",
"\n",
"}"
] | // ReadBundleRevision returns the revision in the currently activated
// bundle. If there is no activated bundle, ths function will return
// storage NotFound error. | [
"ReadBundleRevision",
"returns",
"the",
"revision",
"in",
"the",
"currently",
"activated",
"bundle",
".",
"If",
"there",
"is",
"no",
"activated",
"bundle",
"ths",
"function",
"will",
"return",
"storage",
"NotFound",
"error",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/internal/manifest/manifest.go#L69-L82 | train |
open-policy-agent/opa | ast/term.go | NewLocation | func NewLocation(text []byte, file string, row int, col int) *Location {
return &Location{Text: text, File: file, Row: row, Col: col}
} | go | func NewLocation(text []byte, file string, row int, col int) *Location {
return &Location{Text: text, File: file, Row: row, Col: col}
} | [
"func",
"NewLocation",
"(",
"text",
"[",
"]",
"byte",
",",
"file",
"string",
",",
"row",
"int",
",",
"col",
"int",
")",
"*",
"Location",
"{",
"return",
"&",
"Location",
"{",
"Text",
":",
"text",
",",
"File",
":",
"file",
",",
"Row",
":",
"row",
",",
"Col",
":",
"col",
"}",
"\n",
"}"
] | // NewLocation returns a new Location object. | [
"NewLocation",
"returns",
"a",
"new",
"Location",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L31-L33 | train |
open-policy-agent/opa | ast/term.go | Equal | func (loc *Location) Equal(other *Location) bool {
return bytes.Equal(loc.Text, other.Text) &&
loc.File == other.File &&
loc.Row == other.Row &&
loc.Col == other.Col
} | go | func (loc *Location) Equal(other *Location) bool {
return bytes.Equal(loc.Text, other.Text) &&
loc.File == other.File &&
loc.Row == other.Row &&
loc.Col == other.Col
} | [
"func",
"(",
"loc",
"*",
"Location",
")",
"Equal",
"(",
"other",
"*",
"Location",
")",
"bool",
"{",
"return",
"bytes",
".",
"Equal",
"(",
"loc",
".",
"Text",
",",
"other",
".",
"Text",
")",
"&&",
"loc",
".",
"File",
"==",
"other",
".",
"File",
"&&",
"loc",
".",
"Row",
"==",
"other",
".",
"Row",
"&&",
"loc",
".",
"Col",
"==",
"other",
".",
"Col",
"\n",
"}"
] | // Equal checks if two locations are equal to each other. | [
"Equal",
"checks",
"if",
"two",
"locations",
"are",
"equal",
"to",
"each",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L36-L41 | train |
open-policy-agent/opa | ast/term.go | Format | func (loc *Location) Format(f string, a ...interface{}) string {
if len(loc.File) > 0 {
f = fmt.Sprintf("%v:%v: %v", loc.File, loc.Row, f)
} else {
f = fmt.Sprintf("%v:%v: %v", loc.Row, loc.Col, f)
}
return fmt.Sprintf(f, a...)
} | go | func (loc *Location) Format(f string, a ...interface{}) string {
if len(loc.File) > 0 {
f = fmt.Sprintf("%v:%v: %v", loc.File, loc.Row, f)
} else {
f = fmt.Sprintf("%v:%v: %v", loc.Row, loc.Col, f)
}
return fmt.Sprintf(f, a...)
} | [
"func",
"(",
"loc",
"*",
"Location",
")",
"Format",
"(",
"f",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"len",
"(",
"loc",
".",
"File",
")",
">",
"0",
"{",
"f",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"loc",
".",
"File",
",",
"loc",
".",
"Row",
",",
"f",
")",
"\n",
"}",
"else",
"{",
"f",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"loc",
".",
"Row",
",",
"loc",
".",
"Col",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"f",
",",
"a",
"...",
")",
"\n",
"}"
] | // Format returns a formatted string prefixed with the location information. | [
"Format",
"returns",
"a",
"formatted",
"string",
"prefixed",
"with",
"the",
"location",
"information",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L56-L63 | train |
open-policy-agent/opa | ast/term.go | InterfaceToValue | func InterfaceToValue(x interface{}) (Value, error) {
switch x := x.(type) {
case nil:
return Null{}, nil
case bool:
return Boolean(x), nil
case json.Number:
return Number(x), nil
case int64:
return int64Number(x), nil
case float64:
return floatNumber(x), nil
case int:
return intNumber(x), nil
case string:
return String(x), nil
case []interface{}:
r := Array{}
for _, e := range x {
e, err := InterfaceToValue(e)
if err != nil {
return nil, err
}
r = append(r, &Term{Value: e})
}
return r, nil
case map[string]interface{}:
r := NewObject()
for k, v := range x {
k, err := InterfaceToValue(k)
if err != nil {
return nil, err
}
v, err := InterfaceToValue(v)
if err != nil {
return nil, err
}
r.Insert(NewTerm(k), NewTerm(v))
}
return r, nil
case map[string]string:
r := NewObject()
for k, v := range x {
k, err := InterfaceToValue(k)
if err != nil {
return nil, err
}
v, err := InterfaceToValue(v)
if err != nil {
return nil, err
}
r.Insert(NewTerm(k), NewTerm(v))
}
return r, nil
default:
return nil, fmt.Errorf("ast: illegal value: %T", x)
}
} | go | func InterfaceToValue(x interface{}) (Value, error) {
switch x := x.(type) {
case nil:
return Null{}, nil
case bool:
return Boolean(x), nil
case json.Number:
return Number(x), nil
case int64:
return int64Number(x), nil
case float64:
return floatNumber(x), nil
case int:
return intNumber(x), nil
case string:
return String(x), nil
case []interface{}:
r := Array{}
for _, e := range x {
e, err := InterfaceToValue(e)
if err != nil {
return nil, err
}
r = append(r, &Term{Value: e})
}
return r, nil
case map[string]interface{}:
r := NewObject()
for k, v := range x {
k, err := InterfaceToValue(k)
if err != nil {
return nil, err
}
v, err := InterfaceToValue(v)
if err != nil {
return nil, err
}
r.Insert(NewTerm(k), NewTerm(v))
}
return r, nil
case map[string]string:
r := NewObject()
for k, v := range x {
k, err := InterfaceToValue(k)
if err != nil {
return nil, err
}
v, err := InterfaceToValue(v)
if err != nil {
return nil, err
}
r.Insert(NewTerm(k), NewTerm(v))
}
return r, nil
default:
return nil, fmt.Errorf("ast: illegal value: %T", x)
}
} | [
"func",
"InterfaceToValue",
"(",
"x",
"interface",
"{",
"}",
")",
"(",
"Value",
",",
"error",
")",
"{",
"switch",
"x",
":=",
"x",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"Null",
"{",
"}",
",",
"nil",
"\n",
"case",
"bool",
":",
"return",
"Boolean",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"json",
".",
"Number",
":",
"return",
"Number",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"int64",
":",
"return",
"int64Number",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"float64",
":",
"return",
"floatNumber",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"int",
":",
"return",
"intNumber",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"string",
":",
"return",
"String",
"(",
"x",
")",
",",
"nil",
"\n",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"r",
":=",
"Array",
"{",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"x",
"{",
"e",
",",
"err",
":=",
"InterfaceToValue",
"(",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
"=",
"append",
"(",
"r",
",",
"&",
"Term",
"{",
"Value",
":",
"e",
"}",
")",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"case",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"r",
":=",
"NewObject",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"x",
"{",
"k",
",",
"err",
":=",
"InterfaceToValue",
"(",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"InterfaceToValue",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"Insert",
"(",
"NewTerm",
"(",
"k",
")",
",",
"NewTerm",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"case",
"map",
"[",
"string",
"]",
"string",
":",
"r",
":=",
"NewObject",
"(",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"x",
"{",
"k",
",",
"err",
":=",
"InterfaceToValue",
"(",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"InterfaceToValue",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"Insert",
"(",
"NewTerm",
"(",
"k",
")",
",",
"NewTerm",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"x",
")",
"\n",
"}",
"\n",
"}"
] | // InterfaceToValue converts a native Go value x to a Value. | [
"InterfaceToValue",
"converts",
"a",
"native",
"Go",
"value",
"x",
"to",
"a",
"Value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L118-L175 | train |
open-policy-agent/opa | ast/term.go | MustInterfaceToValue | func MustInterfaceToValue(x interface{}) Value {
v, err := InterfaceToValue(x)
if err != nil {
panic(err)
}
return v
} | go | func MustInterfaceToValue(x interface{}) Value {
v, err := InterfaceToValue(x)
if err != nil {
panic(err)
}
return v
} | [
"func",
"MustInterfaceToValue",
"(",
"x",
"interface",
"{",
"}",
")",
"Value",
"{",
"v",
",",
"err",
":=",
"InterfaceToValue",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // MustInterfaceToValue converts a native Go value x to a Value. If the
// conversion fails, this function will panic. This function is mostly for test
// purposes. | [
"MustInterfaceToValue",
"converts",
"a",
"native",
"Go",
"value",
"x",
"to",
"a",
"Value",
".",
"If",
"the",
"conversion",
"fails",
"this",
"function",
"will",
"panic",
".",
"This",
"function",
"is",
"mostly",
"for",
"test",
"purposes",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L282-L288 | train |
open-policy-agent/opa | ast/term.go | SetLocation | func (term *Term) SetLocation(loc *Location) *Term {
term.Location = loc
return term
} | go | func (term *Term) SetLocation(loc *Location) *Term {
term.Location = loc
return term
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"SetLocation",
"(",
"loc",
"*",
"Location",
")",
"*",
"Term",
"{",
"term",
".",
"Location",
"=",
"loc",
"\n",
"return",
"term",
"\n",
"}"
] | // SetLocation updates the term's Location and returns the term itself. | [
"SetLocation",
"updates",
"the",
"term",
"s",
"Location",
"and",
"returns",
"the",
"term",
"itself",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L304-L307 | train |
open-policy-agent/opa | ast/term.go | Copy | func (term *Term) Copy() *Term {
if term == nil {
return nil
}
cpy := *term
switch v := term.Value.(type) {
case Null, Boolean, Number, String, Var:
cpy.Value = v
case Ref:
cpy.Value = v.Copy()
case Array:
cpy.Value = v.Copy()
case Set:
cpy.Value = v.Copy()
case Object:
cpy.Value = v.Copy()
case *ArrayComprehension:
cpy.Value = v.Copy()
case *ObjectComprehension:
cpy.Value = v.Copy()
case *SetComprehension:
cpy.Value = v.Copy()
case Call:
cpy.Value = v.Copy()
}
return &cpy
} | go | func (term *Term) Copy() *Term {
if term == nil {
return nil
}
cpy := *term
switch v := term.Value.(type) {
case Null, Boolean, Number, String, Var:
cpy.Value = v
case Ref:
cpy.Value = v.Copy()
case Array:
cpy.Value = v.Copy()
case Set:
cpy.Value = v.Copy()
case Object:
cpy.Value = v.Copy()
case *ArrayComprehension:
cpy.Value = v.Copy()
case *ObjectComprehension:
cpy.Value = v.Copy()
case *SetComprehension:
cpy.Value = v.Copy()
case Call:
cpy.Value = v.Copy()
}
return &cpy
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"Copy",
"(",
")",
"*",
"Term",
"{",
"if",
"term",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"cpy",
":=",
"*",
"term",
"\n\n",
"switch",
"v",
":=",
"term",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"Null",
",",
"Boolean",
",",
"Number",
",",
"String",
",",
"Var",
":",
"cpy",
".",
"Value",
"=",
"v",
"\n",
"case",
"Ref",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Array",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Set",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Object",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"*",
"ArrayComprehension",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"*",
"ObjectComprehension",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"*",
"SetComprehension",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Call",
":",
"cpy",
".",
"Value",
"=",
"v",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of term. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"term",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L323-L353 | train |
open-policy-agent/opa | ast/term.go | Equal | func (term *Term) Equal(other *Term) bool {
if term == nil && other != nil {
return false
}
if term != nil && other == nil {
return false
}
if term == other {
return true
}
return term.Value.Compare(other.Value) == 0
} | go | func (term *Term) Equal(other *Term) bool {
if term == nil && other != nil {
return false
}
if term != nil && other == nil {
return false
}
if term == other {
return true
}
return term.Value.Compare(other.Value) == 0
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"Equal",
"(",
"other",
"*",
"Term",
")",
"bool",
"{",
"if",
"term",
"==",
"nil",
"&&",
"other",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"term",
"!=",
"nil",
"&&",
"other",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"term",
"==",
"other",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"term",
".",
"Value",
".",
"Compare",
"(",
"other",
".",
"Value",
")",
"==",
"0",
"\n",
"}"
] | // Equal returns true if this term equals the other term. Equality is
// defined for each kind of term. | [
"Equal",
"returns",
"true",
"if",
"this",
"term",
"equals",
"the",
"other",
"term",
".",
"Equality",
"is",
"defined",
"for",
"each",
"kind",
"of",
"term",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L357-L368 | train |
open-policy-agent/opa | ast/term.go | Get | func (term *Term) Get(name *Term) *Term {
switch v := term.Value.(type) {
case Array:
return v.Get(name)
case Object:
return v.Get(name)
case Set:
if v.Contains(name) {
return name
}
}
return nil
} | go | func (term *Term) Get(name *Term) *Term {
switch v := term.Value.(type) {
case Array:
return v.Get(name)
case Object:
return v.Get(name)
case Set:
if v.Contains(name) {
return name
}
}
return nil
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"Get",
"(",
"name",
"*",
"Term",
")",
"*",
"Term",
"{",
"switch",
"v",
":=",
"term",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"Array",
":",
"return",
"v",
".",
"Get",
"(",
"name",
")",
"\n",
"case",
"Object",
":",
"return",
"v",
".",
"Get",
"(",
"name",
")",
"\n",
"case",
"Set",
":",
"if",
"v",
".",
"Contains",
"(",
"name",
")",
"{",
"return",
"name",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Get returns a value referred to by name from the term. | [
"Get",
"returns",
"a",
"value",
"referred",
"to",
"by",
"name",
"from",
"the",
"term",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L371-L383 | train |
open-policy-agent/opa | ast/term.go | MarshalJSON | func (term *Term) MarshalJSON() ([]byte, error) {
d := map[string]interface{}{
"type": TypeName(term.Value),
"value": term.Value,
}
return json.Marshal(d)
} | go | func (term *Term) MarshalJSON() ([]byte, error) {
d := map[string]interface{}{
"type": TypeName(term.Value),
"value": term.Value,
}
return json.Marshal(d)
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"d",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"TypeName",
"(",
"term",
".",
"Value",
")",
",",
"\"",
"\"",
":",
"term",
".",
"Value",
",",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"d",
")",
"\n",
"}"
] | // MarshalJSON returns the JSON encoding of the term.
//
// Specialized marshalling logic is required to include a type hint for Value. | [
"MarshalJSON",
"returns",
"the",
"JSON",
"encoding",
"of",
"the",
"term",
".",
"Specialized",
"marshalling",
"logic",
"is",
"required",
"to",
"include",
"a",
"type",
"hint",
"for",
"Value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L398-L404 | train |
open-policy-agent/opa | ast/term.go | UnmarshalJSON | func (term *Term) UnmarshalJSON(bs []byte) error {
v := map[string]interface{}{}
if err := util.UnmarshalJSON(bs, &v); err != nil {
return err
}
val, err := unmarshalValue(v)
if err != nil {
return err
}
term.Value = val
return nil
} | go | func (term *Term) UnmarshalJSON(bs []byte) error {
v := map[string]interface{}{}
if err := util.UnmarshalJSON(bs, &v); err != nil {
return err
}
val, err := unmarshalValue(v)
if err != nil {
return err
}
term.Value = val
return nil
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"UnmarshalJSON",
"(",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"v",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"util",
".",
"UnmarshalJSON",
"(",
"bs",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"val",
",",
"err",
":=",
"unmarshalValue",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"term",
".",
"Value",
"=",
"val",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON parses the byte array and stores the result in term.
// Specialized unmarshalling is required to handle Value. | [
"UnmarshalJSON",
"parses",
"the",
"byte",
"array",
"and",
"stores",
"the",
"result",
"in",
"term",
".",
"Specialized",
"unmarshalling",
"is",
"required",
"to",
"handle",
"Value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L412-L423 | train |
open-policy-agent/opa | ast/term.go | Vars | func (term *Term) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
Walk(vis, term)
return vis.vars
} | go | func (term *Term) Vars() VarSet {
vis := &VarVisitor{vars: VarSet{}}
Walk(vis, term)
return vis.vars
} | [
"func",
"(",
"term",
"*",
"Term",
")",
"Vars",
"(",
")",
"VarSet",
"{",
"vis",
":=",
"&",
"VarVisitor",
"{",
"vars",
":",
"VarSet",
"{",
"}",
"}",
"\n",
"Walk",
"(",
"vis",
",",
"term",
")",
"\n",
"return",
"vis",
".",
"vars",
"\n",
"}"
] | // Vars returns a VarSet with variables contained in this term. | [
"Vars",
"returns",
"a",
"VarSet",
"with",
"variables",
"contained",
"in",
"this",
"term",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L426-L430 | train |
open-policy-agent/opa | ast/term.go | IsConstant | func IsConstant(v Value) bool {
found := false
Walk(&GenericVisitor{
func(x interface{}) bool {
switch x.(type) {
case Var, Ref, *ArrayComprehension, *ObjectComprehension, *SetComprehension, Call:
found = true
return true
}
return false
},
}, v)
return !found
} | go | func IsConstant(v Value) bool {
found := false
Walk(&GenericVisitor{
func(x interface{}) bool {
switch x.(type) {
case Var, Ref, *ArrayComprehension, *ObjectComprehension, *SetComprehension, Call:
found = true
return true
}
return false
},
}, v)
return !found
} | [
"func",
"IsConstant",
"(",
"v",
"Value",
")",
"bool",
"{",
"found",
":=",
"false",
"\n",
"Walk",
"(",
"&",
"GenericVisitor",
"{",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"bool",
"{",
"switch",
"x",
".",
"(",
"type",
")",
"{",
"case",
"Var",
",",
"Ref",
",",
"*",
"ArrayComprehension",
",",
"*",
"ObjectComprehension",
",",
"*",
"SetComprehension",
",",
"Call",
":",
"found",
"=",
"true",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
",",
"}",
",",
"v",
")",
"\n",
"return",
"!",
"found",
"\n",
"}"
] | // IsConstant returns true if the AST value is constant. | [
"IsConstant",
"returns",
"true",
"if",
"the",
"AST",
"value",
"is",
"constant",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L433-L446 | train |
open-policy-agent/opa | ast/term.go | IsComprehension | func IsComprehension(x Value) bool {
switch x.(type) {
case *ArrayComprehension, *ObjectComprehension, *SetComprehension:
return true
}
return false
} | go | func IsComprehension(x Value) bool {
switch x.(type) {
case *ArrayComprehension, *ObjectComprehension, *SetComprehension:
return true
}
return false
} | [
"func",
"IsComprehension",
"(",
"x",
"Value",
")",
"bool",
"{",
"switch",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ArrayComprehension",
",",
"*",
"ObjectComprehension",
",",
"*",
"SetComprehension",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsComprehension returns true if the supplied value is a comprehension. | [
"IsComprehension",
"returns",
"true",
"if",
"the",
"supplied",
"value",
"is",
"a",
"comprehension",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L449-L455 | train |
open-policy-agent/opa | ast/term.go | ContainsRefs | func ContainsRefs(v interface{}) bool {
found := false
WalkRefs(v, func(r Ref) bool {
found = true
return found
})
return found
} | go | func ContainsRefs(v interface{}) bool {
found := false
WalkRefs(v, func(r Ref) bool {
found = true
return found
})
return found
} | [
"func",
"ContainsRefs",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"found",
":=",
"false",
"\n",
"WalkRefs",
"(",
"v",
",",
"func",
"(",
"r",
"Ref",
")",
"bool",
"{",
"found",
"=",
"true",
"\n",
"return",
"found",
"\n",
"}",
")",
"\n",
"return",
"found",
"\n",
"}"
] | // ContainsRefs returns true if the Value v contains refs. | [
"ContainsRefs",
"returns",
"true",
"if",
"the",
"Value",
"v",
"contains",
"refs",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L458-L465 | train |
open-policy-agent/opa | ast/term.go | ContainsComprehensions | func ContainsComprehensions(v interface{}) bool {
found := false
WalkClosures(v, func(x interface{}) bool {
switch x.(type) {
case *ArrayComprehension, *ObjectComprehension, *SetComprehension:
found = true
return found
}
return found
})
return found
} | go | func ContainsComprehensions(v interface{}) bool {
found := false
WalkClosures(v, func(x interface{}) bool {
switch x.(type) {
case *ArrayComprehension, *ObjectComprehension, *SetComprehension:
found = true
return found
}
return found
})
return found
} | [
"func",
"ContainsComprehensions",
"(",
"v",
"interface",
"{",
"}",
")",
"bool",
"{",
"found",
":=",
"false",
"\n",
"WalkClosures",
"(",
"v",
",",
"func",
"(",
"x",
"interface",
"{",
"}",
")",
"bool",
"{",
"switch",
"x",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ArrayComprehension",
",",
"*",
"ObjectComprehension",
",",
"*",
"SetComprehension",
":",
"found",
"=",
"true",
"\n",
"return",
"found",
"\n",
"}",
"\n",
"return",
"found",
"\n",
"}",
")",
"\n",
"return",
"found",
"\n",
"}"
] | // ContainsComprehensions returns true if the Value v contains comprehensions. | [
"ContainsComprehensions",
"returns",
"true",
"if",
"the",
"Value",
"v",
"contains",
"comprehensions",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L468-L479 | train |
open-policy-agent/opa | ast/term.go | IsScalar | func IsScalar(v Value) bool {
switch v.(type) {
case String:
return true
case Number:
return true
case Boolean:
return true
case Null:
return true
}
return false
} | go | func IsScalar(v Value) bool {
switch v.(type) {
case String:
return true
case Number:
return true
case Boolean:
return true
case Null:
return true
}
return false
} | [
"func",
"IsScalar",
"(",
"v",
"Value",
")",
"bool",
"{",
"switch",
"v",
".",
"(",
"type",
")",
"{",
"case",
"String",
":",
"return",
"true",
"\n",
"case",
"Number",
":",
"return",
"true",
"\n",
"case",
"Boolean",
":",
"return",
"true",
"\n",
"case",
"Null",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsScalar returns true if the AST value is a scalar. | [
"IsScalar",
"returns",
"true",
"if",
"the",
"AST",
"value",
"is",
"a",
"scalar",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L482-L494 | train |
open-policy-agent/opa | ast/term.go | Equal | func (null Null) Equal(other Value) bool {
switch other.(type) {
case Null:
return true
default:
return false
}
} | go | func (null Null) Equal(other Value) bool {
switch other.(type) {
case Null:
return true
default:
return false
}
} | [
"func",
"(",
"null",
"Null",
")",
"Equal",
"(",
"other",
"Value",
")",
"bool",
"{",
"switch",
"other",
".",
"(",
"type",
")",
"{",
"case",
"Null",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // Equal returns true if the other term Value is also Null. | [
"Equal",
"returns",
"true",
"if",
"the",
"other",
"term",
"Value",
"is",
"also",
"Null",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L505-L512 | train |
open-policy-agent/opa | ast/term.go | Equal | func (bol Boolean) Equal(other Value) bool {
switch other := other.(type) {
case Boolean:
return bol == other
default:
return false
}
} | go | func (bol Boolean) Equal(other Value) bool {
switch other := other.(type) {
case Boolean:
return bol == other
default:
return false
}
} | [
"func",
"(",
"bol",
"Boolean",
")",
"Equal",
"(",
"other",
"Value",
")",
"bool",
"{",
"switch",
"other",
":=",
"other",
".",
"(",
"type",
")",
"{",
"case",
"Boolean",
":",
"return",
"bol",
"==",
"other",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // Equal returns true if the other Value is a Boolean and is equal. | [
"Equal",
"returns",
"true",
"if",
"the",
"other",
"Value",
"is",
"a",
"Boolean",
"and",
"is",
"equal",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L551-L558 | train |
open-policy-agent/opa | ast/term.go | IntNumberTerm | func IntNumberTerm(i int) *Term {
return &Term{Value: Number(strconv.Itoa(i))}
} | go | func IntNumberTerm(i int) *Term {
return &Term{Value: Number(strconv.Itoa(i))}
} | [
"func",
"IntNumberTerm",
"(",
"i",
"int",
")",
"*",
"Term",
"{",
"return",
"&",
"Term",
"{",
"Value",
":",
"Number",
"(",
"strconv",
".",
"Itoa",
"(",
"i",
")",
")",
"}",
"\n",
"}"
] | // IntNumberTerm creates a new Term with an integer Number value. | [
"IntNumberTerm",
"creates",
"a",
"new",
"Term",
"with",
"an",
"integer",
"Number",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L600-L602 | train |
open-policy-agent/opa | ast/term.go | FloatNumberTerm | func FloatNumberTerm(f float64) *Term {
s := strconv.FormatFloat(f, 'g', -1, 64)
return &Term{Value: Number(s)}
} | go | func FloatNumberTerm(f float64) *Term {
s := strconv.FormatFloat(f, 'g', -1, 64)
return &Term{Value: Number(s)}
} | [
"func",
"FloatNumberTerm",
"(",
"f",
"float64",
")",
"*",
"Term",
"{",
"s",
":=",
"strconv",
".",
"FormatFloat",
"(",
"f",
",",
"'g'",
",",
"-",
"1",
",",
"64",
")",
"\n",
"return",
"&",
"Term",
"{",
"Value",
":",
"Number",
"(",
"s",
")",
"}",
"\n",
"}"
] | // FloatNumberTerm creates a new Term with a floating point Number value. | [
"FloatNumberTerm",
"creates",
"a",
"new",
"Term",
"with",
"a",
"floating",
"point",
"Number",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L605-L608 | train |
open-policy-agent/opa | ast/term.go | Equal | func (num Number) Equal(other Value) bool {
switch other := other.(type) {
case Number:
return Compare(num, other) == 0
default:
return false
}
} | go | func (num Number) Equal(other Value) bool {
switch other := other.(type) {
case Number:
return Compare(num, other) == 0
default:
return false
}
} | [
"func",
"(",
"num",
"Number",
")",
"Equal",
"(",
"other",
"Value",
")",
"bool",
"{",
"switch",
"other",
":=",
"other",
".",
"(",
"type",
")",
"{",
"case",
"Number",
":",
"return",
"Compare",
"(",
"num",
",",
"other",
")",
"==",
"0",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // Equal returns true if the other Value is a Number and is equal. | [
"Equal",
"returns",
"true",
"if",
"the",
"other",
"Value",
"is",
"a",
"Number",
"and",
"is",
"equal",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L611-L618 | train |
open-policy-agent/opa | ast/term.go | Int | func (num Number) Int() (int, bool) {
i, err := json.Number(num).Int64()
if err != nil {
return 0, false
}
return int(i), true
} | go | func (num Number) Int() (int, bool) {
i, err := json.Number(num).Int64()
if err != nil {
return 0, false
}
return int(i), true
} | [
"func",
"(",
"num",
"Number",
")",
"Int",
"(",
")",
"(",
"int",
",",
"bool",
")",
"{",
"i",
",",
"err",
":=",
"json",
".",
"Number",
"(",
"num",
")",
".",
"Int64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"return",
"int",
"(",
"i",
")",
",",
"true",
"\n",
"}"
] | // Int returns the int representation of num if possible. | [
"Int",
"returns",
"the",
"int",
"representation",
"of",
"num",
"if",
"possible",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L646-L652 | train |
open-policy-agent/opa | ast/term.go | Float64 | func (num Number) Float64() (float64, bool) {
f, err := json.Number(num).Float64()
if err != nil {
return 0, false
}
return f, true
} | go | func (num Number) Float64() (float64, bool) {
f, err := json.Number(num).Float64()
if err != nil {
return 0, false
}
return f, true
} | [
"func",
"(",
"num",
"Number",
")",
"Float64",
"(",
")",
"(",
"float64",
",",
"bool",
")",
"{",
"f",
",",
"err",
":=",
"json",
".",
"Number",
"(",
"num",
")",
".",
"Float64",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"return",
"f",
",",
"true",
"\n",
"}"
] | // Float64 returns the float64 representation of num if possible. | [
"Float64",
"returns",
"the",
"float64",
"representation",
"of",
"num",
"if",
"possible",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L655-L661 | train |
open-policy-agent/opa | ast/term.go | MarshalJSON | func (num Number) MarshalJSON() ([]byte, error) {
return json.Marshal(json.Number(num))
} | go | func (num Number) MarshalJSON() ([]byte, error) {
return json.Marshal(json.Number(num))
} | [
"func",
"(",
"num",
"Number",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"json",
".",
"Marshal",
"(",
"json",
".",
"Number",
"(",
"num",
")",
")",
"\n",
"}"
] | // MarshalJSON returns JSON encoded bytes representing num. | [
"MarshalJSON",
"returns",
"JSON",
"encoded",
"bytes",
"representing",
"num",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L669-L671 | train |
open-policy-agent/opa | ast/term.go | Equal | func (str String) Equal(other Value) bool {
switch other := other.(type) {
case String:
return str == other
default:
return false
}
} | go | func (str String) Equal(other Value) bool {
switch other := other.(type) {
case String:
return str == other
default:
return false
}
} | [
"func",
"(",
"str",
"String",
")",
"Equal",
"(",
"other",
"Value",
")",
"bool",
"{",
"switch",
"other",
":=",
"other",
".",
"(",
"type",
")",
"{",
"case",
"String",
":",
"return",
"str",
"==",
"other",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // Equal returns true if the other Value is a String and is equal. | [
"Equal",
"returns",
"true",
"if",
"the",
"other",
"Value",
"is",
"a",
"String",
"and",
"is",
"equal",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L698-L705 | train |
open-policy-agent/opa | ast/term.go | PtrRef | func PtrRef(head *Term, s string) (Ref, error) {
s = strings.Trim(s, "/")
if s == "" {
return Ref{head}, nil
}
parts := strings.Split(s, "/")
ref := make(Ref, len(parts)+1)
ref[0] = head
for i := 0; i < len(parts); i++ {
var err error
parts[i], err = url.PathUnescape(parts[i])
if err != nil {
return nil, err
}
ref[i+1] = StringTerm(parts[i])
}
return ref, nil
} | go | func PtrRef(head *Term, s string) (Ref, error) {
s = strings.Trim(s, "/")
if s == "" {
return Ref{head}, nil
}
parts := strings.Split(s, "/")
ref := make(Ref, len(parts)+1)
ref[0] = head
for i := 0; i < len(parts); i++ {
var err error
parts[i], err = url.PathUnescape(parts[i])
if err != nil {
return nil, err
}
ref[i+1] = StringTerm(parts[i])
}
return ref, nil
} | [
"func",
"PtrRef",
"(",
"head",
"*",
"Term",
",",
"s",
"string",
")",
"(",
"Ref",
",",
"error",
")",
"{",
"s",
"=",
"strings",
".",
"Trim",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"Ref",
"{",
"head",
"}",
",",
"nil",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"ref",
":=",
"make",
"(",
"Ref",
",",
"len",
"(",
"parts",
")",
"+",
"1",
")",
"\n",
"ref",
"[",
"0",
"]",
"=",
"head",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"parts",
")",
";",
"i",
"++",
"{",
"var",
"err",
"error",
"\n",
"parts",
"[",
"i",
"]",
",",
"err",
"=",
"url",
".",
"PathUnescape",
"(",
"parts",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ref",
"[",
"i",
"+",
"1",
"]",
"=",
"StringTerm",
"(",
"parts",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"ref",
",",
"nil",
"\n",
"}"
] | // PtrRef returns a new reference against the head for the pointer
// s. Path components in the pointer are unescaped. | [
"PtrRef",
"returns",
"a",
"new",
"reference",
"against",
"the",
"head",
"for",
"the",
"pointer",
"s",
".",
"Path",
"components",
"in",
"the",
"pointer",
"are",
"unescaped",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L811-L828 | train |
open-policy-agent/opa | ast/term.go | Append | func (ref Ref) Append(term *Term) Ref {
n := len(ref)
dst := make(Ref, n+1)
copy(dst, ref)
dst[n] = term
return dst
} | go | func (ref Ref) Append(term *Term) Ref {
n := len(ref)
dst := make(Ref, n+1)
copy(dst, ref)
dst[n] = term
return dst
} | [
"func",
"(",
"ref",
"Ref",
")",
"Append",
"(",
"term",
"*",
"Term",
")",
"Ref",
"{",
"n",
":=",
"len",
"(",
"ref",
")",
"\n",
"dst",
":=",
"make",
"(",
"Ref",
",",
"n",
"+",
"1",
")",
"\n",
"copy",
"(",
"dst",
",",
"ref",
")",
"\n",
"dst",
"[",
"n",
"]",
"=",
"term",
"\n",
"return",
"dst",
"\n",
"}"
] | // Append returns a copy of ref with the term appended to the end. | [
"Append",
"returns",
"a",
"copy",
"of",
"ref",
"with",
"the",
"term",
"appended",
"to",
"the",
"end",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L836-L842 | train |
open-policy-agent/opa | ast/term.go | Extend | func (ref Ref) Extend(other Ref) Ref {
dst := make(Ref, len(ref)+len(other))
for i := range ref {
dst[i] = ref[i]
}
head := other[0].Copy()
head.Value = String(head.Value.(Var))
offset := len(ref)
dst[offset] = head
for i := range other[1:] {
dst[offset+i+1] = other[i+1]
}
return dst
} | go | func (ref Ref) Extend(other Ref) Ref {
dst := make(Ref, len(ref)+len(other))
for i := range ref {
dst[i] = ref[i]
}
head := other[0].Copy()
head.Value = String(head.Value.(Var))
offset := len(ref)
dst[offset] = head
for i := range other[1:] {
dst[offset+i+1] = other[i+1]
}
return dst
} | [
"func",
"(",
"ref",
"Ref",
")",
"Extend",
"(",
"other",
"Ref",
")",
"Ref",
"{",
"dst",
":=",
"make",
"(",
"Ref",
",",
"len",
"(",
"ref",
")",
"+",
"len",
"(",
"other",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ref",
"{",
"dst",
"[",
"i",
"]",
"=",
"ref",
"[",
"i",
"]",
"\n",
"}",
"\n",
"head",
":=",
"other",
"[",
"0",
"]",
".",
"Copy",
"(",
")",
"\n",
"head",
".",
"Value",
"=",
"String",
"(",
"head",
".",
"Value",
".",
"(",
"Var",
")",
")",
"\n",
"offset",
":=",
"len",
"(",
"ref",
")",
"\n",
"dst",
"[",
"offset",
"]",
"=",
"head",
"\n",
"for",
"i",
":=",
"range",
"other",
"[",
"1",
":",
"]",
"{",
"dst",
"[",
"offset",
"+",
"i",
"+",
"1",
"]",
"=",
"other",
"[",
"i",
"+",
"1",
"]",
"\n",
"}",
"\n",
"return",
"dst",
"\n",
"}"
] | // Extend returns a copy of ref with the terms from other appended. The head of
// other will be converted to a string. | [
"Extend",
"returns",
"a",
"copy",
"of",
"ref",
"with",
"the",
"terms",
"from",
"other",
"appended",
".",
"The",
"head",
"of",
"other",
"will",
"be",
"converted",
"to",
"a",
"string",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L866-L879 | train |
open-policy-agent/opa | ast/term.go | Concat | func (ref Ref) Concat(terms []*Term) Ref {
if len(terms) == 0 {
return ref
}
cpy := make(Ref, len(ref)+len(terms))
for i := range ref {
cpy[i] = ref[i]
}
for i := range terms {
cpy[len(ref)+i] = terms[i]
}
return cpy
} | go | func (ref Ref) Concat(terms []*Term) Ref {
if len(terms) == 0 {
return ref
}
cpy := make(Ref, len(ref)+len(terms))
for i := range ref {
cpy[i] = ref[i]
}
for i := range terms {
cpy[len(ref)+i] = terms[i]
}
return cpy
} | [
"func",
"(",
"ref",
"Ref",
")",
"Concat",
"(",
"terms",
"[",
"]",
"*",
"Term",
")",
"Ref",
"{",
"if",
"len",
"(",
"terms",
")",
"==",
"0",
"{",
"return",
"ref",
"\n",
"}",
"\n",
"cpy",
":=",
"make",
"(",
"Ref",
",",
"len",
"(",
"ref",
")",
"+",
"len",
"(",
"terms",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ref",
"{",
"cpy",
"[",
"i",
"]",
"=",
"ref",
"[",
"i",
"]",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"terms",
"{",
"cpy",
"[",
"len",
"(",
"ref",
")",
"+",
"i",
"]",
"=",
"terms",
"[",
"i",
"]",
"\n",
"}",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Concat returns a ref with the terms appended. | [
"Concat",
"returns",
"a",
"ref",
"with",
"the",
"terms",
"appended",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L882-L894 | train |
open-policy-agent/opa | ast/term.go | Dynamic | func (ref Ref) Dynamic() int {
for i := 1; i < len(ref); i++ {
if !IsConstant(ref[i].Value) {
return i
}
}
return -1
} | go | func (ref Ref) Dynamic() int {
for i := 1; i < len(ref); i++ {
if !IsConstant(ref[i].Value) {
return i
}
}
return -1
} | [
"func",
"(",
"ref",
"Ref",
")",
"Dynamic",
"(",
")",
"int",
"{",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"len",
"(",
"ref",
")",
";",
"i",
"++",
"{",
"if",
"!",
"IsConstant",
"(",
"ref",
"[",
"i",
"]",
".",
"Value",
")",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] | // Dynamic returns the offset of the first non-constant operand of ref. | [
"Dynamic",
"returns",
"the",
"offset",
"of",
"the",
"first",
"non",
"-",
"constant",
"operand",
"of",
"ref",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L897-L904 | train |
open-policy-agent/opa | ast/term.go | HasPrefix | func (ref Ref) HasPrefix(other Ref) bool {
if len(other) > len(ref) {
return false
}
for i := range other {
if !ref[i].Equal(other[i]) {
return false
}
}
return true
} | go | func (ref Ref) HasPrefix(other Ref) bool {
if len(other) > len(ref) {
return false
}
for i := range other {
if !ref[i].Equal(other[i]) {
return false
}
}
return true
} | [
"func",
"(",
"ref",
"Ref",
")",
"HasPrefix",
"(",
"other",
"Ref",
")",
"bool",
"{",
"if",
"len",
"(",
"other",
")",
">",
"len",
"(",
"ref",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"other",
"{",
"if",
"!",
"ref",
"[",
"i",
"]",
".",
"Equal",
"(",
"other",
"[",
"i",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // HasPrefix returns true if the other ref is a prefix of this ref. | [
"HasPrefix",
"returns",
"true",
"if",
"the",
"other",
"ref",
"is",
"a",
"prefix",
"of",
"this",
"ref",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L936-L946 | train |
open-policy-agent/opa | ast/term.go | ConstantPrefix | func (ref Ref) ConstantPrefix() Ref {
ref = ref.Copy()
i := ref.Dynamic()
if i < 0 {
return ref
}
return ref[:i]
} | go | func (ref Ref) ConstantPrefix() Ref {
ref = ref.Copy()
i := ref.Dynamic()
if i < 0 {
return ref
}
return ref[:i]
} | [
"func",
"(",
"ref",
"Ref",
")",
"ConstantPrefix",
"(",
")",
"Ref",
"{",
"ref",
"=",
"ref",
".",
"Copy",
"(",
")",
"\n\n",
"i",
":=",
"ref",
".",
"Dynamic",
"(",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"ref",
"\n",
"}",
"\n",
"return",
"ref",
"[",
":",
"i",
"]",
"\n",
"}"
] | // ConstantPrefix returns the constant portion of the ref starting from the head. | [
"ConstantPrefix",
"returns",
"the",
"constant",
"portion",
"of",
"the",
"ref",
"starting",
"from",
"the",
"head",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L949-L957 | train |
open-policy-agent/opa | ast/term.go | GroundPrefix | func (ref Ref) GroundPrefix() Ref {
prefix := make(Ref, 0, len(ref))
for i, x := range ref {
if i > 0 && !x.IsGround() {
break
}
prefix = append(prefix, x)
}
return prefix
} | go | func (ref Ref) GroundPrefix() Ref {
prefix := make(Ref, 0, len(ref))
for i, x := range ref {
if i > 0 && !x.IsGround() {
break
}
prefix = append(prefix, x)
}
return prefix
} | [
"func",
"(",
"ref",
"Ref",
")",
"GroundPrefix",
"(",
")",
"Ref",
"{",
"prefix",
":=",
"make",
"(",
"Ref",
",",
"0",
",",
"len",
"(",
"ref",
")",
")",
"\n\n",
"for",
"i",
",",
"x",
":=",
"range",
"ref",
"{",
"if",
"i",
">",
"0",
"&&",
"!",
"x",
".",
"IsGround",
"(",
")",
"{",
"break",
"\n",
"}",
"\n",
"prefix",
"=",
"append",
"(",
"prefix",
",",
"x",
")",
"\n",
"}",
"\n\n",
"return",
"prefix",
"\n",
"}"
] | // GroundPrefix returns the ground portion of the ref starting from the head. By
// definition, the head of the reference is always ground. | [
"GroundPrefix",
"returns",
"the",
"ground",
"portion",
"of",
"the",
"ref",
"starting",
"from",
"the",
"head",
".",
"By",
"definition",
"the",
"head",
"of",
"the",
"reference",
"is",
"always",
"ground",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L961-L972 | train |
open-policy-agent/opa | ast/term.go | IsNested | func (ref Ref) IsNested() bool {
for _, x := range ref {
if _, ok := x.Value.(Ref); ok {
return true
}
}
return false
} | go | func (ref Ref) IsNested() bool {
for _, x := range ref {
if _, ok := x.Value.(Ref); ok {
return true
}
}
return false
} | [
"func",
"(",
"ref",
"Ref",
")",
"IsNested",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"x",
":=",
"range",
"ref",
"{",
"if",
"_",
",",
"ok",
":=",
"x",
".",
"Value",
".",
"(",
"Ref",
")",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsNested returns true if this ref contains other Refs. | [
"IsNested",
"returns",
"true",
"if",
"this",
"ref",
"contains",
"other",
"Refs",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L983-L990 | train |
open-policy-agent/opa | ast/term.go | Ptr | func (ref Ref) Ptr() (string, error) {
parts := make([]string, 0, len(ref)-1)
for _, term := range ref[1:] {
if str, ok := term.Value.(String); ok {
parts = append(parts, url.PathEscape(string(str)))
} else {
return "", fmt.Errorf("invalid path value type")
}
}
return strings.Join(parts, "/"), nil
} | go | func (ref Ref) Ptr() (string, error) {
parts := make([]string, 0, len(ref)-1)
for _, term := range ref[1:] {
if str, ok := term.Value.(String); ok {
parts = append(parts, url.PathEscape(string(str)))
} else {
return "", fmt.Errorf("invalid path value type")
}
}
return strings.Join(parts, "/"), nil
} | [
"func",
"(",
"ref",
"Ref",
")",
"Ptr",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"parts",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"ref",
")",
"-",
"1",
")",
"\n",
"for",
"_",
",",
"term",
":=",
"range",
"ref",
"[",
"1",
":",
"]",
"{",
"if",
"str",
",",
"ok",
":=",
"term",
".",
"Value",
".",
"(",
"String",
")",
";",
"ok",
"{",
"parts",
"=",
"append",
"(",
"parts",
",",
"url",
".",
"PathEscape",
"(",
"string",
"(",
"str",
")",
")",
")",
"\n",
"}",
"else",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}"
] | // Ptr returns a slash-separated path string for this ref. If the ref
// contains non-string terms this function returns an error. Path
// components are escaped. | [
"Ptr",
"returns",
"a",
"slash",
"-",
"separated",
"path",
"string",
"for",
"this",
"ref",
".",
"If",
"the",
"ref",
"contains",
"non",
"-",
"string",
"terms",
"this",
"function",
"returns",
"an",
"error",
".",
"Path",
"components",
"are",
"escaped",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L995-L1005 | train |
open-policy-agent/opa | ast/term.go | OutputVars | func (ref Ref) OutputVars() VarSet {
vis := NewVarVisitor().WithParams(VarVisitorParams{SkipRefHead: true})
Walk(vis, ref)
return vis.Vars()
} | go | func (ref Ref) OutputVars() VarSet {
vis := NewVarVisitor().WithParams(VarVisitorParams{SkipRefHead: true})
Walk(vis, ref)
return vis.Vars()
} | [
"func",
"(",
"ref",
"Ref",
")",
"OutputVars",
"(",
")",
"VarSet",
"{",
"vis",
":=",
"NewVarVisitor",
"(",
")",
".",
"WithParams",
"(",
"VarVisitorParams",
"{",
"SkipRefHead",
":",
"true",
"}",
")",
"\n",
"Walk",
"(",
"vis",
",",
"ref",
")",
"\n",
"return",
"vis",
".",
"Vars",
"(",
")",
"\n",
"}"
] | // OutputVars returns a VarSet containing variables that would be bound by evaluating
// this expression in isolation. | [
"OutputVars",
"returns",
"a",
"VarSet",
"containing",
"variables",
"that",
"would",
"be",
"bound",
"by",
"evaluating",
"this",
"expression",
"in",
"isolation",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1038-L1042 | train |
open-policy-agent/opa | ast/term.go | Find | func (arr Array) Find(path Ref) (Value, error) {
if len(path) == 0 {
return arr, nil
}
num, ok := path[0].Value.(Number)
if !ok {
return nil, fmt.Errorf("find: not found")
}
i, ok := num.Int()
if !ok {
return nil, fmt.Errorf("find: not found")
}
if i < 0 || i >= len(arr) {
return nil, fmt.Errorf("find: not found")
}
return arr[i].Value.Find(path[1:])
} | go | func (arr Array) Find(path Ref) (Value, error) {
if len(path) == 0 {
return arr, nil
}
num, ok := path[0].Value.(Number)
if !ok {
return nil, fmt.Errorf("find: not found")
}
i, ok := num.Int()
if !ok {
return nil, fmt.Errorf("find: not found")
}
if i < 0 || i >= len(arr) {
return nil, fmt.Errorf("find: not found")
}
return arr[i].Value.Find(path[1:])
} | [
"func",
"(",
"arr",
"Array",
")",
"Find",
"(",
"path",
"Ref",
")",
"(",
"Value",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"arr",
",",
"nil",
"\n",
"}",
"\n",
"num",
",",
"ok",
":=",
"path",
"[",
"0",
"]",
".",
"Value",
".",
"(",
"Number",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"i",
",",
"ok",
":=",
"num",
".",
"Int",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">=",
"len",
"(",
"arr",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"arr",
"[",
"i",
"]",
".",
"Value",
".",
"Find",
"(",
"path",
"[",
"1",
":",
"]",
")",
"\n",
"}"
] | // Find returns the value at the index or an out-of-range error. | [
"Find",
"returns",
"the",
"value",
"at",
"the",
"index",
"or",
"an",
"out",
"-",
"of",
"-",
"range",
"error",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1074-L1090 | train |
open-policy-agent/opa | ast/term.go | Get | func (arr Array) Get(pos *Term) *Term {
num, ok := pos.Value.(Number)
if !ok {
return nil
}
i, ok := num.Int()
if !ok {
return nil
}
if i >= 0 && i < len(arr) {
return arr[i]
}
return nil
} | go | func (arr Array) Get(pos *Term) *Term {
num, ok := pos.Value.(Number)
if !ok {
return nil
}
i, ok := num.Int()
if !ok {
return nil
}
if i >= 0 && i < len(arr) {
return arr[i]
}
return nil
} | [
"func",
"(",
"arr",
"Array",
")",
"Get",
"(",
"pos",
"*",
"Term",
")",
"*",
"Term",
"{",
"num",
",",
"ok",
":=",
"pos",
".",
"Value",
".",
"(",
"Number",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"i",
",",
"ok",
":=",
"num",
".",
"Int",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"i",
">=",
"0",
"&&",
"i",
"<",
"len",
"(",
"arr",
")",
"{",
"return",
"arr",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Get returns the element at pos or nil if not possible. | [
"Get",
"returns",
"the",
"element",
"at",
"pos",
"or",
"nil",
"if",
"not",
"possible",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1093-L1109 | train |
open-policy-agent/opa | ast/term.go | Sorted | func (arr Array) Sorted() Array {
cpy := make(Array, len(arr))
for i := range cpy {
cpy[i] = arr[i]
}
sort.Sort(termSlice(cpy))
return cpy
} | go | func (arr Array) Sorted() Array {
cpy := make(Array, len(arr))
for i := range cpy {
cpy[i] = arr[i]
}
sort.Sort(termSlice(cpy))
return cpy
} | [
"func",
"(",
"arr",
"Array",
")",
"Sorted",
"(",
")",
"Array",
"{",
"cpy",
":=",
"make",
"(",
"Array",
",",
"len",
"(",
"arr",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"cpy",
"{",
"cpy",
"[",
"i",
"]",
"=",
"arr",
"[",
"i",
"]",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"termSlice",
"(",
"cpy",
")",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Sorted returns a new Array that contains the sorted elements of arr. | [
"Sorted",
"returns",
"a",
"new",
"Array",
"that",
"contains",
"the",
"sorted",
"elements",
"of",
"arr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1112-L1119 | train |
open-policy-agent/opa | ast/term.go | MarshalJSON | func (arr Array) MarshalJSON() ([]byte, error) {
if len(arr) == 0 {
return json.Marshal([]interface{}{})
}
return json.Marshal([]*Term(arr))
} | go | func (arr Array) MarshalJSON() ([]byte, error) {
if len(arr) == 0 {
return json.Marshal([]interface{}{})
}
return json.Marshal([]*Term(arr))
} | [
"func",
"(",
"arr",
"Array",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"arr",
")",
"==",
"0",
"{",
"return",
"json",
".",
"Marshal",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"[",
"]",
"*",
"Term",
"(",
"arr",
")",
")",
"\n",
"}"
] | // MarshalJSON returns JSON encoded bytes representing arr. | [
"MarshalJSON",
"returns",
"JSON",
"encoded",
"bytes",
"representing",
"arr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1132-L1137 | train |
open-policy-agent/opa | ast/term.go | NewSet | func NewSet(t ...*Term) Set {
s := newset(len(t))
for i := range t {
s.Add(t[i])
}
return s
} | go | func NewSet(t ...*Term) Set {
s := newset(len(t))
for i := range t {
s.Add(t[i])
}
return s
} | [
"func",
"NewSet",
"(",
"t",
"...",
"*",
"Term",
")",
"Set",
"{",
"s",
":=",
"newset",
"(",
"len",
"(",
"t",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"t",
"{",
"s",
".",
"Add",
"(",
"t",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewSet returns a new Set containing t. | [
"NewSet",
"returns",
"a",
"new",
"Set",
"containing",
"t",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1166-L1172 | train |
open-policy-agent/opa | ast/term.go | SetTerm | func SetTerm(t ...*Term) *Term {
set := NewSet(t...)
return &Term{
Value: set,
}
} | go | func SetTerm(t ...*Term) *Term {
set := NewSet(t...)
return &Term{
Value: set,
}
} | [
"func",
"SetTerm",
"(",
"t",
"...",
"*",
"Term",
")",
"*",
"Term",
"{",
"set",
":=",
"NewSet",
"(",
"t",
"...",
")",
"\n",
"return",
"&",
"Term",
"{",
"Value",
":",
"set",
",",
"}",
"\n",
"}"
] | // SetTerm returns a new Term representing a set containing terms t. | [
"SetTerm",
"returns",
"a",
"new",
"Term",
"representing",
"a",
"set",
"containing",
"terms",
"t",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1186-L1191 | train |
open-policy-agent/opa | ast/term.go | Copy | func (s *set) Copy() Set {
cpy := NewSet()
s.Foreach(func(x *Term) {
cpy.Add(x)
})
return cpy
} | go | func (s *set) Copy() Set {
cpy := NewSet()
s.Foreach(func(x *Term) {
cpy.Add(x)
})
return cpy
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Copy",
"(",
")",
"Set",
"{",
"cpy",
":=",
"NewSet",
"(",
")",
"\n",
"s",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"cpy",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of s. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1199-L1205 | train |
open-policy-agent/opa | ast/term.go | IsGround | func (s *set) IsGround() bool {
return !s.Until(func(x *Term) bool {
return !x.IsGround()
})
} | go | func (s *set) IsGround() bool {
return !s.Until(func(x *Term) bool {
return !x.IsGround()
})
} | [
"func",
"(",
"s",
"*",
"set",
")",
"IsGround",
"(",
")",
"bool",
"{",
"return",
"!",
"s",
".",
"Until",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"bool",
"{",
"return",
"!",
"x",
".",
"IsGround",
"(",
")",
"\n",
"}",
")",
"\n",
"}"
] | // IsGround returns true if all terms in s are ground. | [
"IsGround",
"returns",
"true",
"if",
"all",
"terms",
"in",
"s",
"are",
"ground",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1208-L1212 | train |
open-policy-agent/opa | ast/term.go | Hash | func (s *set) Hash() int {
var hash int
s.Foreach(func(x *Term) {
hash += x.Hash()
})
return hash
} | go | func (s *set) Hash() int {
var hash int
s.Foreach(func(x *Term) {
hash += x.Hash()
})
return hash
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Hash",
"(",
")",
"int",
"{",
"var",
"hash",
"int",
"\n",
"s",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"hash",
"+=",
"x",
".",
"Hash",
"(",
")",
"\n",
"}",
")",
"\n",
"return",
"hash",
"\n",
"}"
] | // Hash returns a hash code for s. | [
"Hash",
"returns",
"a",
"hash",
"code",
"for",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1215-L1221 | train |
open-policy-agent/opa | ast/term.go | Find | func (s *set) Find(path Ref) (Value, error) {
if len(path) == 0 {
return s, nil
}
if !s.Contains(path[0]) {
return nil, fmt.Errorf("find: not found")
}
return path[0].Value.Find(path[1:])
} | go | func (s *set) Find(path Ref) (Value, error) {
if len(path) == 0 {
return s, nil
}
if !s.Contains(path[0]) {
return nil, fmt.Errorf("find: not found")
}
return path[0].Value.Find(path[1:])
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Find",
"(",
"path",
"Ref",
")",
"(",
"Value",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"s",
".",
"Contains",
"(",
"path",
"[",
"0",
"]",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"path",
"[",
"0",
"]",
".",
"Value",
".",
"Find",
"(",
"path",
"[",
"1",
":",
"]",
")",
"\n",
"}"
] | // Find returns the set or dereferences the element itself. | [
"Find",
"returns",
"the",
"set",
"or",
"dereferences",
"the",
"element",
"itself",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1251-L1259 | train |
open-policy-agent/opa | ast/term.go | Diff | func (s *set) Diff(other Set) Set {
r := NewSet()
s.Foreach(func(x *Term) {
if !other.Contains(x) {
r.Add(x)
}
})
return r
} | go | func (s *set) Diff(other Set) Set {
r := NewSet()
s.Foreach(func(x *Term) {
if !other.Contains(x) {
r.Add(x)
}
})
return r
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Diff",
"(",
"other",
"Set",
")",
"Set",
"{",
"r",
":=",
"NewSet",
"(",
")",
"\n",
"s",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"if",
"!",
"other",
".",
"Contains",
"(",
"x",
")",
"{",
"r",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Diff returns elements in s that are not in other. | [
"Diff",
"returns",
"elements",
"in",
"s",
"that",
"are",
"not",
"in",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1262-L1270 | train |
open-policy-agent/opa | ast/term.go | Intersect | func (s *set) Intersect(other Set) Set {
o := other.(*set)
n, m := s.Len(), o.Len()
ss := s
so := o
if m < n {
ss = o
so = s
n = m
}
r := newset(n)
ss.Foreach(func(x *Term) {
if so.Contains(x) {
r.Add(x)
}
})
return r
} | go | func (s *set) Intersect(other Set) Set {
o := other.(*set)
n, m := s.Len(), o.Len()
ss := s
so := o
if m < n {
ss = o
so = s
n = m
}
r := newset(n)
ss.Foreach(func(x *Term) {
if so.Contains(x) {
r.Add(x)
}
})
return r
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Intersect",
"(",
"other",
"Set",
")",
"Set",
"{",
"o",
":=",
"other",
".",
"(",
"*",
"set",
")",
"\n",
"n",
",",
"m",
":=",
"s",
".",
"Len",
"(",
")",
",",
"o",
".",
"Len",
"(",
")",
"\n",
"ss",
":=",
"s",
"\n",
"so",
":=",
"o",
"\n",
"if",
"m",
"<",
"n",
"{",
"ss",
"=",
"o",
"\n",
"so",
"=",
"s",
"\n",
"n",
"=",
"m",
"\n",
"}",
"\n\n",
"r",
":=",
"newset",
"(",
"n",
")",
"\n",
"ss",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"if",
"so",
".",
"Contains",
"(",
"x",
")",
"{",
"r",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Intersect returns the set containing elements in both s and other. | [
"Intersect",
"returns",
"the",
"set",
"containing",
"elements",
"in",
"both",
"s",
"and",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1273-L1291 | train |
open-policy-agent/opa | ast/term.go | Union | func (s *set) Union(other Set) Set {
r := NewSet()
s.Foreach(func(x *Term) {
r.Add(x)
})
other.Foreach(func(x *Term) {
r.Add(x)
})
return r
} | go | func (s *set) Union(other Set) Set {
r := NewSet()
s.Foreach(func(x *Term) {
r.Add(x)
})
other.Foreach(func(x *Term) {
r.Add(x)
})
return r
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Union",
"(",
"other",
"Set",
")",
"Set",
"{",
"r",
":=",
"NewSet",
"(",
")",
"\n",
"s",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"r",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
")",
"\n",
"other",
".",
"Foreach",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"{",
"r",
".",
"Add",
"(",
"x",
")",
"\n",
"}",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Union returns the set containing all elements of s and other. | [
"Union",
"returns",
"the",
"set",
"containing",
"all",
"elements",
"of",
"s",
"and",
"other",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1294-L1303 | train |
open-policy-agent/opa | ast/term.go | Iter | func (s *set) Iter(f func(*Term) error) error {
for i := range s.keys {
if err := f(s.keys[i]); err != nil {
return err
}
}
return nil
} | go | func (s *set) Iter(f func(*Term) error) error {
for i := range s.keys {
if err := f(s.keys[i]); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Iter",
"(",
"f",
"func",
"(",
"*",
"Term",
")",
"error",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"s",
".",
"keys",
"{",
"if",
"err",
":=",
"f",
"(",
"s",
".",
"keys",
"[",
"i",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Iter calls f on each element in s. If f returns an error, iteration stops
// and the return value is the error. | [
"Iter",
"calls",
"f",
"on",
"each",
"element",
"in",
"s",
".",
"If",
"f",
"returns",
"an",
"error",
"iteration",
"stops",
"and",
"the",
"return",
"value",
"is",
"the",
"error",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1312-L1319 | train |
open-policy-agent/opa | ast/term.go | Until | func (s *set) Until(f func(*Term) bool) bool {
err := s.Iter(func(t *Term) error {
if f(t) {
return errStop
}
return nil
})
return err != nil
} | go | func (s *set) Until(f func(*Term) bool) bool {
err := s.Iter(func(t *Term) error {
if f(t) {
return errStop
}
return nil
})
return err != nil
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Until",
"(",
"f",
"func",
"(",
"*",
"Term",
")",
"bool",
")",
"bool",
"{",
"err",
":=",
"s",
".",
"Iter",
"(",
"func",
"(",
"t",
"*",
"Term",
")",
"error",
"{",
"if",
"f",
"(",
"t",
")",
"{",
"return",
"errStop",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"err",
"!=",
"nil",
"\n",
"}"
] | // Until calls f on each element in s. If f returns true, iteration stops. | [
"Until",
"calls",
"f",
"on",
"each",
"element",
"in",
"s",
".",
"If",
"f",
"returns",
"true",
"iteration",
"stops",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1324-L1332 | train |
open-policy-agent/opa | ast/term.go | Foreach | func (s *set) Foreach(f func(*Term)) {
s.Iter(func(t *Term) error {
f(t)
return nil
})
} | go | func (s *set) Foreach(f func(*Term)) {
s.Iter(func(t *Term) error {
f(t)
return nil
})
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Foreach",
"(",
"f",
"func",
"(",
"*",
"Term",
")",
")",
"{",
"s",
".",
"Iter",
"(",
"func",
"(",
"t",
"*",
"Term",
")",
"error",
"{",
"f",
"(",
"t",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // Foreach calls f on each element in s. | [
"Foreach",
"calls",
"f",
"on",
"each",
"element",
"in",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1335-L1340 | train |
open-policy-agent/opa | ast/term.go | Map | func (s *set) Map(f func(*Term) (*Term, error)) (Set, error) {
set := NewSet()
err := s.Iter(func(x *Term) error {
term, err := f(x)
if err != nil {
return err
}
set.Add(term)
return nil
})
if err != nil {
return nil, err
}
return set, nil
} | go | func (s *set) Map(f func(*Term) (*Term, error)) (Set, error) {
set := NewSet()
err := s.Iter(func(x *Term) error {
term, err := f(x)
if err != nil {
return err
}
set.Add(term)
return nil
})
if err != nil {
return nil, err
}
return set, nil
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Map",
"(",
"f",
"func",
"(",
"*",
"Term",
")",
"(",
"*",
"Term",
",",
"error",
")",
")",
"(",
"Set",
",",
"error",
")",
"{",
"set",
":=",
"NewSet",
"(",
")",
"\n",
"err",
":=",
"s",
".",
"Iter",
"(",
"func",
"(",
"x",
"*",
"Term",
")",
"error",
"{",
"term",
",",
"err",
":=",
"f",
"(",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"set",
".",
"Add",
"(",
"term",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"set",
",",
"nil",
"\n",
"}"
] | // Map returns a new Set obtained by applying f to each value in s. | [
"Map",
"returns",
"a",
"new",
"Set",
"obtained",
"by",
"applying",
"f",
"to",
"each",
"value",
"in",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1343-L1357 | train |
open-policy-agent/opa | ast/term.go | Contains | func (s *set) Contains(t *Term) bool {
return s.get(t) != nil
} | go | func (s *set) Contains(t *Term) bool {
return s.get(t) != nil
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Contains",
"(",
"t",
"*",
"Term",
")",
"bool",
"{",
"return",
"s",
".",
"get",
"(",
"t",
")",
"!=",
"nil",
"\n",
"}"
] | // Contains returns true if t is in s. | [
"Contains",
"returns",
"true",
"if",
"t",
"is",
"in",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1375-L1377 | train |
open-policy-agent/opa | ast/term.go | MarshalJSON | func (s *set) MarshalJSON() ([]byte, error) {
if s.keys == nil {
return json.Marshal([]interface{}{})
}
return json.Marshal(s.keys)
} | go | func (s *set) MarshalJSON() ([]byte, error) {
if s.keys == nil {
return json.Marshal([]interface{}{})
}
return json.Marshal(s.keys)
} | [
"func",
"(",
"s",
"*",
"set",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"s",
".",
"keys",
"==",
"nil",
"{",
"return",
"json",
".",
"Marshal",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"s",
".",
"keys",
")",
"\n",
"}"
] | // MarshalJSON returns JSON encoded bytes representing s. | [
"MarshalJSON",
"returns",
"JSON",
"encoded",
"bytes",
"representing",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1385-L1390 | train |
open-policy-agent/opa | ast/term.go | Sorted | func (s *set) Sorted() Array {
cpy := make(Array, len(s.keys))
for i := range cpy {
cpy[i] = s.keys[i]
}
sort.Sort(termSlice(cpy))
return cpy
} | go | func (s *set) Sorted() Array {
cpy := make(Array, len(s.keys))
for i := range cpy {
cpy[i] = s.keys[i]
}
sort.Sort(termSlice(cpy))
return cpy
} | [
"func",
"(",
"s",
"*",
"set",
")",
"Sorted",
"(",
")",
"Array",
"{",
"cpy",
":=",
"make",
"(",
"Array",
",",
"len",
"(",
"s",
".",
"keys",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"cpy",
"{",
"cpy",
"[",
"i",
"]",
"=",
"s",
".",
"keys",
"[",
"i",
"]",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"termSlice",
"(",
"cpy",
")",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Sorted returns an Array that contains the sorted elements of s. | [
"Sorted",
"returns",
"an",
"Array",
"that",
"contains",
"the",
"sorted",
"elements",
"of",
"s",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1393-L1400 | train |
open-policy-agent/opa | ast/term.go | NewObject | func NewObject(t ...[2]*Term) Object {
obj := newobject(len(t))
for i := range t {
obj.Insert(t[i][0], t[i][1])
}
return obj
} | go | func NewObject(t ...[2]*Term) Object {
obj := newobject(len(t))
for i := range t {
obj.Insert(t[i][0], t[i][1])
}
return obj
} | [
"func",
"NewObject",
"(",
"t",
"...",
"[",
"2",
"]",
"*",
"Term",
")",
"Object",
"{",
"obj",
":=",
"newobject",
"(",
"len",
"(",
"t",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"t",
"{",
"obj",
".",
"Insert",
"(",
"t",
"[",
"i",
"]",
"[",
"0",
"]",
",",
"t",
"[",
"i",
"]",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"return",
"obj",
"\n",
"}"
] | // NewObject creates a new Object with t. | [
"NewObject",
"creates",
"a",
"new",
"Object",
"with",
"t",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1448-L1454 | train |
open-policy-agent/opa | ast/term.go | Find | func (obj *object) Find(path Ref) (Value, error) {
if len(path) == 0 {
return obj, nil
}
value := obj.Get(path[0])
if value == nil {
return nil, fmt.Errorf("find: not found")
}
return value.Value.Find(path[1:])
} | go | func (obj *object) Find(path Ref) (Value, error) {
if len(path) == 0 {
return obj, nil
}
value := obj.Get(path[0])
if value == nil {
return nil, fmt.Errorf("find: not found")
}
return value.Value.Find(path[1:])
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Find",
"(",
"path",
"Ref",
")",
"(",
"Value",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"obj",
",",
"nil",
"\n",
"}",
"\n",
"value",
":=",
"obj",
".",
"Get",
"(",
"path",
"[",
"0",
"]",
")",
"\n",
"if",
"value",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"value",
".",
"Value",
".",
"Find",
"(",
"path",
"[",
"1",
":",
"]",
")",
"\n",
"}"
] | // Find returns the value at the key or undefined. | [
"Find",
"returns",
"the",
"value",
"at",
"the",
"key",
"or",
"undefined",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1536-L1545 | train |
open-policy-agent/opa | ast/term.go | Get | func (obj *object) Get(k *Term) *Term {
if elem := obj.get(k); elem != nil {
return elem.value
}
return nil
} | go | func (obj *object) Get(k *Term) *Term {
if elem := obj.get(k); elem != nil {
return elem.value
}
return nil
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Get",
"(",
"k",
"*",
"Term",
")",
"*",
"Term",
"{",
"if",
"elem",
":=",
"obj",
".",
"get",
"(",
"k",
")",
";",
"elem",
"!=",
"nil",
"{",
"return",
"elem",
".",
"value",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Get returns the value of k in obj if k exists, otherwise nil. | [
"Get",
"returns",
"the",
"value",
"of",
"k",
"in",
"obj",
"if",
"k",
"exists",
"otherwise",
"nil",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1552-L1557 | train |
open-policy-agent/opa | ast/term.go | Copy | func (obj *object) Copy() Object {
cpy, _ := obj.Map(func(k, v *Term) (*Term, *Term, error) {
return k.Copy(), v.Copy(), nil
})
return cpy
} | go | func (obj *object) Copy() Object {
cpy, _ := obj.Map(func(k, v *Term) (*Term, *Term, error) {
return k.Copy(), v.Copy(), nil
})
return cpy
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Copy",
"(",
")",
"Object",
"{",
"cpy",
",",
"_",
":=",
"obj",
".",
"Map",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"(",
"*",
"Term",
",",
"*",
"Term",
",",
"error",
")",
"{",
"return",
"k",
".",
"Copy",
"(",
")",
",",
"v",
".",
"Copy",
"(",
")",
",",
"nil",
"\n",
"}",
")",
"\n",
"return",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of obj. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"obj",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1575-L1580 | train |
open-policy-agent/opa | ast/term.go | Iter | func (obj *object) Iter(f func(*Term, *Term) error) error {
for i := range obj.keys {
k := obj.keys[i]
node := obj.get(k)
if node == nil {
panic("corrupt object")
}
if err := f(k, node.value); err != nil {
return err
}
}
return nil
} | go | func (obj *object) Iter(f func(*Term, *Term) error) error {
for i := range obj.keys {
k := obj.keys[i]
node := obj.get(k)
if node == nil {
panic("corrupt object")
}
if err := f(k, node.value); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Iter",
"(",
"f",
"func",
"(",
"*",
"Term",
",",
"*",
"Term",
")",
"error",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"obj",
".",
"keys",
"{",
"k",
":=",
"obj",
".",
"keys",
"[",
"i",
"]",
"\n",
"node",
":=",
"obj",
".",
"get",
"(",
"k",
")",
"\n",
"if",
"node",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
"(",
"k",
",",
"node",
".",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Iter calls the function f for each key-value pair in the object. If f
// returns an error, iteration stops and the error is returned. | [
"Iter",
"calls",
"the",
"function",
"f",
"for",
"each",
"key",
"-",
"value",
"pair",
"in",
"the",
"object",
".",
"If",
"f",
"returns",
"an",
"error",
"iteration",
"stops",
"and",
"the",
"error",
"is",
"returned",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1608-L1620 | train |
open-policy-agent/opa | ast/term.go | Until | func (obj *object) Until(f func(*Term, *Term) bool) bool {
err := obj.Iter(func(k, v *Term) error {
if f(k, v) {
return errStop
}
return nil
})
return err != nil
} | go | func (obj *object) Until(f func(*Term, *Term) bool) bool {
err := obj.Iter(func(k, v *Term) error {
if f(k, v) {
return errStop
}
return nil
})
return err != nil
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Until",
"(",
"f",
"func",
"(",
"*",
"Term",
",",
"*",
"Term",
")",
"bool",
")",
"bool",
"{",
"err",
":=",
"obj",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"error",
"{",
"if",
"f",
"(",
"k",
",",
"v",
")",
"{",
"return",
"errStop",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"err",
"!=",
"nil",
"\n",
"}"
] | // Until calls f for each key-value pair in the object. If f returns true,
// iteration stops. | [
"Until",
"calls",
"f",
"for",
"each",
"key",
"-",
"value",
"pair",
"in",
"the",
"object",
".",
"If",
"f",
"returns",
"true",
"iteration",
"stops",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1624-L1632 | train |
open-policy-agent/opa | ast/term.go | Foreach | func (obj *object) Foreach(f func(*Term, *Term)) {
obj.Iter(func(k, v *Term) error {
f(k, v)
return nil
})
} | go | func (obj *object) Foreach(f func(*Term, *Term)) {
obj.Iter(func(k, v *Term) error {
f(k, v)
return nil
})
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Foreach",
"(",
"f",
"func",
"(",
"*",
"Term",
",",
"*",
"Term",
")",
")",
"{",
"obj",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"error",
"{",
"f",
"(",
"k",
",",
"v",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // Foreach calls f for each key-value pair in the object. | [
"Foreach",
"calls",
"f",
"for",
"each",
"key",
"-",
"value",
"pair",
"in",
"the",
"object",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1635-L1640 | train |
open-policy-agent/opa | ast/term.go | Map | func (obj *object) Map(f func(*Term, *Term) (*Term, *Term, error)) (Object, error) {
cpy := newobject(obj.Len())
err := obj.Iter(func(k, v *Term) error {
var err error
k, v, err = f(k, v)
if err != nil {
return err
}
cpy.insert(k, v)
return nil
})
if err != nil {
return nil, err
}
return cpy, nil
} | go | func (obj *object) Map(f func(*Term, *Term) (*Term, *Term, error)) (Object, error) {
cpy := newobject(obj.Len())
err := obj.Iter(func(k, v *Term) error {
var err error
k, v, err = f(k, v)
if err != nil {
return err
}
cpy.insert(k, v)
return nil
})
if err != nil {
return nil, err
}
return cpy, nil
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"Map",
"(",
"f",
"func",
"(",
"*",
"Term",
",",
"*",
"Term",
")",
"(",
"*",
"Term",
",",
"*",
"Term",
",",
"error",
")",
")",
"(",
"Object",
",",
"error",
")",
"{",
"cpy",
":=",
"newobject",
"(",
"obj",
".",
"Len",
"(",
")",
")",
"\n",
"err",
":=",
"obj",
".",
"Iter",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"k",
",",
"v",
",",
"err",
"=",
"f",
"(",
"k",
",",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"cpy",
".",
"insert",
"(",
"k",
",",
"v",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"cpy",
",",
"nil",
"\n",
"}"
] | // Map returns a new Object constructed by mapping each element in the object
// using the function f. | [
"Map",
"returns",
"a",
"new",
"Object",
"constructed",
"by",
"mapping",
"each",
"element",
"in",
"the",
"object",
"using",
"the",
"function",
"f",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1644-L1659 | train |
open-policy-agent/opa | ast/term.go | MarshalJSON | func (obj *object) MarshalJSON() ([]byte, error) {
sl := make([][2]*Term, obj.Len())
for i := range obj.keys {
k := obj.keys[i]
sl[i] = Item(k, obj.get(k).value)
}
return json.Marshal(sl)
} | go | func (obj *object) MarshalJSON() ([]byte, error) {
sl := make([][2]*Term, obj.Len())
for i := range obj.keys {
k := obj.keys[i]
sl[i] = Item(k, obj.get(k).value)
}
return json.Marshal(sl)
} | [
"func",
"(",
"obj",
"*",
"object",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"sl",
":=",
"make",
"(",
"[",
"]",
"[",
"2",
"]",
"*",
"Term",
",",
"obj",
".",
"Len",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"obj",
".",
"keys",
"{",
"k",
":=",
"obj",
".",
"keys",
"[",
"i",
"]",
"\n",
"sl",
"[",
"i",
"]",
"=",
"Item",
"(",
"k",
",",
"obj",
".",
"get",
"(",
"k",
")",
".",
"value",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"sl",
")",
"\n",
"}"
] | // MarshalJSON returns JSON encoded bytes representing obj. | [
"MarshalJSON",
"returns",
"JSON",
"encoded",
"bytes",
"representing",
"obj",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1667-L1674 | train |
open-policy-agent/opa | ast/term.go | Merge | func (obj object) Merge(other Object) (result Object, ok bool) {
result = NewObject()
stop := obj.Until(func(k, v *Term) bool {
if v2 := other.Get(k); v2 == nil {
result.Insert(k, v)
} else {
obj1, ok1 := v.Value.(Object)
obj2, ok2 := v2.Value.(Object)
if !ok1 || !ok2 {
return true
}
obj3, ok := obj1.Merge(obj2)
if !ok {
return true
}
result.Insert(k, NewTerm(obj3))
}
return false
})
if stop {
return nil, false
}
other.Foreach(func(k, v *Term) {
if v2 := obj.Get(k); v2 == nil {
result.Insert(k, v)
}
})
return result, true
} | go | func (obj object) Merge(other Object) (result Object, ok bool) {
result = NewObject()
stop := obj.Until(func(k, v *Term) bool {
if v2 := other.Get(k); v2 == nil {
result.Insert(k, v)
} else {
obj1, ok1 := v.Value.(Object)
obj2, ok2 := v2.Value.(Object)
if !ok1 || !ok2 {
return true
}
obj3, ok := obj1.Merge(obj2)
if !ok {
return true
}
result.Insert(k, NewTerm(obj3))
}
return false
})
if stop {
return nil, false
}
other.Foreach(func(k, v *Term) {
if v2 := obj.Get(k); v2 == nil {
result.Insert(k, v)
}
})
return result, true
} | [
"func",
"(",
"obj",
"object",
")",
"Merge",
"(",
"other",
"Object",
")",
"(",
"result",
"Object",
",",
"ok",
"bool",
")",
"{",
"result",
"=",
"NewObject",
"(",
")",
"\n",
"stop",
":=",
"obj",
".",
"Until",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"bool",
"{",
"if",
"v2",
":=",
"other",
".",
"Get",
"(",
"k",
")",
";",
"v2",
"==",
"nil",
"{",
"result",
".",
"Insert",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"else",
"{",
"obj1",
",",
"ok1",
":=",
"v",
".",
"Value",
".",
"(",
"Object",
")",
"\n",
"obj2",
",",
"ok2",
":=",
"v2",
".",
"Value",
".",
"(",
"Object",
")",
"\n",
"if",
"!",
"ok1",
"||",
"!",
"ok2",
"{",
"return",
"true",
"\n",
"}",
"\n",
"obj3",
",",
"ok",
":=",
"obj1",
".",
"Merge",
"(",
"obj2",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"result",
".",
"Insert",
"(",
"k",
",",
"NewTerm",
"(",
"obj3",
")",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"if",
"stop",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"other",
".",
"Foreach",
"(",
"func",
"(",
"k",
",",
"v",
"*",
"Term",
")",
"{",
"if",
"v2",
":=",
"obj",
".",
"Get",
"(",
"k",
")",
";",
"v2",
"==",
"nil",
"{",
"result",
".",
"Insert",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"result",
",",
"true",
"\n",
"}"
] | // Merge returns a new Object containing the non-overlapping keys of obj and other. If there are
// overlapping keys between obj and other, the values of associated with the keys are merged. Only
// objects can be merged with other objects. If the values cannot be merged, the second turn value
// will be false. | [
"Merge",
"returns",
"a",
"new",
"Object",
"containing",
"the",
"non",
"-",
"overlapping",
"keys",
"of",
"obj",
"and",
"other",
".",
"If",
"there",
"are",
"overlapping",
"keys",
"between",
"obj",
"and",
"other",
"the",
"values",
"of",
"associated",
"with",
"the",
"keys",
"are",
"merged",
".",
"Only",
"objects",
"can",
"be",
"merged",
"with",
"other",
"objects",
".",
"If",
"the",
"values",
"cannot",
"be",
"merged",
"the",
"second",
"turn",
"value",
"will",
"be",
"false",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1680-L1708 | train |
open-policy-agent/opa | ast/term.go | ArrayComprehensionTerm | func ArrayComprehensionTerm(term *Term, body Body) *Term {
return &Term{
Value: &ArrayComprehension{
Term: term,
Body: body,
},
}
} | go | func ArrayComprehensionTerm(term *Term, body Body) *Term {
return &Term{
Value: &ArrayComprehension{
Term: term,
Body: body,
},
}
} | [
"func",
"ArrayComprehensionTerm",
"(",
"term",
"*",
"Term",
",",
"body",
"Body",
")",
"*",
"Term",
"{",
"return",
"&",
"Term",
"{",
"Value",
":",
"&",
"ArrayComprehension",
"{",
"Term",
":",
"term",
",",
"Body",
":",
"body",
",",
"}",
",",
"}",
"\n",
"}"
] | // ArrayComprehensionTerm creates a new Term with an ArrayComprehension value. | [
"ArrayComprehensionTerm",
"creates",
"a",
"new",
"Term",
"with",
"an",
"ArrayComprehension",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1758-L1765 | train |
open-policy-agent/opa | ast/term.go | Copy | func (ac *ArrayComprehension) Copy() *ArrayComprehension {
cpy := *ac
cpy.Body = ac.Body.Copy()
cpy.Term = ac.Term.Copy()
return &cpy
} | go | func (ac *ArrayComprehension) Copy() *ArrayComprehension {
cpy := *ac
cpy.Body = ac.Body.Copy()
cpy.Term = ac.Term.Copy()
return &cpy
} | [
"func",
"(",
"ac",
"*",
"ArrayComprehension",
")",
"Copy",
"(",
")",
"*",
"ArrayComprehension",
"{",
"cpy",
":=",
"*",
"ac",
"\n",
"cpy",
".",
"Body",
"=",
"ac",
".",
"Body",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Term",
"=",
"ac",
".",
"Term",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of ac. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"ac",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1768-L1773 | train |
open-policy-agent/opa | ast/term.go | ObjectComprehensionTerm | func ObjectComprehensionTerm(key, value *Term, body Body) *Term {
return &Term{
Value: &ObjectComprehension{
Key: key,
Value: value,
Body: body,
},
}
} | go | func ObjectComprehensionTerm(key, value *Term, body Body) *Term {
return &Term{
Value: &ObjectComprehension{
Key: key,
Value: value,
Body: body,
},
}
} | [
"func",
"ObjectComprehensionTerm",
"(",
"key",
",",
"value",
"*",
"Term",
",",
"body",
"Body",
")",
"*",
"Term",
"{",
"return",
"&",
"Term",
"{",
"Value",
":",
"&",
"ObjectComprehension",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"value",
",",
"Body",
":",
"body",
",",
"}",
",",
"}",
"\n",
"}"
] | // ObjectComprehensionTerm creates a new Term with an ObjectComprehension value. | [
"ObjectComprehensionTerm",
"creates",
"a",
"new",
"Term",
"with",
"an",
"ObjectComprehension",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1816-L1824 | train |
open-policy-agent/opa | ast/term.go | Copy | func (oc *ObjectComprehension) Copy() *ObjectComprehension {
cpy := *oc
cpy.Body = oc.Body.Copy()
cpy.Key = oc.Key.Copy()
cpy.Value = oc.Value.Copy()
return &cpy
} | go | func (oc *ObjectComprehension) Copy() *ObjectComprehension {
cpy := *oc
cpy.Body = oc.Body.Copy()
cpy.Key = oc.Key.Copy()
cpy.Value = oc.Value.Copy()
return &cpy
} | [
"func",
"(",
"oc",
"*",
"ObjectComprehension",
")",
"Copy",
"(",
")",
"*",
"ObjectComprehension",
"{",
"cpy",
":=",
"*",
"oc",
"\n",
"cpy",
".",
"Body",
"=",
"oc",
".",
"Body",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Key",
"=",
"oc",
".",
"Key",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Value",
"=",
"oc",
".",
"Value",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of oc. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"oc",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1827-L1833 | train |
open-policy-agent/opa | ast/term.go | IsGround | func (oc *ObjectComprehension) IsGround() bool {
return oc.Key.IsGround() && oc.Value.IsGround() && oc.Body.IsGround()
} | go | func (oc *ObjectComprehension) IsGround() bool {
return oc.Key.IsGround() && oc.Value.IsGround() && oc.Body.IsGround()
} | [
"func",
"(",
"oc",
"*",
"ObjectComprehension",
")",
"IsGround",
"(",
")",
"bool",
"{",
"return",
"oc",
".",
"Key",
".",
"IsGround",
"(",
")",
"&&",
"oc",
".",
"Value",
".",
"IsGround",
"(",
")",
"&&",
"oc",
".",
"Body",
".",
"IsGround",
"(",
")",
"\n",
"}"
] | // IsGround returns true if the Key, Value and Body are ground. | [
"IsGround",
"returns",
"true",
"if",
"the",
"Key",
"Value",
"and",
"Body",
"are",
"ground",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1860-L1862 | train |
open-policy-agent/opa | ast/term.go | SetComprehensionTerm | func SetComprehensionTerm(term *Term, body Body) *Term {
return &Term{
Value: &SetComprehension{
Term: term,
Body: body,
},
}
} | go | func SetComprehensionTerm(term *Term, body Body) *Term {
return &Term{
Value: &SetComprehension{
Term: term,
Body: body,
},
}
} | [
"func",
"SetComprehensionTerm",
"(",
"term",
"*",
"Term",
",",
"body",
"Body",
")",
"*",
"Term",
"{",
"return",
"&",
"Term",
"{",
"Value",
":",
"&",
"SetComprehension",
"{",
"Term",
":",
"term",
",",
"Body",
":",
"body",
",",
"}",
",",
"}",
"\n",
"}"
] | // SetComprehensionTerm creates a new Term with an SetComprehension value. | [
"SetComprehensionTerm",
"creates",
"a",
"new",
"Term",
"with",
"an",
"SetComprehension",
"value",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1875-L1882 | train |
open-policy-agent/opa | ast/term.go | Copy | func (sc *SetComprehension) Copy() *SetComprehension {
cpy := *sc
cpy.Body = sc.Body.Copy()
cpy.Term = sc.Term.Copy()
return &cpy
} | go | func (sc *SetComprehension) Copy() *SetComprehension {
cpy := *sc
cpy.Body = sc.Body.Copy()
cpy.Term = sc.Term.Copy()
return &cpy
} | [
"func",
"(",
"sc",
"*",
"SetComprehension",
")",
"Copy",
"(",
")",
"*",
"SetComprehension",
"{",
"cpy",
":=",
"*",
"sc",
"\n",
"cpy",
".",
"Body",
"=",
"sc",
".",
"Body",
".",
"Copy",
"(",
")",
"\n",
"cpy",
".",
"Term",
"=",
"sc",
".",
"Term",
".",
"Copy",
"(",
")",
"\n",
"return",
"&",
"cpy",
"\n",
"}"
] | // Copy returns a deep copy of sc. | [
"Copy",
"returns",
"a",
"deep",
"copy",
"of",
"sc",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1885-L1890 | train |
open-policy-agent/opa | ast/term.go | MakeExpr | func (c Call) MakeExpr(output *Term) *Expr {
terms := []*Term(c)
return NewExpr(append(terms, output))
} | go | func (c Call) MakeExpr(output *Term) *Expr {
terms := []*Term(c)
return NewExpr(append(terms, output))
} | [
"func",
"(",
"c",
"Call",
")",
"MakeExpr",
"(",
"output",
"*",
"Term",
")",
"*",
"Expr",
"{",
"terms",
":=",
"[",
"]",
"*",
"Term",
"(",
"c",
")",
"\n",
"return",
"NewExpr",
"(",
"append",
"(",
"terms",
",",
"output",
")",
")",
"\n",
"}"
] | // MakeExpr returns an ew Expr from this call. | [
"MakeExpr",
"returns",
"an",
"ew",
"Expr",
"from",
"this",
"call",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/term.go#L1961-L1964 | train |
open-policy-agent/opa | storage/interface.go | GetPolicy | func (PolicyNotSupported) GetPolicy(context.Context, Transaction, string) ([]byte, error) {
return nil, policyNotSupportedError()
} | go | func (PolicyNotSupported) GetPolicy(context.Context, Transaction, string) ([]byte, error) {
return nil, policyNotSupportedError()
} | [
"func",
"(",
"PolicyNotSupported",
")",
"GetPolicy",
"(",
"context",
".",
"Context",
",",
"Transaction",
",",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"nil",
",",
"policyNotSupportedError",
"(",
")",
"\n",
"}"
] | // GetPolicy always returns a PolicyNotSupportedErr. | [
"GetPolicy",
"always",
"returns",
"a",
"PolicyNotSupportedErr",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/interface.go#L90-L92 | train |
open-policy-agent/opa | storage/interface.go | Register | func (TriggersNotSupported) Register(context.Context, Transaction, TriggerConfig) (TriggerHandle, error) {
return nil, triggersNotSupportedError()
} | go | func (TriggersNotSupported) Register(context.Context, Transaction, TriggerConfig) (TriggerHandle, error) {
return nil, triggersNotSupportedError()
} | [
"func",
"(",
"TriggersNotSupported",
")",
"Register",
"(",
"context",
".",
"Context",
",",
"Transaction",
",",
"TriggerConfig",
")",
"(",
"TriggerHandle",
",",
"error",
")",
"{",
"return",
"nil",
",",
"triggersNotSupportedError",
"(",
")",
"\n",
"}"
] | // Register always returns an error indicating triggers are not supported. | [
"Register",
"always",
"returns",
"an",
"error",
"indicating",
"triggers",
"are",
"not",
"supported",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/interface.go#L160-L162 | train |
open-policy-agent/opa | storage/interface.go | Build | func (IndexingNotSupported) Build(context.Context, Transaction, ast.Ref) (Index, error) {
return nil, indexingNotSupportedError()
} | go | func (IndexingNotSupported) Build(context.Context, Transaction, ast.Ref) (Index, error) {
return nil, indexingNotSupportedError()
} | [
"func",
"(",
"IndexingNotSupported",
")",
"Build",
"(",
"context",
".",
"Context",
",",
"Transaction",
",",
"ast",
".",
"Ref",
")",
"(",
"Index",
",",
"error",
")",
"{",
"return",
"nil",
",",
"indexingNotSupportedError",
"(",
")",
"\n",
"}"
] | // Build always returns an error indicating indexing is not supported. | [
"Build",
"always",
"returns",
"an",
"error",
"indicating",
"indexing",
"is",
"not",
"supported",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/storage/interface.go#L188-L190 | train |
open-policy-agent/opa | cmd/plugins.go | lambdaWalker | func lambdaWalker(lambda func(string) error, ext string) filepath.WalkFunc {
walk := func(path string, f os.FileInfo, err error) error {
// if error occurs during traversal to path, exit and crash
if err != nil {
return err
}
// skip anything that is a directory
if f.IsDir() {
return nil
}
if filepath.Ext(path) == ext {
return lambda(path)
}
// ignore anything else
return nil
}
return walk
} | go | func lambdaWalker(lambda func(string) error, ext string) filepath.WalkFunc {
walk := func(path string, f os.FileInfo, err error) error {
// if error occurs during traversal to path, exit and crash
if err != nil {
return err
}
// skip anything that is a directory
if f.IsDir() {
return nil
}
if filepath.Ext(path) == ext {
return lambda(path)
}
// ignore anything else
return nil
}
return walk
} | [
"func",
"lambdaWalker",
"(",
"lambda",
"func",
"(",
"string",
")",
"error",
",",
"ext",
"string",
")",
"filepath",
".",
"WalkFunc",
"{",
"walk",
":=",
"func",
"(",
"path",
"string",
",",
"f",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"// if error occurs during traversal to path, exit and crash",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// skip anything that is a directory",
"if",
"f",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"filepath",
".",
"Ext",
"(",
"path",
")",
"==",
"ext",
"{",
"return",
"lambda",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"// ignore anything else",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"walk",
"\n",
"}"
] | // lambdaWalker returns a walkfunc that applies lambda to every file with extension ext. Ignores all other file types.
// Lambda should take the file path as its parameter. | [
"lambdaWalker",
"returns",
"a",
"walkfunc",
"that",
"applies",
"lambda",
"to",
"every",
"file",
"with",
"extension",
"ext",
".",
"Ignores",
"all",
"other",
"file",
"types",
".",
"Lambda",
"should",
"take",
"the",
"file",
"path",
"as",
"its",
"parameter",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cmd/plugins.go#L26-L45 | train |
open-policy-agent/opa | cmd/plugins.go | registerSharedObjectFromFile | func registerSharedObjectFromFile(path string) error {
mod, err := plugin.Open(path)
if err != nil {
return err
}
initSym, err := mod.Lookup("Init")
if err != nil {
return err
}
// type assert init symbol
init, ok := initSym.(func() error)
if !ok {
return fmt.Errorf("symbol Init must be of type func() error")
}
// execute init
return init()
} | go | func registerSharedObjectFromFile(path string) error {
mod, err := plugin.Open(path)
if err != nil {
return err
}
initSym, err := mod.Lookup("Init")
if err != nil {
return err
}
// type assert init symbol
init, ok := initSym.(func() error)
if !ok {
return fmt.Errorf("symbol Init must be of type func() error")
}
// execute init
return init()
} | [
"func",
"registerSharedObjectFromFile",
"(",
"path",
"string",
")",
"error",
"{",
"mod",
",",
"err",
":=",
"plugin",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"initSym",
",",
"err",
":=",
"mod",
".",
"Lookup",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// type assert init symbol",
"init",
",",
"ok",
":=",
"initSym",
".",
"(",
"func",
"(",
")",
"error",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// execute init",
"return",
"init",
"(",
")",
"\n",
"}"
] | // loads the builtin from a file path | [
"loads",
"the",
"builtin",
"from",
"a",
"file",
"path"
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/cmd/plugins.go#L48-L66 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseBody | func MustParseBody(input string) Body {
parsed, err := ParseBody(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseBody(input string) Body {
parsed, err := ParseBody(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseBody",
"(",
"input",
"string",
")",
"Body",
"{",
"parsed",
",",
"err",
":=",
"ParseBody",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseBody returns a parsed body.
// If an error occurs during parsing, panic. | [
"MustParseBody",
"returns",
"a",
"parsed",
"body",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L24-L30 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseExpr | func MustParseExpr(input string) *Expr {
parsed, err := ParseExpr(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseExpr(input string) *Expr {
parsed, err := ParseExpr(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseExpr",
"(",
"input",
"string",
")",
"*",
"Expr",
"{",
"parsed",
",",
"err",
":=",
"ParseExpr",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseExpr returns a parsed expression.
// If an error occurs during parsing, panic. | [
"MustParseExpr",
"returns",
"a",
"parsed",
"expression",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L34-L40 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseImports | func MustParseImports(input string) []*Import {
parsed, err := ParseImports(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseImports(input string) []*Import {
parsed, err := ParseImports(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseImports",
"(",
"input",
"string",
")",
"[",
"]",
"*",
"Import",
"{",
"parsed",
",",
"err",
":=",
"ParseImports",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseImports returns a slice of imports.
// If an error occurs during parsing, panic. | [
"MustParseImports",
"returns",
"a",
"slice",
"of",
"imports",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L44-L50 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseModule | func MustParseModule(input string) *Module {
parsed, err := ParseModule("", input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseModule(input string) *Module {
parsed, err := ParseModule("", input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseModule",
"(",
"input",
"string",
")",
"*",
"Module",
"{",
"parsed",
",",
"err",
":=",
"ParseModule",
"(",
"\"",
"\"",
",",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseModule returns a parsed module.
// If an error occurs during parsing, panic. | [
"MustParseModule",
"returns",
"a",
"parsed",
"module",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L54-L60 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParsePackage | func MustParsePackage(input string) *Package {
parsed, err := ParsePackage(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParsePackage(input string) *Package {
parsed, err := ParsePackage(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParsePackage",
"(",
"input",
"string",
")",
"*",
"Package",
"{",
"parsed",
",",
"err",
":=",
"ParsePackage",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParsePackage returns a Package.
// If an error occurs during parsing, panic. | [
"MustParsePackage",
"returns",
"a",
"Package",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L64-L70 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseStatements | func MustParseStatements(input string) []Statement {
parsed, _, err := ParseStatements("", input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseStatements(input string) []Statement {
parsed, _, err := ParseStatements("", input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseStatements",
"(",
"input",
"string",
")",
"[",
"]",
"Statement",
"{",
"parsed",
",",
"_",
",",
"err",
":=",
"ParseStatements",
"(",
"\"",
"\"",
",",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseStatements returns a slice of parsed statements.
// If an error occurs during parsing, panic. | [
"MustParseStatements",
"returns",
"a",
"slice",
"of",
"parsed",
"statements",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L74-L80 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseStatement | func MustParseStatement(input string) Statement {
parsed, err := ParseStatement(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseStatement(input string) Statement {
parsed, err := ParseStatement(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseStatement",
"(",
"input",
"string",
")",
"Statement",
"{",
"parsed",
",",
"err",
":=",
"ParseStatement",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseStatement returns exactly one statement.
// If an error occurs during parsing, panic. | [
"MustParseStatement",
"returns",
"exactly",
"one",
"statement",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L84-L90 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseRef | func MustParseRef(input string) Ref {
parsed, err := ParseRef(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseRef(input string) Ref {
parsed, err := ParseRef(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseRef",
"(",
"input",
"string",
")",
"Ref",
"{",
"parsed",
",",
"err",
":=",
"ParseRef",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseRef returns a parsed reference.
// If an error occurs during parsing, panic. | [
"MustParseRef",
"returns",
"a",
"parsed",
"reference",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L94-L100 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseRule | func MustParseRule(input string) *Rule {
parsed, err := ParseRule(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseRule(input string) *Rule {
parsed, err := ParseRule(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseRule",
"(",
"input",
"string",
")",
"*",
"Rule",
"{",
"parsed",
",",
"err",
":=",
"ParseRule",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseRule returns a parsed rule.
// If an error occurs during parsing, panic. | [
"MustParseRule",
"returns",
"a",
"parsed",
"rule",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L104-L110 | train |
open-policy-agent/opa | ast/parser_ext.go | MustParseTerm | func MustParseTerm(input string) *Term {
parsed, err := ParseTerm(input)
if err != nil {
panic(err)
}
return parsed
} | go | func MustParseTerm(input string) *Term {
parsed, err := ParseTerm(input)
if err != nil {
panic(err)
}
return parsed
} | [
"func",
"MustParseTerm",
"(",
"input",
"string",
")",
"*",
"Term",
"{",
"parsed",
",",
"err",
":=",
"ParseTerm",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"parsed",
"\n",
"}"
] | // MustParseTerm returns a parsed term.
// If an error occurs during parsing, panic. | [
"MustParseTerm",
"returns",
"a",
"parsed",
"term",
".",
"If",
"an",
"error",
"occurs",
"during",
"parsing",
"panic",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L114-L120 | train |
open-policy-agent/opa | ast/parser_ext.go | ParseRuleFromBody | func ParseRuleFromBody(module *Module, body Body) (*Rule, error) {
if len(body) != 1 {
return nil, fmt.Errorf("multiple expressions cannot be used for rule head")
}
return ParseRuleFromExpr(module, body[0])
} | go | func ParseRuleFromBody(module *Module, body Body) (*Rule, error) {
if len(body) != 1 {
return nil, fmt.Errorf("multiple expressions cannot be used for rule head")
}
return ParseRuleFromExpr(module, body[0])
} | [
"func",
"ParseRuleFromBody",
"(",
"module",
"*",
"Module",
",",
"body",
"Body",
")",
"(",
"*",
"Rule",
",",
"error",
")",
"{",
"if",
"len",
"(",
"body",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ParseRuleFromExpr",
"(",
"module",
",",
"body",
"[",
"0",
"]",
")",
"\n",
"}"
] | // ParseRuleFromBody returns a rule if the body can be interpreted as a rule
// definition. Otherwise, an error is returned. | [
"ParseRuleFromBody",
"returns",
"a",
"rule",
"if",
"the",
"body",
"can",
"be",
"interpreted",
"as",
"a",
"rule",
"definition",
".",
"Otherwise",
"an",
"error",
"is",
"returned",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L124-L131 | train |
open-policy-agent/opa | ast/parser_ext.go | ParseRuleFromExpr | func ParseRuleFromExpr(module *Module, expr *Expr) (*Rule, error) {
if len(expr.With) > 0 {
return nil, fmt.Errorf("expressions using with keyword cannot be used for rule head")
}
if expr.Negated {
return nil, fmt.Errorf("negated expressions cannot be used for rule head")
}
if term, ok := expr.Terms.(*Term); ok {
switch v := term.Value.(type) {
case Ref:
return ParsePartialSetDocRuleFromTerm(module, term)
default:
return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(v))
}
}
if !expr.IsEquality() && expr.IsCall() {
if _, ok := BuiltinMap[expr.Operator().String()]; ok {
return nil, fmt.Errorf("rule name conflicts with built-in function")
}
return ParseRuleFromCallExpr(module, expr.Terms.([]*Term))
}
lhs, rhs := expr.Operand(0), expr.Operand(1)
rule, err := ParseCompleteDocRuleFromEqExpr(module, lhs, rhs)
if err == nil {
return rule, nil
}
rule, err = ParseRuleFromCallEqExpr(module, lhs, rhs)
if err == nil {
return rule, nil
}
return ParsePartialObjectDocRuleFromEqExpr(module, lhs, rhs)
} | go | func ParseRuleFromExpr(module *Module, expr *Expr) (*Rule, error) {
if len(expr.With) > 0 {
return nil, fmt.Errorf("expressions using with keyword cannot be used for rule head")
}
if expr.Negated {
return nil, fmt.Errorf("negated expressions cannot be used for rule head")
}
if term, ok := expr.Terms.(*Term); ok {
switch v := term.Value.(type) {
case Ref:
return ParsePartialSetDocRuleFromTerm(module, term)
default:
return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(v))
}
}
if !expr.IsEquality() && expr.IsCall() {
if _, ok := BuiltinMap[expr.Operator().String()]; ok {
return nil, fmt.Errorf("rule name conflicts with built-in function")
}
return ParseRuleFromCallExpr(module, expr.Terms.([]*Term))
}
lhs, rhs := expr.Operand(0), expr.Operand(1)
rule, err := ParseCompleteDocRuleFromEqExpr(module, lhs, rhs)
if err == nil {
return rule, nil
}
rule, err = ParseRuleFromCallEqExpr(module, lhs, rhs)
if err == nil {
return rule, nil
}
return ParsePartialObjectDocRuleFromEqExpr(module, lhs, rhs)
} | [
"func",
"ParseRuleFromExpr",
"(",
"module",
"*",
"Module",
",",
"expr",
"*",
"Expr",
")",
"(",
"*",
"Rule",
",",
"error",
")",
"{",
"if",
"len",
"(",
"expr",
".",
"With",
")",
">",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"expr",
".",
"Negated",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"term",
",",
"ok",
":=",
"expr",
".",
"Terms",
".",
"(",
"*",
"Term",
")",
";",
"ok",
"{",
"switch",
"v",
":=",
"term",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"Ref",
":",
"return",
"ParsePartialSetDocRuleFromTerm",
"(",
"module",
",",
"term",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"TypeName",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"expr",
".",
"IsEquality",
"(",
")",
"&&",
"expr",
".",
"IsCall",
"(",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"BuiltinMap",
"[",
"expr",
".",
"Operator",
"(",
")",
".",
"String",
"(",
")",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ParseRuleFromCallExpr",
"(",
"module",
",",
"expr",
".",
"Terms",
".",
"(",
"[",
"]",
"*",
"Term",
")",
")",
"\n",
"}",
"\n\n",
"lhs",
",",
"rhs",
":=",
"expr",
".",
"Operand",
"(",
"0",
")",
",",
"expr",
".",
"Operand",
"(",
"1",
")",
"\n\n",
"rule",
",",
"err",
":=",
"ParseCompleteDocRuleFromEqExpr",
"(",
"module",
",",
"lhs",
",",
"rhs",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"rule",
",",
"nil",
"\n",
"}",
"\n\n",
"rule",
",",
"err",
"=",
"ParseRuleFromCallEqExpr",
"(",
"module",
",",
"lhs",
",",
"rhs",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"rule",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"ParsePartialObjectDocRuleFromEqExpr",
"(",
"module",
",",
"lhs",
",",
"rhs",
")",
"\n",
"}"
] | // ParseRuleFromExpr returns a rule if the expression can be interpreted as a
// rule definition. | [
"ParseRuleFromExpr",
"returns",
"a",
"rule",
"if",
"the",
"expression",
"can",
"be",
"interpreted",
"as",
"a",
"rule",
"definition",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L135-L174 | train |
open-policy-agent/opa | ast/parser_ext.go | ParseCompleteDocRuleFromEqExpr | func ParseCompleteDocRuleFromEqExpr(module *Module, lhs, rhs *Term) (*Rule, error) {
var name Var
if RootDocumentRefs.Contains(lhs) {
name = lhs.Value.(Ref)[0].Value.(Var)
} else if v, ok := lhs.Value.(Var); ok {
name = v
} else {
return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(lhs.Value))
}
rule := &Rule{
Location: rhs.Location,
Head: &Head{
Location: rhs.Location,
Name: name,
Value: rhs,
},
Body: NewBody(
NewExpr(BooleanTerm(true).SetLocation(rhs.Location)).SetLocation(rhs.Location),
),
Module: module,
}
return rule, nil
} | go | func ParseCompleteDocRuleFromEqExpr(module *Module, lhs, rhs *Term) (*Rule, error) {
var name Var
if RootDocumentRefs.Contains(lhs) {
name = lhs.Value.(Ref)[0].Value.(Var)
} else if v, ok := lhs.Value.(Var); ok {
name = v
} else {
return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(lhs.Value))
}
rule := &Rule{
Location: rhs.Location,
Head: &Head{
Location: rhs.Location,
Name: name,
Value: rhs,
},
Body: NewBody(
NewExpr(BooleanTerm(true).SetLocation(rhs.Location)).SetLocation(rhs.Location),
),
Module: module,
}
return rule, nil
} | [
"func",
"ParseCompleteDocRuleFromEqExpr",
"(",
"module",
"*",
"Module",
",",
"lhs",
",",
"rhs",
"*",
"Term",
")",
"(",
"*",
"Rule",
",",
"error",
")",
"{",
"var",
"name",
"Var",
"\n\n",
"if",
"RootDocumentRefs",
".",
"Contains",
"(",
"lhs",
")",
"{",
"name",
"=",
"lhs",
".",
"Value",
".",
"(",
"Ref",
")",
"[",
"0",
"]",
".",
"Value",
".",
"(",
"Var",
")",
"\n",
"}",
"else",
"if",
"v",
",",
"ok",
":=",
"lhs",
".",
"Value",
".",
"(",
"Var",
")",
";",
"ok",
"{",
"name",
"=",
"v",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"TypeName",
"(",
"lhs",
".",
"Value",
")",
")",
"\n",
"}",
"\n\n",
"rule",
":=",
"&",
"Rule",
"{",
"Location",
":",
"rhs",
".",
"Location",
",",
"Head",
":",
"&",
"Head",
"{",
"Location",
":",
"rhs",
".",
"Location",
",",
"Name",
":",
"name",
",",
"Value",
":",
"rhs",
",",
"}",
",",
"Body",
":",
"NewBody",
"(",
"NewExpr",
"(",
"BooleanTerm",
"(",
"true",
")",
".",
"SetLocation",
"(",
"rhs",
".",
"Location",
")",
")",
".",
"SetLocation",
"(",
"rhs",
".",
"Location",
")",
",",
")",
",",
"Module",
":",
"module",
",",
"}",
"\n\n",
"return",
"rule",
",",
"nil",
"\n",
"}"
] | // ParseCompleteDocRuleFromEqExpr returns a rule if the expression can be
// interpreted as a complete document definition. | [
"ParseCompleteDocRuleFromEqExpr",
"returns",
"a",
"rule",
"if",
"the",
"expression",
"can",
"be",
"interpreted",
"as",
"a",
"complete",
"document",
"definition",
"."
] | 589105aff580587c1b27b87df7123105af3e212a | https://github.com/open-policy-agent/opa/blob/589105aff580587c1b27b87df7123105af3e212a/ast/parser_ext.go#L178-L204 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.