id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,500 |
tyler-sommer/stick
|
parse/parse.go
|
leave
|
func (t *Tree) leave(n Node) {
for _, v := range t.Visitors {
v.Leave(n)
}
}
|
go
|
func (t *Tree) leave(n Node) {
for _, v := range t.Visitors {
v.Leave(n)
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"leave",
"(",
"n",
"Node",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"t",
".",
"Visitors",
"{",
"v",
".",
"Leave",
"(",
"n",
")",
"\n",
"}",
"\n",
"}"
] |
// Leave is called just before the state exits the given Node.
|
[
"Leave",
"is",
"called",
"just",
"before",
"the",
"state",
"exits",
"the",
"given",
"Node",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L190-L194
|
16,501 |
tyler-sommer/stick
|
parse/parse.go
|
Parse
|
func Parse(input string) (*Tree, error) {
t := NewTree(bytes.NewReader([]byte(input)))
return t, t.Parse()
}
|
go
|
func Parse(input string) (*Tree, error) {
t := NewTree(bytes.NewReader([]byte(input)))
return t, t.Parse()
}
|
[
"func",
"Parse",
"(",
"input",
"string",
")",
"(",
"*",
"Tree",
",",
"error",
")",
"{",
"t",
":=",
"NewTree",
"(",
"bytes",
".",
"NewReader",
"(",
"[",
"]",
"byte",
"(",
"input",
")",
")",
")",
"\n",
"return",
"t",
",",
"t",
".",
"Parse",
"(",
")",
"\n",
"}"
] |
// Parse parses the given input.
|
[
"Parse",
"parses",
"the",
"given",
"input",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L208-L211
|
16,502 |
tyler-sommer/stick
|
parse/parse.go
|
Parse
|
func (t *Tree) Parse() error {
go t.lex.tokenize()
for {
n, err := t.parse()
if err != nil {
return t.enrichError(err)
}
if n == nil {
break
}
t.root.Append(n)
}
t.traverse(t.root)
return nil
}
|
go
|
func (t *Tree) Parse() error {
go t.lex.tokenize()
for {
n, err := t.parse()
if err != nil {
return t.enrichError(err)
}
if n == nil {
break
}
t.root.Append(n)
}
t.traverse(t.root)
return nil
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"Parse",
"(",
")",
"error",
"{",
"go",
"t",
".",
"lex",
".",
"tokenize",
"(",
")",
"\n",
"for",
"{",
"n",
",",
"err",
":=",
"t",
".",
"parse",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"t",
".",
"enrichError",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"t",
".",
"root",
".",
"Append",
"(",
"n",
")",
"\n",
"}",
"\n",
"t",
".",
"traverse",
"(",
"t",
".",
"root",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Parse begins parsing, returning an error, if any.
|
[
"Parse",
"begins",
"parsing",
"returning",
"an",
"error",
"if",
"any",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L214-L228
|
16,503 |
tyler-sommer/stick
|
parse/parse.go
|
parse
|
func (t *Tree) parse() (Node, error) {
tok := t.nextNonSpace()
switch tok.tokenType {
case tokenText:
return NewTextNode(tok.value, tok.Pos), nil
case tokenPrintOpen:
name, err := t.parseExpr()
if err != nil {
return nil, err
}
_, err = t.expect(tokenPrintClose)
if err != nil {
return nil, err
}
return NewPrintNode(name, tok.Pos), nil
case tokenTagOpen:
return t.parseTag()
case tokenCommentOpen:
tok, err := t.expect(tokenText)
if err != nil {
return nil, err
}
_, err = t.expect(tokenCommentClose)
if err != nil {
return nil, err
}
return NewCommentNode(tok.value, tok.Pos), nil
case tokenEOF:
// expected end of input
return nil, nil
}
return nil, newUnexpectedTokenError(tok)
}
|
go
|
func (t *Tree) parse() (Node, error) {
tok := t.nextNonSpace()
switch tok.tokenType {
case tokenText:
return NewTextNode(tok.value, tok.Pos), nil
case tokenPrintOpen:
name, err := t.parseExpr()
if err != nil {
return nil, err
}
_, err = t.expect(tokenPrintClose)
if err != nil {
return nil, err
}
return NewPrintNode(name, tok.Pos), nil
case tokenTagOpen:
return t.parseTag()
case tokenCommentOpen:
tok, err := t.expect(tokenText)
if err != nil {
return nil, err
}
_, err = t.expect(tokenCommentClose)
if err != nil {
return nil, err
}
return NewCommentNode(tok.value, tok.Pos), nil
case tokenEOF:
// expected end of input
return nil, nil
}
return nil, newUnexpectedTokenError(tok)
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parse",
"(",
")",
"(",
"Node",
",",
"error",
")",
"{",
"tok",
":=",
"t",
".",
"nextNonSpace",
"(",
")",
"\n",
"switch",
"tok",
".",
"tokenType",
"{",
"case",
"tokenText",
":",
"return",
"NewTextNode",
"(",
"tok",
".",
"value",
",",
"tok",
".",
"Pos",
")",
",",
"nil",
"\n\n",
"case",
"tokenPrintOpen",
":",
"name",
",",
"err",
":=",
"t",
".",
"parseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"t",
".",
"expect",
"(",
"tokenPrintClose",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewPrintNode",
"(",
"name",
",",
"tok",
".",
"Pos",
")",
",",
"nil",
"\n\n",
"case",
"tokenTagOpen",
":",
"return",
"t",
".",
"parseTag",
"(",
")",
"\n\n",
"case",
"tokenCommentOpen",
":",
"tok",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"tokenText",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"t",
".",
"expect",
"(",
"tokenCommentClose",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewCommentNode",
"(",
"tok",
".",
"value",
",",
"tok",
".",
"Pos",
")",
",",
"nil",
"\n\n",
"case",
"tokenEOF",
":",
"// expected end of input",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"newUnexpectedTokenError",
"(",
"tok",
")",
"\n",
"}"
] |
// parse parses generic input, such as text markup, print or tag statement opening tokens.
// parse is intended to pick up at the beginning of input, such as the start of a tag's body
// or the more obvious start of a document.
|
[
"parse",
"parses",
"generic",
"input",
"such",
"as",
"text",
"markup",
"print",
"or",
"tag",
"statement",
"opening",
"tokens",
".",
"parse",
"is",
"intended",
"to",
"pick",
"up",
"at",
"the",
"beginning",
"of",
"input",
"such",
"as",
"the",
"start",
"of",
"a",
"tag",
"s",
"body",
"or",
"the",
"more",
"obvious",
"start",
"of",
"a",
"document",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L233-L269
|
16,504 |
tyler-sommer/stick
|
value.go
|
NewSafeValue
|
func NewSafeValue(val Value, types ...string) SafeValue {
safeFor := make(map[string]bool)
for _, k := range types {
safeFor[k] = true
}
if v, ok := val.(SafeValue); ok {
for _, k := range v.SafeFor() {
safeFor[k] = true
}
return safeValue{safeFor, v.Value()}
}
return safeValue{safeFor, val}
}
|
go
|
func NewSafeValue(val Value, types ...string) SafeValue {
safeFor := make(map[string]bool)
for _, k := range types {
safeFor[k] = true
}
if v, ok := val.(SafeValue); ok {
for _, k := range v.SafeFor() {
safeFor[k] = true
}
return safeValue{safeFor, v.Value()}
}
return safeValue{safeFor, val}
}
|
[
"func",
"NewSafeValue",
"(",
"val",
"Value",
",",
"types",
"...",
"string",
")",
"SafeValue",
"{",
"safeFor",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"types",
"{",
"safeFor",
"[",
"k",
"]",
"=",
"true",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"val",
".",
"(",
"SafeValue",
")",
";",
"ok",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"v",
".",
"SafeFor",
"(",
")",
"{",
"safeFor",
"[",
"k",
"]",
"=",
"true",
"\n",
"}",
"\n",
"return",
"safeValue",
"{",
"safeFor",
",",
"v",
".",
"Value",
"(",
")",
"}",
"\n",
"}",
"\n",
"return",
"safeValue",
"{",
"safeFor",
",",
"val",
"}",
"\n",
"}"
] |
// NewSafeValue wraps the given value and returns a SafeValue.
|
[
"NewSafeValue",
"wraps",
"the",
"given",
"value",
"and",
"returns",
"a",
"SafeValue",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L28-L40
|
16,505 |
tyler-sommer/stick
|
value.go
|
CoerceBool
|
func CoerceBool(v Value) bool {
switch vc := v.(type) {
case SafeValue:
return CoerceBool(vc.Value())
case bool:
return vc
case Boolean:
return vc.Boolean()
case uint:
return vc > 0
case uint8:
return vc > 0
case uint16:
return vc > 0
case uint32:
return vc > 0
case uint64:
return vc > 0
case int:
return vc > 0
case int8:
return vc > 0
case int16:
return vc > 0
case int32:
return vc > 0
case int64:
return vc > 0
case float32:
return vc > 0
case float64:
return vc > 0
case string:
return len(vc) > 0
case decimal.Decimal:
return vc.GreaterThan(decimal.Zero)
case Stringer:
return len(vc.String()) > 0
case Number:
return vc.Number() > 0
}
return false
}
|
go
|
func CoerceBool(v Value) bool {
switch vc := v.(type) {
case SafeValue:
return CoerceBool(vc.Value())
case bool:
return vc
case Boolean:
return vc.Boolean()
case uint:
return vc > 0
case uint8:
return vc > 0
case uint16:
return vc > 0
case uint32:
return vc > 0
case uint64:
return vc > 0
case int:
return vc > 0
case int8:
return vc > 0
case int16:
return vc > 0
case int32:
return vc > 0
case int64:
return vc > 0
case float32:
return vc > 0
case float64:
return vc > 0
case string:
return len(vc) > 0
case decimal.Decimal:
return vc.GreaterThan(decimal.Zero)
case Stringer:
return len(vc.String()) > 0
case Number:
return vc.Number() > 0
}
return false
}
|
[
"func",
"CoerceBool",
"(",
"v",
"Value",
")",
"bool",
"{",
"switch",
"vc",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"SafeValue",
":",
"return",
"CoerceBool",
"(",
"vc",
".",
"Value",
"(",
")",
")",
"\n",
"case",
"bool",
":",
"return",
"vc",
"\n",
"case",
"Boolean",
":",
"return",
"vc",
".",
"Boolean",
"(",
")",
"\n",
"case",
"uint",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"uint8",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"uint16",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"uint32",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"uint64",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"int",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"int8",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"int16",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"int32",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"int64",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"float32",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"float64",
":",
"return",
"vc",
">",
"0",
"\n",
"case",
"string",
":",
"return",
"len",
"(",
"vc",
")",
">",
"0",
"\n",
"case",
"decimal",
".",
"Decimal",
":",
"return",
"vc",
".",
"GreaterThan",
"(",
"decimal",
".",
"Zero",
")",
"\n",
"case",
"Stringer",
":",
"return",
"len",
"(",
"vc",
".",
"String",
"(",
")",
")",
">",
"0",
"\n",
"case",
"Number",
":",
"return",
"vc",
".",
"Number",
"(",
")",
">",
"0",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// CoerceBool coerces the given value into a boolean. Boolean false is returned
// if the value cannot be coerced.
|
[
"CoerceBool",
"coerces",
"the",
"given",
"value",
"into",
"a",
"boolean",
".",
"Boolean",
"false",
"is",
"returned",
"if",
"the",
"value",
"cannot",
"be",
"coerced",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L85-L127
|
16,506 |
tyler-sommer/stick
|
value.go
|
CoerceString
|
func CoerceString(v Value) string {
switch vc := v.(type) {
case SafeValue:
return CoerceString(vc.Value())
case string:
return vc
case Stringer:
return vc.String()
case float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%v", vc)
case Number:
return fmt.Sprintf("%v", vc.Number())
case Boolean:
if vc.Boolean() == true {
return "1" // Twig compatibility (aka PHP compatibility)
}
case bool:
if vc == true {
return "1" // Twig compatibility (aka PHP compatibility)
}
}
return ""
}
|
go
|
func CoerceString(v Value) string {
switch vc := v.(type) {
case SafeValue:
return CoerceString(vc.Value())
case string:
return vc
case Stringer:
return vc.String()
case float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%v", vc)
case Number:
return fmt.Sprintf("%v", vc.Number())
case Boolean:
if vc.Boolean() == true {
return "1" // Twig compatibility (aka PHP compatibility)
}
case bool:
if vc == true {
return "1" // Twig compatibility (aka PHP compatibility)
}
}
return ""
}
|
[
"func",
"CoerceString",
"(",
"v",
"Value",
")",
"string",
"{",
"switch",
"vc",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"SafeValue",
":",
"return",
"CoerceString",
"(",
"vc",
".",
"Value",
"(",
")",
")",
"\n",
"case",
"string",
":",
"return",
"vc",
"\n",
"case",
"Stringer",
":",
"return",
"vc",
".",
"String",
"(",
")",
"\n",
"case",
"float32",
",",
"float64",
",",
"int",
",",
"int8",
",",
"int16",
",",
"int32",
",",
"int64",
",",
"uint",
",",
"uint8",
",",
"uint16",
",",
"uint32",
",",
"uint64",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"vc",
")",
"\n",
"case",
"Number",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"vc",
".",
"Number",
"(",
")",
")",
"\n",
"case",
"Boolean",
":",
"if",
"vc",
".",
"Boolean",
"(",
")",
"==",
"true",
"{",
"return",
"\"",
"\"",
"// Twig compatibility (aka PHP compatibility)",
"\n",
"}",
"\n",
"case",
"bool",
":",
"if",
"vc",
"==",
"true",
"{",
"return",
"\"",
"\"",
"// Twig compatibility (aka PHP compatibility)",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// CoerceString coerces the given value into a string. An empty string is returned
// if the value cannot be coerced.
|
[
"CoerceString",
"coerces",
"the",
"given",
"value",
"into",
"a",
"string",
".",
"An",
"empty",
"string",
"is",
"returned",
"if",
"the",
"value",
"cannot",
"be",
"coerced",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L190-L213
|
16,507 |
tyler-sommer/stick
|
value.go
|
GetAttr
|
func GetAttr(v Value, attr Value, args ...Value) (Value, error) {
r := reflect.Indirect(reflect.ValueOf(v))
if !r.IsValid() {
return nil, fmt.Errorf("getattr: value does not support attribute lookup: %v", v)
}
var retval reflect.Value
switch r.Kind() {
case reflect.Struct:
strval := CoerceString(attr)
retval = r.FieldByName(strval)
if !retval.IsValid() {
var err error
retval, err = getMethod(v, strval)
if err != nil {
return nil, err
}
}
case reflect.Map:
retval = r.MapIndex(reflect.ValueOf(attr))
case reflect.Slice, reflect.Array:
index := int(CoerceNumber(attr))
if index >= 0 && index < r.Len() {
retval = r.Index(index)
}
}
if !retval.IsValid() {
return nil, fmt.Errorf("getattr: unable to locate attribute \"%s\" on \"%v\"", attr, v)
}
if retval.Kind() == reflect.Func {
t := retval.Type()
if t.NumOut() > 1 {
return nil, fmt.Errorf("getattr: multiple return values unsupported, called method \"%s\" on \"%v\"", attr, v)
}
rargs := make([]reflect.Value, len(args))
for k, v := range args {
rargs[k] = reflect.ValueOf(v)
}
if t.NumIn() != len(rargs) {
return nil, fmt.Errorf("getattr: method \"%s\" on \"%v\" expects %d parameter(s), %d given", attr, v, t.NumIn(), len(rargs))
}
res := retval.Call(rargs)
if len(res) == 0 {
return nil, nil
}
retval = res[0]
}
return retval.Interface(), nil
}
|
go
|
func GetAttr(v Value, attr Value, args ...Value) (Value, error) {
r := reflect.Indirect(reflect.ValueOf(v))
if !r.IsValid() {
return nil, fmt.Errorf("getattr: value does not support attribute lookup: %v", v)
}
var retval reflect.Value
switch r.Kind() {
case reflect.Struct:
strval := CoerceString(attr)
retval = r.FieldByName(strval)
if !retval.IsValid() {
var err error
retval, err = getMethod(v, strval)
if err != nil {
return nil, err
}
}
case reflect.Map:
retval = r.MapIndex(reflect.ValueOf(attr))
case reflect.Slice, reflect.Array:
index := int(CoerceNumber(attr))
if index >= 0 && index < r.Len() {
retval = r.Index(index)
}
}
if !retval.IsValid() {
return nil, fmt.Errorf("getattr: unable to locate attribute \"%s\" on \"%v\"", attr, v)
}
if retval.Kind() == reflect.Func {
t := retval.Type()
if t.NumOut() > 1 {
return nil, fmt.Errorf("getattr: multiple return values unsupported, called method \"%s\" on \"%v\"", attr, v)
}
rargs := make([]reflect.Value, len(args))
for k, v := range args {
rargs[k] = reflect.ValueOf(v)
}
if t.NumIn() != len(rargs) {
return nil, fmt.Errorf("getattr: method \"%s\" on \"%v\" expects %d parameter(s), %d given", attr, v, t.NumIn(), len(rargs))
}
res := retval.Call(rargs)
if len(res) == 0 {
return nil, nil
}
retval = res[0]
}
return retval.Interface(), nil
}
|
[
"func",
"GetAttr",
"(",
"v",
"Value",
",",
"attr",
"Value",
",",
"args",
"...",
"Value",
")",
"(",
"Value",
",",
"error",
")",
"{",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
")",
"\n",
"if",
"!",
"r",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"var",
"retval",
"reflect",
".",
"Value",
"\n",
"switch",
"r",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Struct",
":",
"strval",
":=",
"CoerceString",
"(",
"attr",
")",
"\n",
"retval",
"=",
"r",
".",
"FieldByName",
"(",
"strval",
")",
"\n",
"if",
"!",
"retval",
".",
"IsValid",
"(",
")",
"{",
"var",
"err",
"error",
"\n",
"retval",
",",
"err",
"=",
"getMethod",
"(",
"v",
",",
"strval",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Map",
":",
"retval",
"=",
"r",
".",
"MapIndex",
"(",
"reflect",
".",
"ValueOf",
"(",
"attr",
")",
")",
"\n",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
":",
"index",
":=",
"int",
"(",
"CoerceNumber",
"(",
"attr",
")",
")",
"\n",
"if",
"index",
">=",
"0",
"&&",
"index",
"<",
"r",
".",
"Len",
"(",
")",
"{",
"retval",
"=",
"r",
".",
"Index",
"(",
"index",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"retval",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"attr",
",",
"v",
")",
"\n",
"}",
"\n",
"if",
"retval",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Func",
"{",
"t",
":=",
"retval",
".",
"Type",
"(",
")",
"\n",
"if",
"t",
".",
"NumOut",
"(",
")",
">",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"attr",
",",
"v",
")",
"\n",
"}",
"\n",
"rargs",
":=",
"make",
"(",
"[",
"]",
"reflect",
".",
"Value",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"args",
"{",
"rargs",
"[",
"k",
"]",
"=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"NumIn",
"(",
")",
"!=",
"len",
"(",
"rargs",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"attr",
",",
"v",
",",
"t",
".",
"NumIn",
"(",
")",
",",
"len",
"(",
"rargs",
")",
")",
"\n",
"}",
"\n",
"res",
":=",
"retval",
".",
"Call",
"(",
"rargs",
")",
"\n",
"if",
"len",
"(",
"res",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"retval",
"=",
"res",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"retval",
".",
"Interface",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GetAttr attempts to access the given value and return the specified attribute.
|
[
"GetAttr",
"attempts",
"to",
"access",
"the",
"given",
"value",
"and",
"return",
"the",
"specified",
"attribute",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L216-L263
|
16,508 |
tyler-sommer/stick
|
value.go
|
IsArray
|
func IsArray(val Value) bool {
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array:
return true
}
return false
}
|
go
|
func IsArray(val Value) bool {
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array:
return true
}
return false
}
|
[
"func",
"IsArray",
"(",
"val",
"Value",
")",
"bool",
"{",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
")",
"\n",
"switch",
"r",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsArray returns true if the given Value is a slice or array.
|
[
"IsArray",
"returns",
"true",
"if",
"the",
"given",
"Value",
"is",
"a",
"slice",
"or",
"array",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L300-L307
|
16,509 |
tyler-sommer/stick
|
value.go
|
IsMap
|
func IsMap(val Value) bool {
r := reflect.Indirect(reflect.ValueOf(val))
return r.Kind() == reflect.Map
}
|
go
|
func IsMap(val Value) bool {
r := reflect.Indirect(reflect.ValueOf(val))
return r.Kind() == reflect.Map
}
|
[
"func",
"IsMap",
"(",
"val",
"Value",
")",
"bool",
"{",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
")",
"\n",
"return",
"r",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Map",
"\n",
"}"
] |
// IsMap returns true if the given Value is a map.
|
[
"IsMap",
"returns",
"true",
"if",
"the",
"given",
"Value",
"is",
"a",
"map",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L310-L313
|
16,510 |
tyler-sommer/stick
|
value.go
|
IsIterable
|
func IsIterable(val Value) bool {
if val == nil {
return true
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array, reflect.Map:
return true
}
return false
}
|
go
|
func IsIterable(val Value) bool {
if val == nil {
return true
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array, reflect.Map:
return true
}
return false
}
|
[
"func",
"IsIterable",
"(",
"val",
"Value",
")",
"bool",
"{",
"if",
"val",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
")",
"\n",
"switch",
"r",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Map",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsIterable returns true if the given Value is a slice, array, or map.
|
[
"IsIterable",
"returns",
"true",
"if",
"the",
"given",
"Value",
"is",
"a",
"slice",
"array",
"or",
"map",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L316-L326
|
16,511 |
tyler-sommer/stick
|
value.go
|
Iterate
|
func Iterate(val Value, it Iteratee) (int, error) {
if val == nil {
return 0, nil
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array:
ln := r.Len()
l := Loop{ln == 1, 1, 0}
for i := 0; i < ln; i++ {
v := r.Index(i)
brk, err := it(i, v.Interface(), l)
if brk || err != nil {
return i + 1, err
}
l.Index++
l.Index0++
l.Last = ln == l.Index
}
return ln, nil
case reflect.Map:
keys := r.MapKeys()
ln := r.Len()
l := Loop{ln == 1, 1, 0}
for i, k := range keys {
v := r.MapIndex(k)
brk, err := it(k.Interface(), v.Interface(), l)
if brk || err != nil {
return i + 1, err
}
l.Index++
l.Index0++
l.Last = ln == l.Index
}
return ln, nil
default:
return 0, fmt.Errorf(`stick: unable to iterate over %s "%v"`, r.Kind(), val)
}
}
|
go
|
func Iterate(val Value, it Iteratee) (int, error) {
if val == nil {
return 0, nil
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array:
ln := r.Len()
l := Loop{ln == 1, 1, 0}
for i := 0; i < ln; i++ {
v := r.Index(i)
brk, err := it(i, v.Interface(), l)
if brk || err != nil {
return i + 1, err
}
l.Index++
l.Index0++
l.Last = ln == l.Index
}
return ln, nil
case reflect.Map:
keys := r.MapKeys()
ln := r.Len()
l := Loop{ln == 1, 1, 0}
for i, k := range keys {
v := r.MapIndex(k)
brk, err := it(k.Interface(), v.Interface(), l)
if brk || err != nil {
return i + 1, err
}
l.Index++
l.Index0++
l.Last = ln == l.Index
}
return ln, nil
default:
return 0, fmt.Errorf(`stick: unable to iterate over %s "%v"`, r.Kind(), val)
}
}
|
[
"func",
"Iterate",
"(",
"val",
"Value",
",",
"it",
"Iteratee",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"val",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
")",
"\n",
"switch",
"r",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
":",
"ln",
":=",
"r",
".",
"Len",
"(",
")",
"\n",
"l",
":=",
"Loop",
"{",
"ln",
"==",
"1",
",",
"1",
",",
"0",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"ln",
";",
"i",
"++",
"{",
"v",
":=",
"r",
".",
"Index",
"(",
"i",
")",
"\n",
"brk",
",",
"err",
":=",
"it",
"(",
"i",
",",
"v",
".",
"Interface",
"(",
")",
",",
"l",
")",
"\n",
"if",
"brk",
"||",
"err",
"!=",
"nil",
"{",
"return",
"i",
"+",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"l",
".",
"Index",
"++",
"\n",
"l",
".",
"Index0",
"++",
"\n",
"l",
".",
"Last",
"=",
"ln",
"==",
"l",
".",
"Index",
"\n",
"}",
"\n",
"return",
"ln",
",",
"nil",
"\n",
"case",
"reflect",
".",
"Map",
":",
"keys",
":=",
"r",
".",
"MapKeys",
"(",
")",
"\n",
"ln",
":=",
"r",
".",
"Len",
"(",
")",
"\n",
"l",
":=",
"Loop",
"{",
"ln",
"==",
"1",
",",
"1",
",",
"0",
"}",
"\n",
"for",
"i",
",",
"k",
":=",
"range",
"keys",
"{",
"v",
":=",
"r",
".",
"MapIndex",
"(",
"k",
")",
"\n",
"brk",
",",
"err",
":=",
"it",
"(",
"k",
".",
"Interface",
"(",
")",
",",
"v",
".",
"Interface",
"(",
")",
",",
"l",
")",
"\n",
"if",
"brk",
"||",
"err",
"!=",
"nil",
"{",
"return",
"i",
"+",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"l",
".",
"Index",
"++",
"\n",
"l",
".",
"Index0",
"++",
"\n",
"l",
".",
"Last",
"=",
"ln",
"==",
"l",
".",
"Index",
"\n",
"}",
"\n",
"return",
"ln",
",",
"nil",
"\n",
"default",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`stick: unable to iterate over %s \"%v\"`",
",",
"r",
".",
"Kind",
"(",
")",
",",
"val",
")",
"\n",
"}",
"\n",
"}"
] |
// Iterate calls the Iteratee func for every item in the Value.
|
[
"Iterate",
"calls",
"the",
"Iteratee",
"func",
"for",
"every",
"item",
"in",
"the",
"Value",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L329-L369
|
16,512 |
tyler-sommer/stick
|
value.go
|
Len
|
func Len(val Value) (int, error) {
if val == nil {
return 0, nil
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array, reflect.Map:
return r.Len(), nil
}
return 0, fmt.Errorf(`stick: could not get length of %s "%v"`, r.Kind(), val)
}
|
go
|
func Len(val Value) (int, error) {
if val == nil {
return 0, nil
}
r := reflect.Indirect(reflect.ValueOf(val))
switch r.Kind() {
case reflect.Slice, reflect.Array, reflect.Map:
return r.Len(), nil
}
return 0, fmt.Errorf(`stick: could not get length of %s "%v"`, r.Kind(), val)
}
|
[
"func",
"Len",
"(",
"val",
"Value",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"val",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"r",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
")",
"\n",
"switch",
"r",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Map",
":",
"return",
"r",
".",
"Len",
"(",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`stick: could not get length of %s \"%v\"`",
",",
"r",
".",
"Kind",
"(",
")",
",",
"val",
")",
"\n",
"}"
] |
// Len returns the length of Value.
|
[
"Len",
"returns",
"the",
"length",
"of",
"Value",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L372-L382
|
16,513 |
tyler-sommer/stick
|
value.go
|
Equal
|
func Equal(left Value, right Value) bool {
// TODO: Stop-gap for now, this will need to be much more sophisticated.
return CoerceString(left) == CoerceString(right)
}
|
go
|
func Equal(left Value, right Value) bool {
// TODO: Stop-gap for now, this will need to be much more sophisticated.
return CoerceString(left) == CoerceString(right)
}
|
[
"func",
"Equal",
"(",
"left",
"Value",
",",
"right",
"Value",
")",
"bool",
"{",
"// TODO: Stop-gap for now, this will need to be much more sophisticated.",
"return",
"CoerceString",
"(",
"left",
")",
"==",
"CoerceString",
"(",
"right",
")",
"\n",
"}"
] |
// Equal returns true if the two Values are considered equal.
|
[
"Equal",
"returns",
"true",
"if",
"the",
"two",
"Values",
"are",
"considered",
"equal",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L385-L388
|
16,514 |
tyler-sommer/stick
|
value.go
|
Contains
|
func Contains(haystack Value, needle Value) (bool, error) {
res := false
_, err := Iterate(haystack, func(k Value, v Value, l Loop) (bool, error) {
if Equal(v, needle) {
res = true
return true, nil // break
}
return false, nil
})
if err != nil {
return false, err
}
return res, nil
}
|
go
|
func Contains(haystack Value, needle Value) (bool, error) {
res := false
_, err := Iterate(haystack, func(k Value, v Value, l Loop) (bool, error) {
if Equal(v, needle) {
res = true
return true, nil // break
}
return false, nil
})
if err != nil {
return false, err
}
return res, nil
}
|
[
"func",
"Contains",
"(",
"haystack",
"Value",
",",
"needle",
"Value",
")",
"(",
"bool",
",",
"error",
")",
"{",
"res",
":=",
"false",
"\n",
"_",
",",
"err",
":=",
"Iterate",
"(",
"haystack",
",",
"func",
"(",
"k",
"Value",
",",
"v",
"Value",
",",
"l",
"Loop",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"Equal",
"(",
"v",
",",
"needle",
")",
"{",
"res",
"=",
"true",
"\n",
"return",
"true",
",",
"nil",
"// break",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// Contains returns true if the haystack Value contains needle.
|
[
"Contains",
"returns",
"true",
"if",
"the",
"haystack",
"Value",
"contains",
"needle",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/value.go#L391-L404
|
16,515 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (p Pos) String() string {
return fmt.Sprintf("%d:%d", p.Line, p.Offset)
}
|
go
|
func (p Pos) String() string {
return fmt.Sprintf("%d:%d", p.Line, p.Offset)
}
|
[
"func",
"(",
"p",
"Pos",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"Line",
",",
"p",
".",
"Offset",
")",
"\n",
"}"
] |
// String returns a string representation of a pos.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"pos",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L35-L37
|
16,516 |
tyler-sommer/stick
|
parse/node.go
|
NewModuleNode
|
func NewModuleNode(name string, nodes ...Node) *ModuleNode {
return &ModuleNode{NewBodyNode(Pos{1, 0}, nodes...), nil, name}
}
|
go
|
func NewModuleNode(name string, nodes ...Node) *ModuleNode {
return &ModuleNode{NewBodyNode(Pos{1, 0}, nodes...), nil, name}
}
|
[
"func",
"NewModuleNode",
"(",
"name",
"string",
",",
"nodes",
"...",
"Node",
")",
"*",
"ModuleNode",
"{",
"return",
"&",
"ModuleNode",
"{",
"NewBodyNode",
"(",
"Pos",
"{",
"1",
",",
"0",
"}",
",",
"nodes",
"...",
")",
",",
"nil",
",",
"name",
"}",
"\n",
"}"
] |
// NewModuleNode returns a ModuleNode.
|
[
"NewModuleNode",
"returns",
"a",
"ModuleNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L47-L49
|
16,517 |
tyler-sommer/stick
|
parse/node.go
|
Append
|
func (l *BodyNode) Append(n Node) {
l.Nodes = append(l.Nodes, n)
}
|
go
|
func (l *BodyNode) Append(n Node) {
l.Nodes = append(l.Nodes, n)
}
|
[
"func",
"(",
"l",
"*",
"BodyNode",
")",
"Append",
"(",
"n",
"Node",
")",
"{",
"l",
".",
"Nodes",
"=",
"append",
"(",
"l",
".",
"Nodes",
",",
"n",
")",
"\n",
"}"
] |
// Append a Node to the BodyNode.
|
[
"Append",
"a",
"Node",
"to",
"the",
"BodyNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L68-L70
|
16,518 |
tyler-sommer/stick
|
parse/node.go
|
NewCommentNode
|
func NewCommentNode(data string, p Pos) *CommentNode {
return &CommentNode{NewTextNode(data, p), TrimmableNode{}}
}
|
go
|
func NewCommentNode(data string, p Pos) *CommentNode {
return &CommentNode{NewTextNode(data, p), TrimmableNode{}}
}
|
[
"func",
"NewCommentNode",
"(",
"data",
"string",
",",
"p",
"Pos",
")",
"*",
"CommentNode",
"{",
"return",
"&",
"CommentNode",
"{",
"NewTextNode",
"(",
"data",
",",
"p",
")",
",",
"TrimmableNode",
"{",
"}",
"}",
"\n",
"}"
] |
// NewCommentNode returns a CommentNode.
|
[
"NewCommentNode",
"returns",
"a",
"CommentNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L110-L112
|
16,519 |
tyler-sommer/stick
|
parse/node.go
|
NewPrintNode
|
func NewPrintNode(exp Expr, p Pos) *PrintNode {
return &PrintNode{p, TrimmableNode{}, exp}
}
|
go
|
func NewPrintNode(exp Expr, p Pos) *PrintNode {
return &PrintNode{p, TrimmableNode{}, exp}
}
|
[
"func",
"NewPrintNode",
"(",
"exp",
"Expr",
",",
"p",
"Pos",
")",
"*",
"PrintNode",
"{",
"return",
"&",
"PrintNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"exp",
"}",
"\n",
"}"
] |
// NewPrintNode returns a PrintNode.
|
[
"NewPrintNode",
"returns",
"a",
"PrintNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L122-L124
|
16,520 |
tyler-sommer/stick
|
parse/node.go
|
NewBlockNode
|
func NewBlockNode(name string, body Node, p Pos) *BlockNode {
return &BlockNode{p, TrimmableNode{}, name, body, ""}
}
|
go
|
func NewBlockNode(name string, body Node, p Pos) *BlockNode {
return &BlockNode{p, TrimmableNode{}, name, body, ""}
}
|
[
"func",
"NewBlockNode",
"(",
"name",
"string",
",",
"body",
"Node",
",",
"p",
"Pos",
")",
"*",
"BlockNode",
"{",
"return",
"&",
"BlockNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"name",
",",
"body",
",",
"\"",
"\"",
"}",
"\n",
"}"
] |
// NewBlockNode returns a BlockNode.
|
[
"NewBlockNode",
"returns",
"a",
"BlockNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L146-L148
|
16,521 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *BlockNode) String() string {
return fmt.Sprintf("Block(%s: %s)", t.Name, t.Body)
}
|
go
|
func (t *BlockNode) String() string {
return fmt.Sprintf("Block(%s: %s)", t.Name, t.Body)
}
|
[
"func",
"(",
"t",
"*",
"BlockNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Name",
",",
"t",
".",
"Body",
")",
"\n",
"}"
] |
// String returns a string representation of a BlockNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"BlockNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L151-L153
|
16,522 |
tyler-sommer/stick
|
parse/node.go
|
NewIfNode
|
func NewIfNode(cond Expr, body Node, els Node, p Pos) *IfNode {
return &IfNode{p, TrimmableNode{}, cond, body, els}
}
|
go
|
func NewIfNode(cond Expr, body Node, els Node, p Pos) *IfNode {
return &IfNode{p, TrimmableNode{}, cond, body, els}
}
|
[
"func",
"NewIfNode",
"(",
"cond",
"Expr",
",",
"body",
"Node",
",",
"els",
"Node",
",",
"p",
"Pos",
")",
"*",
"IfNode",
"{",
"return",
"&",
"IfNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"cond",
",",
"body",
",",
"els",
"}",
"\n",
"}"
] |
// NewIfNode returns a IfNode.
|
[
"NewIfNode",
"returns",
"a",
"IfNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L170-L172
|
16,523 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *IfNode) String() string {
return fmt.Sprintf("If(%s: %s Else: %s)", t.Cond, t.Body, t.Else)
}
|
go
|
func (t *IfNode) String() string {
return fmt.Sprintf("If(%s: %s Else: %s)", t.Cond, t.Body, t.Else)
}
|
[
"func",
"(",
"t",
"*",
"IfNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Cond",
",",
"t",
".",
"Body",
",",
"t",
".",
"Else",
")",
"\n",
"}"
] |
// String returns a string representation of an IfNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"an",
"IfNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L175-L177
|
16,524 |
tyler-sommer/stick
|
parse/node.go
|
All
|
func (t *IfNode) All() []Node {
return []Node{t.Cond, t.Body, t.Else}
}
|
go
|
func (t *IfNode) All() []Node {
return []Node{t.Cond, t.Body, t.Else}
}
|
[
"func",
"(",
"t",
"*",
"IfNode",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"return",
"[",
"]",
"Node",
"{",
"t",
".",
"Cond",
",",
"t",
".",
"Body",
",",
"t",
".",
"Else",
"}",
"\n",
"}"
] |
// All returns all the child Nodes in a IfNode.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"IfNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L180-L182
|
16,525 |
tyler-sommer/stick
|
parse/node.go
|
NewExtendsNode
|
func NewExtendsNode(tplRef Expr, p Pos) *ExtendsNode {
return &ExtendsNode{p, TrimmableNode{}, tplRef}
}
|
go
|
func NewExtendsNode(tplRef Expr, p Pos) *ExtendsNode {
return &ExtendsNode{p, TrimmableNode{}, tplRef}
}
|
[
"func",
"NewExtendsNode",
"(",
"tplRef",
"Expr",
",",
"p",
"Pos",
")",
"*",
"ExtendsNode",
"{",
"return",
"&",
"ExtendsNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"tplRef",
"}",
"\n",
"}"
] |
// NewExtendsNode returns a ExtendsNode.
|
[
"NewExtendsNode",
"returns",
"a",
"ExtendsNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L192-L194
|
16,526 |
tyler-sommer/stick
|
parse/node.go
|
NewForNode
|
func NewForNode(k, v string, expr Expr, body, els Node, p Pos) *ForNode {
return &ForNode{p, TrimmableNode{}, k, v, expr, body, els}
}
|
go
|
func NewForNode(k, v string, expr Expr, body, els Node, p Pos) *ForNode {
return &ForNode{p, TrimmableNode{}, k, v, expr, body, els}
}
|
[
"func",
"NewForNode",
"(",
"k",
",",
"v",
"string",
",",
"expr",
"Expr",
",",
"body",
",",
"els",
"Node",
",",
"p",
"Pos",
")",
"*",
"ForNode",
"{",
"return",
"&",
"ForNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"k",
",",
"v",
",",
"expr",
",",
"body",
",",
"els",
"}",
"\n",
"}"
] |
// NewForNode returns a ForNode.
|
[
"NewForNode",
"returns",
"a",
"ForNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L218-L220
|
16,527 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *ForNode) String() string {
return fmt.Sprintf("For(%s, %s in %s: %s else %s)", t.Key, t.Val, t.X, t.Body, t.Else)
}
|
go
|
func (t *ForNode) String() string {
return fmt.Sprintf("For(%s, %s in %s: %s else %s)", t.Key, t.Val, t.X, t.Body, t.Else)
}
|
[
"func",
"(",
"t",
"*",
"ForNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Key",
",",
"t",
".",
"Val",
",",
"t",
".",
"X",
",",
"t",
".",
"Body",
",",
"t",
".",
"Else",
")",
"\n",
"}"
] |
// String returns a string representation of a ForNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"ForNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L223-L225
|
16,528 |
tyler-sommer/stick
|
parse/node.go
|
All
|
func (t *ForNode) All() []Node {
return []Node{t.X, t.Body, t.Else}
}
|
go
|
func (t *ForNode) All() []Node {
return []Node{t.X, t.Body, t.Else}
}
|
[
"func",
"(",
"t",
"*",
"ForNode",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"return",
"[",
"]",
"Node",
"{",
"t",
".",
"X",
",",
"t",
".",
"Body",
",",
"t",
".",
"Else",
"}",
"\n",
"}"
] |
// All returns all the child Nodes in a ForNode.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"ForNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L228-L230
|
16,529 |
tyler-sommer/stick
|
parse/node.go
|
NewIncludeNode
|
func NewIncludeNode(tmpl Expr, with Expr, only bool, pos Pos) *IncludeNode {
return &IncludeNode{pos, TrimmableNode{}, tmpl, with, only}
}
|
go
|
func NewIncludeNode(tmpl Expr, with Expr, only bool, pos Pos) *IncludeNode {
return &IncludeNode{pos, TrimmableNode{}, tmpl, with, only}
}
|
[
"func",
"NewIncludeNode",
"(",
"tmpl",
"Expr",
",",
"with",
"Expr",
",",
"only",
"bool",
",",
"pos",
"Pos",
")",
"*",
"IncludeNode",
"{",
"return",
"&",
"IncludeNode",
"{",
"pos",
",",
"TrimmableNode",
"{",
"}",
",",
"tmpl",
",",
"with",
",",
"only",
"}",
"\n",
"}"
] |
// NewIncludeNode returns a IncludeNode.
|
[
"NewIncludeNode",
"returns",
"a",
"IncludeNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L242-L244
|
16,530 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *IncludeNode) String() string {
return fmt.Sprintf("Include(%s with %s %v)", t.Tpl, t.With, t.Only)
}
|
go
|
func (t *IncludeNode) String() string {
return fmt.Sprintf("Include(%s with %s %v)", t.Tpl, t.With, t.Only)
}
|
[
"func",
"(",
"t",
"*",
"IncludeNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
",",
"t",
".",
"With",
",",
"t",
".",
"Only",
")",
"\n",
"}"
] |
// String returns a string representation of an IncludeNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"an",
"IncludeNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L247-L249
|
16,531 |
tyler-sommer/stick
|
parse/node.go
|
NewEmbedNode
|
func NewEmbedNode(tmpl Expr, with Expr, only bool, blocks map[string]*BlockNode, pos Pos) *EmbedNode {
return &EmbedNode{NewIncludeNode(tmpl, with, only, pos), blocks}
}
|
go
|
func NewEmbedNode(tmpl Expr, with Expr, only bool, blocks map[string]*BlockNode, pos Pos) *EmbedNode {
return &EmbedNode{NewIncludeNode(tmpl, with, only, pos), blocks}
}
|
[
"func",
"NewEmbedNode",
"(",
"tmpl",
"Expr",
",",
"with",
"Expr",
",",
"only",
"bool",
",",
"blocks",
"map",
"[",
"string",
"]",
"*",
"BlockNode",
",",
"pos",
"Pos",
")",
"*",
"EmbedNode",
"{",
"return",
"&",
"EmbedNode",
"{",
"NewIncludeNode",
"(",
"tmpl",
",",
"with",
",",
"only",
",",
"pos",
")",
",",
"blocks",
"}",
"\n",
"}"
] |
// NewEmbedNode returns a EmbedNode.
|
[
"NewEmbedNode",
"returns",
"a",
"EmbedNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L263-L265
|
16,532 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *EmbedNode) String() string {
return fmt.Sprintf("Embed(%s with %s %v: %v)", t.Tpl, t.With, t.Only, t.Blocks)
}
|
go
|
func (t *EmbedNode) String() string {
return fmt.Sprintf("Embed(%s with %s %v: %v)", t.Tpl, t.With, t.Only, t.Blocks)
}
|
[
"func",
"(",
"t",
"*",
"EmbedNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
",",
"t",
".",
"With",
",",
"t",
".",
"Only",
",",
"t",
".",
"Blocks",
")",
"\n",
"}"
] |
// String returns a string representation of an EmbedNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"an",
"EmbedNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L268-L270
|
16,533 |
tyler-sommer/stick
|
parse/node.go
|
All
|
func (t *EmbedNode) All() []Node {
r := t.IncludeNode.All()
for _, blk := range t.Blocks {
r = append(r, blk)
}
return r
}
|
go
|
func (t *EmbedNode) All() []Node {
r := t.IncludeNode.All()
for _, blk := range t.Blocks {
r = append(r, blk)
}
return r
}
|
[
"func",
"(",
"t",
"*",
"EmbedNode",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"r",
":=",
"t",
".",
"IncludeNode",
".",
"All",
"(",
")",
"\n",
"for",
"_",
",",
"blk",
":=",
"range",
"t",
".",
"Blocks",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"blk",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// All returns all the child Nodes in a EmbedNode.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"EmbedNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L273-L279
|
16,534 |
tyler-sommer/stick
|
parse/node.go
|
NewUseNode
|
func NewUseNode(tpl Expr, aliases map[string]string, pos Pos) *UseNode {
return &UseNode{pos, TrimmableNode{}, tpl, aliases}
}
|
go
|
func NewUseNode(tpl Expr, aliases map[string]string, pos Pos) *UseNode {
return &UseNode{pos, TrimmableNode{}, tpl, aliases}
}
|
[
"func",
"NewUseNode",
"(",
"tpl",
"Expr",
",",
"aliases",
"map",
"[",
"string",
"]",
"string",
",",
"pos",
"Pos",
")",
"*",
"UseNode",
"{",
"return",
"&",
"UseNode",
"{",
"pos",
",",
"TrimmableNode",
"{",
"}",
",",
"tpl",
",",
"aliases",
"}",
"\n",
"}"
] |
// NewUseNode returns a UseNode.
|
[
"NewUseNode",
"returns",
"a",
"UseNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L292-L294
|
16,535 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *UseNode) String() string {
if l := len(t.Aliases); l > 0 {
keys := make([]string, l)
i := 0
for orig := range t.Aliases {
keys[i] = orig
i++
}
sort.Strings(keys)
res := make([]string, l)
for i, orig := range keys {
res[i] = orig + ": " + t.Aliases[orig]
}
return fmt.Sprintf("Use(%s with %s)", t.Tpl, strings.Join(res, ", "))
}
return fmt.Sprintf("Use(%s)", t.Tpl)
}
|
go
|
func (t *UseNode) String() string {
if l := len(t.Aliases); l > 0 {
keys := make([]string, l)
i := 0
for orig := range t.Aliases {
keys[i] = orig
i++
}
sort.Strings(keys)
res := make([]string, l)
for i, orig := range keys {
res[i] = orig + ": " + t.Aliases[orig]
}
return fmt.Sprintf("Use(%s with %s)", t.Tpl, strings.Join(res, ", "))
}
return fmt.Sprintf("Use(%s)", t.Tpl)
}
|
[
"func",
"(",
"t",
"*",
"UseNode",
")",
"String",
"(",
")",
"string",
"{",
"if",
"l",
":=",
"len",
"(",
"t",
".",
"Aliases",
")",
";",
"l",
">",
"0",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"l",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"orig",
":=",
"range",
"t",
".",
"Aliases",
"{",
"keys",
"[",
"i",
"]",
"=",
"orig",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"l",
")",
"\n",
"for",
"i",
",",
"orig",
":=",
"range",
"keys",
"{",
"res",
"[",
"i",
"]",
"=",
"orig",
"+",
"\"",
"\"",
"+",
"t",
".",
"Aliases",
"[",
"orig",
"]",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
",",
"strings",
".",
"Join",
"(",
"res",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
")",
"\n",
"}"
] |
// String returns a string representation of a UseNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"UseNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L297-L313
|
16,536 |
tyler-sommer/stick
|
parse/node.go
|
NewSetNode
|
func NewSetNode(varName string, expr Expr, pos Pos) *SetNode {
return &SetNode{pos, TrimmableNode{}, varName, expr}
}
|
go
|
func NewSetNode(varName string, expr Expr, pos Pos) *SetNode {
return &SetNode{pos, TrimmableNode{}, varName, expr}
}
|
[
"func",
"NewSetNode",
"(",
"varName",
"string",
",",
"expr",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"SetNode",
"{",
"return",
"&",
"SetNode",
"{",
"pos",
",",
"TrimmableNode",
"{",
"}",
",",
"varName",
",",
"expr",
"}",
"\n",
"}"
] |
// NewSetNode returns a SetNode.
|
[
"NewSetNode",
"returns",
"a",
"SetNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L329-L331
|
16,537 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *SetNode) String() string {
return fmt.Sprintf("Set(%s = %v)", t.Name, t.X)
}
|
go
|
func (t *SetNode) String() string {
return fmt.Sprintf("Set(%s = %v)", t.Name, t.X)
}
|
[
"func",
"(",
"t",
"*",
"SetNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Name",
",",
"t",
".",
"X",
")",
"\n",
"}"
] |
// String returns a string representation of an SetNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"an",
"SetNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L334-L336
|
16,538 |
tyler-sommer/stick
|
parse/node.go
|
NewDoNode
|
func NewDoNode(expr Expr, pos Pos) *DoNode {
return &DoNode{pos, TrimmableNode{}, expr}
}
|
go
|
func NewDoNode(expr Expr, pos Pos) *DoNode {
return &DoNode{pos, TrimmableNode{}, expr}
}
|
[
"func",
"NewDoNode",
"(",
"expr",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"DoNode",
"{",
"return",
"&",
"DoNode",
"{",
"pos",
",",
"TrimmableNode",
"{",
"}",
",",
"expr",
"}",
"\n",
"}"
] |
// NewDoNode returns a DoNode.
|
[
"NewDoNode",
"returns",
"a",
"DoNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L351-L353
|
16,539 |
tyler-sommer/stick
|
parse/node.go
|
NewFilterNode
|
func NewFilterNode(filters []string, body Node, p Pos) *FilterNode {
return &FilterNode{p, TrimmableNode{}, filters, body}
}
|
go
|
func NewFilterNode(filters []string, body Node, p Pos) *FilterNode {
return &FilterNode{p, TrimmableNode{}, filters, body}
}
|
[
"func",
"NewFilterNode",
"(",
"filters",
"[",
"]",
"string",
",",
"body",
"Node",
",",
"p",
"Pos",
")",
"*",
"FilterNode",
"{",
"return",
"&",
"FilterNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"filters",
",",
"body",
"}",
"\n",
"}"
] |
// NewFilterNode creates a FilterNode.
|
[
"NewFilterNode",
"creates",
"a",
"FilterNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L374-L376
|
16,540 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *FilterNode) String() string {
return fmt.Sprintf("Filter (%s): %s", strings.Join(t.Filters, "|"), t.Body)
}
|
go
|
func (t *FilterNode) String() string {
return fmt.Sprintf("Filter (%s): %s", strings.Join(t.Filters, "|"), t.Body)
}
|
[
"func",
"(",
"t",
"*",
"FilterNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"t",
".",
"Filters",
",",
"\"",
"\"",
")",
",",
"t",
".",
"Body",
")",
"\n",
"}"
] |
// String returns a string representation of a FilterNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"FilterNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L379-L381
|
16,541 |
tyler-sommer/stick
|
parse/node.go
|
NewMacroNode
|
func NewMacroNode(name string, args []string, body *BodyNode, p Pos) *MacroNode {
return &MacroNode{p, TrimmableNode{}, name, args, body, ""}
}
|
go
|
func NewMacroNode(name string, args []string, body *BodyNode, p Pos) *MacroNode {
return &MacroNode{p, TrimmableNode{}, name, args, body, ""}
}
|
[
"func",
"NewMacroNode",
"(",
"name",
"string",
",",
"args",
"[",
"]",
"string",
",",
"body",
"*",
"BodyNode",
",",
"p",
"Pos",
")",
"*",
"MacroNode",
"{",
"return",
"&",
"MacroNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"name",
",",
"args",
",",
"body",
",",
"\"",
"\"",
"}",
"\n",
"}"
] |
// NewMacroNode returns a MacroNode.
|
[
"NewMacroNode",
"returns",
"a",
"MacroNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L399-L401
|
16,542 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *MacroNode) String() string {
return fmt.Sprintf("Macro %s(%s): %s", t.Name, strings.Join(t.Args, ", "), t.Body)
}
|
go
|
func (t *MacroNode) String() string {
return fmt.Sprintf("Macro %s(%s): %s", t.Name, strings.Join(t.Args, ", "), t.Body)
}
|
[
"func",
"(",
"t",
"*",
"MacroNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Name",
",",
"strings",
".",
"Join",
"(",
"t",
".",
"Args",
",",
"\"",
"\"",
")",
",",
"t",
".",
"Body",
")",
"\n",
"}"
] |
// String returns a string representation of a MacroNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"MacroNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L404-L406
|
16,543 |
tyler-sommer/stick
|
parse/node.go
|
NewImportNode
|
func NewImportNode(tpl Expr, alias string, p Pos) *ImportNode {
return &ImportNode{p, TrimmableNode{}, tpl, alias}
}
|
go
|
func NewImportNode(tpl Expr, alias string, p Pos) *ImportNode {
return &ImportNode{p, TrimmableNode{}, tpl, alias}
}
|
[
"func",
"NewImportNode",
"(",
"tpl",
"Expr",
",",
"alias",
"string",
",",
"p",
"Pos",
")",
"*",
"ImportNode",
"{",
"return",
"&",
"ImportNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"tpl",
",",
"alias",
"}",
"\n",
"}"
] |
// NewImportNode returns a ImportNode.
|
[
"NewImportNode",
"returns",
"a",
"ImportNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L422-L424
|
16,544 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *ImportNode) String() string {
return fmt.Sprintf("Import (%s as %s)", t.Tpl, t.Alias)
}
|
go
|
func (t *ImportNode) String() string {
return fmt.Sprintf("Import (%s as %s)", t.Tpl, t.Alias)
}
|
[
"func",
"(",
"t",
"*",
"ImportNode",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
",",
"t",
".",
"Alias",
")",
"\n",
"}"
] |
// String returns a string representation of a ImportNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"ImportNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L427-L429
|
16,545 |
tyler-sommer/stick
|
parse/node.go
|
NewFromNode
|
func NewFromNode(tpl Expr, imports map[string]string, p Pos) *FromNode {
return &FromNode{p, TrimmableNode{}, tpl, imports}
}
|
go
|
func NewFromNode(tpl Expr, imports map[string]string, p Pos) *FromNode {
return &FromNode{p, TrimmableNode{}, tpl, imports}
}
|
[
"func",
"NewFromNode",
"(",
"tpl",
"Expr",
",",
"imports",
"map",
"[",
"string",
"]",
"string",
",",
"p",
"Pos",
")",
"*",
"FromNode",
"{",
"return",
"&",
"FromNode",
"{",
"p",
",",
"TrimmableNode",
"{",
"}",
",",
"tpl",
",",
"imports",
"}",
"\n",
"}"
] |
// NewFromNode returns a FromNode.
|
[
"NewFromNode",
"returns",
"a",
"FromNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L445-L447
|
16,546 |
tyler-sommer/stick
|
parse/node.go
|
String
|
func (t *FromNode) String() string {
keys := make([]string, len(t.Imports))
i := 0
for orig := range t.Imports {
keys[i] = orig
i++
}
sort.Strings(keys)
res := make([]string, len(t.Imports))
for i, orig := range keys {
if orig == t.Imports[orig] {
res[i] = orig
} else {
res[i] = orig + " as " + t.Imports[orig]
}
}
return fmt.Sprintf("From %s import %s", t.Tpl, strings.Join(res, ", "))
}
|
go
|
func (t *FromNode) String() string {
keys := make([]string, len(t.Imports))
i := 0
for orig := range t.Imports {
keys[i] = orig
i++
}
sort.Strings(keys)
res := make([]string, len(t.Imports))
for i, orig := range keys {
if orig == t.Imports[orig] {
res[i] = orig
} else {
res[i] = orig + " as " + t.Imports[orig]
}
}
return fmt.Sprintf("From %s import %s", t.Tpl, strings.Join(res, ", "))
}
|
[
"func",
"(",
"t",
"*",
"FromNode",
")",
"String",
"(",
")",
"string",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"t",
".",
"Imports",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"orig",
":=",
"range",
"t",
".",
"Imports",
"{",
"keys",
"[",
"i",
"]",
"=",
"orig",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"t",
".",
"Imports",
")",
")",
"\n",
"for",
"i",
",",
"orig",
":=",
"range",
"keys",
"{",
"if",
"orig",
"==",
"t",
".",
"Imports",
"[",
"orig",
"]",
"{",
"res",
"[",
"i",
"]",
"=",
"orig",
"\n",
"}",
"else",
"{",
"res",
"[",
"i",
"]",
"=",
"orig",
"+",
"\"",
"\"",
"+",
"t",
".",
"Imports",
"[",
"orig",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Tpl",
",",
"strings",
".",
"Join",
"(",
"res",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// String returns a string representation of a FromNode.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"FromNode",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/node.go#L450-L467
|
16,547 |
tyler-sommer/stick
|
parse/expr.go
|
All
|
func (exp *FuncExpr) All() []Node {
res := make([]Node, len(exp.Args))
for i, n := range exp.Args {
res[i] = n
}
return res
}
|
go
|
func (exp *FuncExpr) All() []Node {
res := make([]Node, len(exp.Args))
for i, n := range exp.Args {
res[i] = n
}
return res
}
|
[
"func",
"(",
"exp",
"*",
"FuncExpr",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"res",
":=",
"make",
"(",
"[",
"]",
"Node",
",",
"len",
"(",
"exp",
".",
"Args",
")",
")",
"\n",
"for",
"i",
",",
"n",
":=",
"range",
"exp",
".",
"Args",
"{",
"res",
"[",
"i",
"]",
"=",
"n",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] |
// All returns all the child Nodes in a FuncExpr.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"FuncExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L125-L131
|
16,548 |
tyler-sommer/stick
|
parse/expr.go
|
NewFuncExpr
|
func NewFuncExpr(name string, args []Expr, pos Pos) *FuncExpr {
return &FuncExpr{pos, name, args}
}
|
go
|
func NewFuncExpr(name string, args []Expr, pos Pos) *FuncExpr {
return &FuncExpr{pos, name, args}
}
|
[
"func",
"NewFuncExpr",
"(",
"name",
"string",
",",
"args",
"[",
"]",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"FuncExpr",
"{",
"return",
"&",
"FuncExpr",
"{",
"pos",
",",
"name",
",",
"args",
"}",
"\n",
"}"
] |
// NewFuncExpr returns a FuncExpr.
|
[
"NewFuncExpr",
"returns",
"a",
"FuncExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L134-L136
|
16,549 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *FuncExpr) String() string {
return fmt.Sprintf("FuncExpr(%s, %s)", exp.Name, exp.Args)
}
|
go
|
func (exp *FuncExpr) String() string {
return fmt.Sprintf("FuncExpr(%s, %s)", exp.Name, exp.Args)
}
|
[
"func",
"(",
"exp",
"*",
"FuncExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Name",
",",
"exp",
".",
"Args",
")",
"\n",
"}"
] |
// String returns a string representation of a FuncExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"FuncExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L139-L141
|
16,550 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *FilterExpr) String() string {
return fmt.Sprintf("FilterExpr(%s, %s)", exp.Name, exp.Args)
}
|
go
|
func (exp *FilterExpr) String() string {
return fmt.Sprintf("FilterExpr(%s, %s)", exp.Name, exp.Args)
}
|
[
"func",
"(",
"exp",
"*",
"FilterExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Name",
",",
"exp",
".",
"Args",
")",
"\n",
"}"
] |
// String returns a string representation of the FilterExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"FilterExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L149-L151
|
16,551 |
tyler-sommer/stick
|
parse/expr.go
|
NewFilterExpr
|
func NewFilterExpr(name string, args []Expr, pos Pos) *FilterExpr {
return &FilterExpr{NewFuncExpr(name, args, pos)}
}
|
go
|
func NewFilterExpr(name string, args []Expr, pos Pos) *FilterExpr {
return &FilterExpr{NewFuncExpr(name, args, pos)}
}
|
[
"func",
"NewFilterExpr",
"(",
"name",
"string",
",",
"args",
"[",
"]",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"FilterExpr",
"{",
"return",
"&",
"FilterExpr",
"{",
"NewFuncExpr",
"(",
"name",
",",
"args",
",",
"pos",
")",
"}",
"\n",
"}"
] |
// NewFilterExpr returns a FilterExpr.
|
[
"NewFilterExpr",
"returns",
"a",
"FilterExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L154-L156
|
16,552 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *TestExpr) String() string {
return fmt.Sprintf("TestExpr(%s, %s)", exp.Name, exp.Args)
}
|
go
|
func (exp *TestExpr) String() string {
return fmt.Sprintf("TestExpr(%s, %s)", exp.Name, exp.Args)
}
|
[
"func",
"(",
"exp",
"*",
"TestExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Name",
",",
"exp",
".",
"Args",
")",
"\n",
"}"
] |
// String returns a string representation of the TestExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"TestExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L164-L166
|
16,553 |
tyler-sommer/stick
|
parse/expr.go
|
NewBinaryExpr
|
func NewBinaryExpr(left Expr, op string, right Expr, pos Pos) *BinaryExpr {
return &BinaryExpr{pos, left, op, right}
}
|
go
|
func NewBinaryExpr(left Expr, op string, right Expr, pos Pos) *BinaryExpr {
return &BinaryExpr{pos, left, op, right}
}
|
[
"func",
"NewBinaryExpr",
"(",
"left",
"Expr",
",",
"op",
"string",
",",
"right",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"BinaryExpr",
"{",
"return",
"&",
"BinaryExpr",
"{",
"pos",
",",
"left",
",",
"op",
",",
"right",
"}",
"\n",
"}"
] |
// NewBinaryExpr returns a BinaryExpr.
|
[
"NewBinaryExpr",
"returns",
"a",
"BinaryExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L182-L184
|
16,554 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *BinaryExpr) String() string {
return fmt.Sprintf("BinaryExpr(%s %s %s)", exp.Left, exp.Op, exp.Right)
}
|
go
|
func (exp *BinaryExpr) String() string {
return fmt.Sprintf("BinaryExpr(%s %s %s)", exp.Left, exp.Op, exp.Right)
}
|
[
"func",
"(",
"exp",
"*",
"BinaryExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Left",
",",
"exp",
".",
"Op",
",",
"exp",
".",
"Right",
")",
"\n",
"}"
] |
// String returns a string representation of the BinaryExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"BinaryExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L192-L194
|
16,555 |
tyler-sommer/stick
|
parse/expr.go
|
NewUnaryExpr
|
func NewUnaryExpr(op string, expr Expr, pos Pos) *UnaryExpr {
return &UnaryExpr{pos, op, expr}
}
|
go
|
func NewUnaryExpr(op string, expr Expr, pos Pos) *UnaryExpr {
return &UnaryExpr{pos, op, expr}
}
|
[
"func",
"NewUnaryExpr",
"(",
"op",
"string",
",",
"expr",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"UnaryExpr",
"{",
"return",
"&",
"UnaryExpr",
"{",
"pos",
",",
"op",
",",
"expr",
"}",
"\n",
"}"
] |
// NewUnaryExpr returns a new UnaryExpr.
|
[
"NewUnaryExpr",
"returns",
"a",
"new",
"UnaryExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L204-L206
|
16,556 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *UnaryExpr) String() string {
return fmt.Sprintf("UnaryExpr(%s %s)", exp.Op, exp.X)
}
|
go
|
func (exp *UnaryExpr) String() string {
return fmt.Sprintf("UnaryExpr(%s %s)", exp.Op, exp.X)
}
|
[
"func",
"(",
"exp",
"*",
"UnaryExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Op",
",",
"exp",
".",
"X",
")",
"\n",
"}"
] |
// String returns a string representation of a UnaryExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"UnaryExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L214-L216
|
16,557 |
tyler-sommer/stick
|
parse/expr.go
|
NewGetAttrExpr
|
func NewGetAttrExpr(cont Expr, attr Expr, args []Expr, pos Pos) *GetAttrExpr {
return &GetAttrExpr{pos, cont, attr, args}
}
|
go
|
func NewGetAttrExpr(cont Expr, attr Expr, args []Expr, pos Pos) *GetAttrExpr {
return &GetAttrExpr{pos, cont, attr, args}
}
|
[
"func",
"NewGetAttrExpr",
"(",
"cont",
"Expr",
",",
"attr",
"Expr",
",",
"args",
"[",
"]",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"GetAttrExpr",
"{",
"return",
"&",
"GetAttrExpr",
"{",
"pos",
",",
"cont",
",",
"attr",
",",
"args",
"}",
"\n",
"}"
] |
// NewGetAttrExpr returns a GetAttrExpr.
|
[
"NewGetAttrExpr",
"returns",
"a",
"GetAttrExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L248-L250
|
16,558 |
tyler-sommer/stick
|
parse/expr.go
|
All
|
func (exp *GetAttrExpr) All() []Node {
res := []Node{exp.Cont, exp.Attr}
for _, v := range exp.Args {
res = append(res, v)
}
return res
}
|
go
|
func (exp *GetAttrExpr) All() []Node {
res := []Node{exp.Cont, exp.Attr}
for _, v := range exp.Args {
res = append(res, v)
}
return res
}
|
[
"func",
"(",
"exp",
"*",
"GetAttrExpr",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"res",
":=",
"[",
"]",
"Node",
"{",
"exp",
".",
"Cont",
",",
"exp",
".",
"Attr",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"exp",
".",
"Args",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] |
// All returns all the child Nodes in a GetAttrExpr.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"GetAttrExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L253-L259
|
16,559 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *GetAttrExpr) String() string {
if len(exp.Args) > 0 {
return fmt.Sprintf("GetAttrExpr(%s -> %s %v)", exp.Cont, exp.Attr, exp.Args)
}
return fmt.Sprintf("GetAttrExpr(%s -> %s)", exp.Cont, exp.Attr)
}
|
go
|
func (exp *GetAttrExpr) String() string {
if len(exp.Args) > 0 {
return fmt.Sprintf("GetAttrExpr(%s -> %s %v)", exp.Cont, exp.Attr, exp.Args)
}
return fmt.Sprintf("GetAttrExpr(%s -> %s)", exp.Cont, exp.Attr)
}
|
[
"func",
"(",
"exp",
"*",
"GetAttrExpr",
")",
"String",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"exp",
".",
"Args",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Cont",
",",
"exp",
".",
"Attr",
",",
"exp",
".",
"Args",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Cont",
",",
"exp",
".",
"Attr",
")",
"\n",
"}"
] |
// String returns a string representation of a GetAttrExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"GetAttrExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L262-L267
|
16,560 |
tyler-sommer/stick
|
parse/expr.go
|
NewTernaryIfExpr
|
func NewTernaryIfExpr(cond, tx, fx Expr, pos Pos) *TernaryIfExpr {
return &TernaryIfExpr{pos, cond, tx, fx}
}
|
go
|
func NewTernaryIfExpr(cond, tx, fx Expr, pos Pos) *TernaryIfExpr {
return &TernaryIfExpr{pos, cond, tx, fx}
}
|
[
"func",
"NewTernaryIfExpr",
"(",
"cond",
",",
"tx",
",",
"fx",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"TernaryIfExpr",
"{",
"return",
"&",
"TernaryIfExpr",
"{",
"pos",
",",
"cond",
",",
"tx",
",",
"fx",
"}",
"\n",
"}"
] |
// NewTernaryIfExpr returns a TernaryIfExpr.
|
[
"NewTernaryIfExpr",
"returns",
"a",
"TernaryIfExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L278-L280
|
16,561 |
tyler-sommer/stick
|
parse/expr.go
|
All
|
func (exp *TernaryIfExpr) All() []Node {
return []Node{exp.Cond, exp.TrueX, exp.FalseX}
}
|
go
|
func (exp *TernaryIfExpr) All() []Node {
return []Node{exp.Cond, exp.TrueX, exp.FalseX}
}
|
[
"func",
"(",
"exp",
"*",
"TernaryIfExpr",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"return",
"[",
"]",
"Node",
"{",
"exp",
".",
"Cond",
",",
"exp",
".",
"TrueX",
",",
"exp",
".",
"FalseX",
"}",
"\n",
"}"
] |
// All returns all the child Nodes in a TernaryIfExpr.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"TernaryIfExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L283-L285
|
16,562 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *TernaryIfExpr) String() string {
return fmt.Sprintf("%s ? %s : %v", exp.Cond, exp.TrueX, exp.FalseX)
}
|
go
|
func (exp *TernaryIfExpr) String() string {
return fmt.Sprintf("%s ? %s : %v", exp.Cond, exp.TrueX, exp.FalseX)
}
|
[
"func",
"(",
"exp",
"*",
"TernaryIfExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Cond",
",",
"exp",
".",
"TrueX",
",",
"exp",
".",
"FalseX",
")",
"\n",
"}"
] |
// String returns a string representation of a TernaryIfExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"TernaryIfExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L288-L290
|
16,563 |
tyler-sommer/stick
|
parse/expr.go
|
NewKeyValueExpr
|
func NewKeyValueExpr(k, v Expr, pos Pos) *KeyValueExpr {
return &KeyValueExpr{pos, k, v}
}
|
go
|
func NewKeyValueExpr(k, v Expr, pos Pos) *KeyValueExpr {
return &KeyValueExpr{pos, k, v}
}
|
[
"func",
"NewKeyValueExpr",
"(",
"k",
",",
"v",
"Expr",
",",
"pos",
"Pos",
")",
"*",
"KeyValueExpr",
"{",
"return",
"&",
"KeyValueExpr",
"{",
"pos",
",",
"k",
",",
"v",
"}",
"\n",
"}"
] |
// NewKeyValueExpr returns a KeyValueExpr.
|
[
"NewKeyValueExpr",
"returns",
"a",
"KeyValueExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L299-L301
|
16,564 |
tyler-sommer/stick
|
parse/expr.go
|
String
|
func (exp *KeyValueExpr) String() string {
return fmt.Sprintf("%s: %s", exp.Key, exp.Value)
}
|
go
|
func (exp *KeyValueExpr) String() string {
return fmt.Sprintf("%s: %s", exp.Key, exp.Value)
}
|
[
"func",
"(",
"exp",
"*",
"KeyValueExpr",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"exp",
".",
"Key",
",",
"exp",
".",
"Value",
")",
"\n",
"}"
] |
// String returns a string representation of a KeyValueExpr.
|
[
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"KeyValueExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L309-L311
|
16,565 |
tyler-sommer/stick
|
parse/expr.go
|
All
|
func (exp *ArrayExpr) All() []Node {
all := make([]Node, len(exp.Elements))
for i, v := range exp.Elements {
all[i] = v
}
return all
}
|
go
|
func (exp *ArrayExpr) All() []Node {
all := make([]Node, len(exp.Elements))
for i, v := range exp.Elements {
all[i] = v
}
return all
}
|
[
"func",
"(",
"exp",
"*",
"ArrayExpr",
")",
"All",
"(",
")",
"[",
"]",
"Node",
"{",
"all",
":=",
"make",
"(",
"[",
"]",
"Node",
",",
"len",
"(",
"exp",
".",
"Elements",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"exp",
".",
"Elements",
"{",
"all",
"[",
"i",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"all",
"\n",
"}"
] |
// All returns all the child Nodes in a ArrayExpr.
|
[
"All",
"returns",
"all",
"the",
"child",
"Nodes",
"in",
"a",
"ArrayExpr",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/expr.go#L348-L354
|
16,566 |
tyler-sommer/stick
|
stick.go
|
New
|
func New(loader Loader) *Env {
if loader == nil {
loader = &StringLoader{}
}
return &Env{loader, make(map[string]Func), make(map[string]Filter), make(map[string]Test), make([]parse.NodeVisitor, 0)}
}
|
go
|
func New(loader Loader) *Env {
if loader == nil {
loader = &StringLoader{}
}
return &Env{loader, make(map[string]Func), make(map[string]Filter), make(map[string]Test), make([]parse.NodeVisitor, 0)}
}
|
[
"func",
"New",
"(",
"loader",
"Loader",
")",
"*",
"Env",
"{",
"if",
"loader",
"==",
"nil",
"{",
"loader",
"=",
"&",
"StringLoader",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Env",
"{",
"loader",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"Func",
")",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"Filter",
")",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"Test",
")",
",",
"make",
"(",
"[",
"]",
"parse",
".",
"NodeVisitor",
",",
"0",
")",
"}",
"\n",
"}"
] |
// New creates an empty Env.
// If nil is passed as loader, a StringLoader is used.
|
[
"New",
"creates",
"an",
"empty",
"Env",
".",
"If",
"nil",
"is",
"passed",
"as",
"loader",
"a",
"StringLoader",
"is",
"used",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/stick.go#L84-L89
|
16,567 |
tyler-sommer/stick
|
stick.go
|
Execute
|
func (env *Env) Execute(tpl string, out io.Writer, ctx map[string]Value) error {
return execute(tpl, out, ctx, env)
}
|
go
|
func (env *Env) Execute(tpl string, out io.Writer, ctx map[string]Value) error {
return execute(tpl, out, ctx, env)
}
|
[
"func",
"(",
"env",
"*",
"Env",
")",
"Execute",
"(",
"tpl",
"string",
",",
"out",
"io",
".",
"Writer",
",",
"ctx",
"map",
"[",
"string",
"]",
"Value",
")",
"error",
"{",
"return",
"execute",
"(",
"tpl",
",",
"out",
",",
"ctx",
",",
"env",
")",
"\n",
"}"
] |
// Execute parses and executes the given template.
|
[
"Execute",
"parses",
"and",
"executes",
"the",
"given",
"template",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/stick.go#L97-L99
|
16,568 |
tyler-sommer/stick
|
stick.go
|
Parse
|
func (env *Env) Parse(name string) (*parse.Tree, error) {
return env.load(name)
}
|
go
|
func (env *Env) Parse(name string) (*parse.Tree, error) {
return env.load(name)
}
|
[
"func",
"(",
"env",
"*",
"Env",
")",
"Parse",
"(",
"name",
"string",
")",
"(",
"*",
"parse",
".",
"Tree",
",",
"error",
")",
"{",
"return",
"env",
".",
"load",
"(",
"name",
")",
"\n",
"}"
] |
// Parse loads and parses the given template.
|
[
"Parse",
"loads",
"and",
"parses",
"the",
"given",
"template",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/stick.go#L102-L104
|
16,569 |
tyler-sommer/stick
|
loader.go
|
Load
|
func (l *StringLoader) Load(name string) (Template, error) {
return &stringTemplate{name, name}, nil
}
|
go
|
func (l *StringLoader) Load(name string) (Template, error) {
return &stringTemplate{name, name}, nil
}
|
[
"func",
"(",
"l",
"*",
"StringLoader",
")",
"Load",
"(",
"name",
"string",
")",
"(",
"Template",
",",
"error",
")",
"{",
"return",
"&",
"stringTemplate",
"{",
"name",
",",
"name",
"}",
",",
"nil",
"\n",
"}"
] |
// Load on a StringLoader simply returns the name that is passed in.
|
[
"Load",
"on",
"a",
"StringLoader",
"simply",
"returns",
"the",
"name",
"that",
"is",
"passed",
"in",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/loader.go#L33-L35
|
16,570 |
tyler-sommer/stick
|
loader.go
|
Load
|
func (l *MemoryLoader) Load(name string) (Template, error) {
v, ok := l.Templates[name]
if !ok {
return nil, os.ErrNotExist
}
return &stringTemplate{name, v}, nil
}
|
go
|
func (l *MemoryLoader) Load(name string) (Template, error) {
v, ok := l.Templates[name]
if !ok {
return nil, os.ErrNotExist
}
return &stringTemplate{name, v}, nil
}
|
[
"func",
"(",
"l",
"*",
"MemoryLoader",
")",
"Load",
"(",
"name",
"string",
")",
"(",
"Template",
",",
"error",
")",
"{",
"v",
",",
"ok",
":=",
"l",
".",
"Templates",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"os",
".",
"ErrNotExist",
"\n",
"}",
"\n",
"return",
"&",
"stringTemplate",
"{",
"name",
",",
"v",
"}",
",",
"nil",
"\n",
"}"
] |
// Load tries to load the template from the in-memory map.
|
[
"Load",
"tries",
"to",
"load",
"the",
"template",
"from",
"the",
"in",
"-",
"memory",
"map",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/loader.go#L43-L49
|
16,571 |
tyler-sommer/stick
|
loader.go
|
Load
|
func (l *FilesystemLoader) Load(name string) (Template, error) {
path := filepath.Join(l.rootDir, name)
f, err := os.Open(path)
if err != nil {
return nil, err
}
return &fileTemplate{name, f}, nil
}
|
go
|
func (l *FilesystemLoader) Load(name string) (Template, error) {
path := filepath.Join(l.rootDir, name)
f, err := os.Open(path)
if err != nil {
return nil, err
}
return &fileTemplate{name, f}, nil
}
|
[
"func",
"(",
"l",
"*",
"FilesystemLoader",
")",
"Load",
"(",
"name",
"string",
")",
"(",
"Template",
",",
"error",
")",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"l",
".",
"rootDir",
",",
"name",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"fileTemplate",
"{",
"name",
",",
"f",
"}",
",",
"nil",
"\n",
"}"
] |
// Load on a FileSystemLoader attempts to load the given file, relative to the
// configured root directory.
|
[
"Load",
"on",
"a",
"FileSystemLoader",
"attempts",
"to",
"load",
"the",
"given",
"file",
"relative",
"to",
"the",
"configured",
"root",
"directory",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/loader.go#L76-L83
|
16,572 |
tyler-sommer/stick
|
parse/error.go
|
newUnexpectedTokenError
|
func newUnexpectedTokenError(actual token, expected ...tokenType) error {
return &UnexpectedTokenError{newBaseError(actual.Pos), actual, expected}
}
|
go
|
func newUnexpectedTokenError(actual token, expected ...tokenType) error {
return &UnexpectedTokenError{newBaseError(actual.Pos), actual, expected}
}
|
[
"func",
"newUnexpectedTokenError",
"(",
"actual",
"token",
",",
"expected",
"...",
"tokenType",
")",
"error",
"{",
"return",
"&",
"UnexpectedTokenError",
"{",
"newBaseError",
"(",
"actual",
".",
"Pos",
")",
",",
"actual",
",",
"expected",
"}",
"\n",
"}"
] |
// newUnexpectedTokenError returns a new UnexpectedTokenError
|
[
"newUnexpectedTokenError",
"returns",
"a",
"new",
"UnexpectedTokenError"
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/error.go#L74-L76
|
16,573 |
tyler-sommer/stick
|
parse/error.go
|
newUnclosedTagError
|
func newUnclosedTagError(tagName string, start Pos) error {
return &UnclosedTagError{newBaseError(start), tagName}
}
|
go
|
func newUnclosedTagError(tagName string, start Pos) error {
return &UnclosedTagError{newBaseError(start), tagName}
}
|
[
"func",
"newUnclosedTagError",
"(",
"tagName",
"string",
",",
"start",
"Pos",
")",
"error",
"{",
"return",
"&",
"UnclosedTagError",
"{",
"newBaseError",
"(",
"start",
")",
",",
"tagName",
"}",
"\n",
"}"
] |
// newUnclosedTagError returns a new UnclosedTagError.
|
[
"newUnclosedTagError",
"returns",
"a",
"new",
"UnclosedTagError",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/error.go#L89-L91
|
16,574 |
tyler-sommer/stick
|
parse/error.go
|
newUnexpectedValueError
|
func newUnexpectedValueError(tok token, expected string) error {
return &UnexpectedValueError{newBaseError(tok.Pos), tok, expected}
}
|
go
|
func newUnexpectedValueError(tok token, expected string) error {
return &UnexpectedValueError{newBaseError(tok.Pos), tok, expected}
}
|
[
"func",
"newUnexpectedValueError",
"(",
"tok",
"token",
",",
"expected",
"string",
")",
"error",
"{",
"return",
"&",
"UnexpectedValueError",
"{",
"newBaseError",
"(",
"tok",
".",
"Pos",
")",
",",
"tok",
",",
"expected",
"}",
"\n",
"}"
] |
// newUnexpectedValueError returns a new UnexpectedPunctuationError
|
[
"newUnexpectedValueError",
"returns",
"a",
"new",
"UnexpectedPunctuationError"
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/error.go#L119-L121
|
16,575 |
tyler-sommer/stick
|
twig/filter/filter.go
|
TwigFilters
|
func TwigFilters() map[string]stick.Filter {
return map[string]stick.Filter{
"abs": filterAbs,
"default": filterDefault,
"batch": filterBatch,
"capitalize": filterCapitalize,
"convert_encoding": filterConvertEncoding,
"date": filterDate,
"date_modify": filterDateModify,
"first": filterFirst,
"format": filterFormat,
"join": filterJoin,
"json_encode": filterJSONEncode,
"keys": filterKeys,
"last": filterLast,
"length": filterLength,
"lower": filterLower,
"merge": filterMerge,
"nl2br": filterNL2BR,
"number_format": filterNumberFormat,
"raw": filterRaw,
"replace": filterReplace,
"reverse": filterReverse,
"round": filterRound,
"slice": filterSlice,
"sort": filterSort,
"split": filterSplit,
"striptags": filterStripTags,
"title": filterTitle,
"trim": filterTrim,
"upper": filterUpper,
"url_encode": filterURLEncode,
}
}
|
go
|
func TwigFilters() map[string]stick.Filter {
return map[string]stick.Filter{
"abs": filterAbs,
"default": filterDefault,
"batch": filterBatch,
"capitalize": filterCapitalize,
"convert_encoding": filterConvertEncoding,
"date": filterDate,
"date_modify": filterDateModify,
"first": filterFirst,
"format": filterFormat,
"join": filterJoin,
"json_encode": filterJSONEncode,
"keys": filterKeys,
"last": filterLast,
"length": filterLength,
"lower": filterLower,
"merge": filterMerge,
"nl2br": filterNL2BR,
"number_format": filterNumberFormat,
"raw": filterRaw,
"replace": filterReplace,
"reverse": filterReverse,
"round": filterRound,
"slice": filterSlice,
"sort": filterSort,
"split": filterSplit,
"striptags": filterStripTags,
"title": filterTitle,
"trim": filterTrim,
"upper": filterUpper,
"url_encode": filterURLEncode,
}
}
|
[
"func",
"TwigFilters",
"(",
")",
"map",
"[",
"string",
"]",
"stick",
".",
"Filter",
"{",
"return",
"map",
"[",
"string",
"]",
"stick",
".",
"Filter",
"{",
"\"",
"\"",
":",
"filterAbs",
",",
"\"",
"\"",
":",
"filterDefault",
",",
"\"",
"\"",
":",
"filterBatch",
",",
"\"",
"\"",
":",
"filterCapitalize",
",",
"\"",
"\"",
":",
"filterConvertEncoding",
",",
"\"",
"\"",
":",
"filterDate",
",",
"\"",
"\"",
":",
"filterDateModify",
",",
"\"",
"\"",
":",
"filterFirst",
",",
"\"",
"\"",
":",
"filterFormat",
",",
"\"",
"\"",
":",
"filterJoin",
",",
"\"",
"\"",
":",
"filterJSONEncode",
",",
"\"",
"\"",
":",
"filterKeys",
",",
"\"",
"\"",
":",
"filterLast",
",",
"\"",
"\"",
":",
"filterLength",
",",
"\"",
"\"",
":",
"filterLower",
",",
"\"",
"\"",
":",
"filterMerge",
",",
"\"",
"\"",
":",
"filterNL2BR",
",",
"\"",
"\"",
":",
"filterNumberFormat",
",",
"\"",
"\"",
":",
"filterRaw",
",",
"\"",
"\"",
":",
"filterReplace",
",",
"\"",
"\"",
":",
"filterReverse",
",",
"\"",
"\"",
":",
"filterRound",
",",
"\"",
"\"",
":",
"filterSlice",
",",
"\"",
"\"",
":",
"filterSort",
",",
"\"",
"\"",
":",
"filterSplit",
",",
"\"",
"\"",
":",
"filterStripTags",
",",
"\"",
"\"",
":",
"filterTitle",
",",
"\"",
"\"",
":",
"filterTrim",
",",
"\"",
"\"",
":",
"filterUpper",
",",
"\"",
"\"",
":",
"filterURLEncode",
",",
"}",
"\n",
"}"
] |
// builtInFilters returns a map containing all built-in Twig filters,
// with the exception of "escape", which is provided by the AutoEscapeExtension.
|
[
"builtInFilters",
"returns",
"a",
"map",
"containing",
"all",
"built",
"-",
"in",
"Twig",
"filters",
"with",
"the",
"exception",
"of",
"escape",
"which",
"is",
"provided",
"by",
"the",
"AutoEscapeExtension",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L16-L49
|
16,576 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterAbs
|
func filterAbs(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
n := stick.CoerceNumber(val)
if 0 == n {
return n
}
return math.Abs(n)
}
|
go
|
func filterAbs(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
n := stick.CoerceNumber(val)
if 0 == n {
return n
}
return math.Abs(n)
}
|
[
"func",
"filterAbs",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"n",
":=",
"stick",
".",
"CoerceNumber",
"(",
"val",
")",
"\n",
"if",
"0",
"==",
"n",
"{",
"return",
"n",
"\n",
"}",
"\n",
"return",
"math",
".",
"Abs",
"(",
"n",
")",
"\n",
"}"
] |
// filterAbs takes no arguments and returns the absolute value of val.
// Value val will be coerced into a number.
|
[
"filterAbs",
"takes",
"no",
"arguments",
"and",
"returns",
"the",
"absolute",
"value",
"of",
"val",
".",
"Value",
"val",
"will",
"be",
"coerced",
"into",
"a",
"number",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L53-L59
|
16,577 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterCapitalize
|
func filterCapitalize(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
s := stick.CoerceString(val)
return strings.ToUpper(s[:1]) + s[1:]
}
|
go
|
func filterCapitalize(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
s := stick.CoerceString(val)
return strings.ToUpper(s[:1]) + s[1:]
}
|
[
"func",
"filterCapitalize",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"s",
":=",
"stick",
".",
"CoerceString",
"(",
"val",
")",
"\n",
"return",
"strings",
".",
"ToUpper",
"(",
"s",
"[",
":",
"1",
"]",
")",
"+",
"s",
"[",
"1",
":",
"]",
"\n",
"}"
] |
// filterCapitalize takes no arguments and returns val with the first
// character capitalized.
|
[
"filterCapitalize",
"takes",
"no",
"arguments",
"and",
"returns",
"val",
"with",
"the",
"first",
"character",
"capitalized",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L117-L120
|
16,578 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterDefault
|
func filterDefault(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
var d stick.Value
if len(args) > 0 {
d = args[0]
}
if stick.CoerceString(val) == "" {
return d
}
return val
}
|
go
|
func filterDefault(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
var d stick.Value
if len(args) > 0 {
d = args[0]
}
if stick.CoerceString(val) == "" {
return d
}
return val
}
|
[
"func",
"filterDefault",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"var",
"d",
"stick",
".",
"Value",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"d",
"=",
"args",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"stick",
".",
"CoerceString",
"(",
"val",
")",
"==",
"\"",
"\"",
"{",
"return",
"d",
"\n",
"}",
"\n",
"return",
"val",
"\n",
"}"
] |
// filterDefault takes one argument, the default value. If val is empty,
// the default value will be returned.
|
[
"filterDefault",
"takes",
"one",
"argument",
"the",
"default",
"value",
".",
"If",
"val",
"is",
"empty",
"the",
"default",
"value",
"will",
"be",
"returned",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L204-L213
|
16,579 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterLength
|
func filterLength(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
if v, ok := val.(string); ok {
return utf8.RuneCountInString(v)
}
l, _ := stick.Len(val)
// TODO: Report error
return l
}
|
go
|
func filterLength(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
if v, ok := val.(string); ok {
return utf8.RuneCountInString(v)
}
l, _ := stick.Len(val)
// TODO: Report error
return l
}
|
[
"func",
"filterLength",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"if",
"v",
",",
"ok",
":=",
"val",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"utf8",
".",
"RuneCountInString",
"(",
"v",
")",
"\n",
"}",
"\n",
"l",
",",
"_",
":=",
"stick",
".",
"Len",
"(",
"val",
")",
"\n",
"// TODO: Report error",
"return",
"l",
"\n",
"}"
] |
// filterLength returns the length of val.
|
[
"filterLength",
"returns",
"the",
"length",
"of",
"val",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L273-L280
|
16,580 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterLower
|
func filterLower(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.ToLower(stick.CoerceString(val))
}
|
go
|
func filterLower(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.ToLower(stick.CoerceString(val))
}
|
[
"func",
"filterLower",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"return",
"strings",
".",
"ToLower",
"(",
"stick",
".",
"CoerceString",
"(",
"val",
")",
")",
"\n",
"}"
] |
// filterLower returns val transformed to lower-case.
|
[
"filterLower",
"returns",
"val",
"transformed",
"to",
"lower",
"-",
"case",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L283-L285
|
16,581 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterTitle
|
func filterTitle(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.Title(stick.CoerceString(val))
}
|
go
|
func filterTitle(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.Title(stick.CoerceString(val))
}
|
[
"func",
"filterTitle",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"return",
"strings",
".",
"Title",
"(",
"stick",
".",
"CoerceString",
"(",
"val",
")",
")",
"\n",
"}"
] |
// filterTitle returns val with the first character of each word capitalized.
|
[
"filterTitle",
"returns",
"val",
"with",
"the",
"first",
"character",
"of",
"each",
"word",
"capitalized",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L362-L364
|
16,582 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterTrim
|
func filterTrim(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.TrimSpace(stick.CoerceString(val))
}
|
go
|
func filterTrim(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.TrimSpace(stick.CoerceString(val))
}
|
[
"func",
"filterTrim",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"return",
"strings",
".",
"TrimSpace",
"(",
"stick",
".",
"CoerceString",
"(",
"val",
")",
")",
"\n",
"}"
] |
// filterTrim returns val with whitespace trimmed on both left and ride sides.
|
[
"filterTrim",
"returns",
"val",
"with",
"whitespace",
"trimmed",
"on",
"both",
"left",
"and",
"ride",
"sides",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L367-L369
|
16,583 |
tyler-sommer/stick
|
twig/filter/filter.go
|
filterUpper
|
func filterUpper(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.ToUpper(stick.CoerceString(val))
}
|
go
|
func filterUpper(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
return strings.ToUpper(stick.CoerceString(val))
}
|
[
"func",
"filterUpper",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"return",
"strings",
".",
"ToUpper",
"(",
"stick",
".",
"CoerceString",
"(",
"val",
")",
")",
"\n",
"}"
] |
// filterUpper returns val in upper-case.
|
[
"filterUpper",
"returns",
"val",
"in",
"upper",
"-",
"case",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/filter/filter.go#L372-L374
|
16,584 |
tyler-sommer/stick
|
parse/lex.go
|
nextToken
|
func (l *lexer) nextToken() token {
for v, ok := <-l.tokens; ok; {
l.last = v
return v
}
return l.last
}
|
go
|
func (l *lexer) nextToken() token {
for v, ok := <-l.tokens; ok; {
l.last = v
return v
}
return l.last
}
|
[
"func",
"(",
"l",
"*",
"lexer",
")",
"nextToken",
"(",
")",
"token",
"{",
"for",
"v",
",",
"ok",
":=",
"<-",
"l",
".",
"tokens",
";",
"ok",
";",
"{",
"l",
".",
"last",
"=",
"v",
"\n",
"return",
"v",
"\n",
"}",
"\n\n",
"return",
"l",
".",
"last",
"\n",
"}"
] |
// nextToken returns the next token emitted by the lexer.
|
[
"nextToken",
"returns",
"the",
"next",
"token",
"emitted",
"by",
"the",
"lexer",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/lex.go#L123-L130
|
16,585 |
tyler-sommer/stick
|
parse/lex.go
|
tokenize
|
func (l *lexer) tokenize() {
for l.state = lexData; l.state != nil; {
l.state = l.state(l)
}
}
|
go
|
func (l *lexer) tokenize() {
for l.state = lexData; l.state != nil; {
l.state = l.state(l)
}
}
|
[
"func",
"(",
"l",
"*",
"lexer",
")",
"tokenize",
"(",
")",
"{",
"for",
"l",
".",
"state",
"=",
"lexData",
";",
"l",
".",
"state",
"!=",
"nil",
";",
"{",
"l",
".",
"state",
"=",
"l",
".",
"state",
"(",
"l",
")",
"\n",
"}",
"\n",
"}"
] |
// tokenize kicks things off.
|
[
"tokenize",
"kicks",
"things",
"off",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/lex.go#L133-L137
|
16,586 |
tyler-sommer/stick
|
parse/lex.go
|
newLexer
|
func newLexer(input io.Reader) *lexer {
// TODO: lexer should use the reader.
i, _ := ioutil.ReadAll(input)
return &lexer{0, 0, 1, 0, string(i), make(chan token), nil, modeNormal, token{}, 0}
}
|
go
|
func newLexer(input io.Reader) *lexer {
// TODO: lexer should use the reader.
i, _ := ioutil.ReadAll(input)
return &lexer{0, 0, 1, 0, string(i), make(chan token), nil, modeNormal, token{}, 0}
}
|
[
"func",
"newLexer",
"(",
"input",
"io",
".",
"Reader",
")",
"*",
"lexer",
"{",
"// TODO: lexer should use the reader.",
"i",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"input",
")",
"\n",
"return",
"&",
"lexer",
"{",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"string",
"(",
"i",
")",
",",
"make",
"(",
"chan",
"token",
")",
",",
"nil",
",",
"modeNormal",
",",
"token",
"{",
"}",
",",
"0",
"}",
"\n",
"}"
] |
// newLexer creates a lexer, ready to begin tokenizing.
|
[
"newLexer",
"creates",
"a",
"lexer",
"ready",
"to",
"begin",
"tokenizing",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/lex.go#L140-L144
|
16,587 |
tyler-sommer/stick
|
parse/lex.go
|
emit
|
func (l *lexer) emit(t tokenType) {
val := ""
if l.pos <= len(l.input) {
val = l.input[l.start:l.pos]
}
tok := token{val, t, Pos{l.line, l.offset}}
if c := strings.Count(val, "\n"); c > 0 {
l.line += c
lpos := strings.LastIndex(val, "\n")
l.offset = len(val[lpos+1:])
} else {
l.offset += len(val)
}
l.tokens <- tok
l.start = l.pos
if tok.tokenType == tokenEOF {
close(l.tokens)
l.mode = modeClosed
}
}
|
go
|
func (l *lexer) emit(t tokenType) {
val := ""
if l.pos <= len(l.input) {
val = l.input[l.start:l.pos]
}
tok := token{val, t, Pos{l.line, l.offset}}
if c := strings.Count(val, "\n"); c > 0 {
l.line += c
lpos := strings.LastIndex(val, "\n")
l.offset = len(val[lpos+1:])
} else {
l.offset += len(val)
}
l.tokens <- tok
l.start = l.pos
if tok.tokenType == tokenEOF {
close(l.tokens)
l.mode = modeClosed
}
}
|
[
"func",
"(",
"l",
"*",
"lexer",
")",
"emit",
"(",
"t",
"tokenType",
")",
"{",
"val",
":=",
"\"",
"\"",
"\n",
"if",
"l",
".",
"pos",
"<=",
"len",
"(",
"l",
".",
"input",
")",
"{",
"val",
"=",
"l",
".",
"input",
"[",
"l",
".",
"start",
":",
"l",
".",
"pos",
"]",
"\n",
"}",
"\n\n",
"tok",
":=",
"token",
"{",
"val",
",",
"t",
",",
"Pos",
"{",
"l",
".",
"line",
",",
"l",
".",
"offset",
"}",
"}",
"\n\n",
"if",
"c",
":=",
"strings",
".",
"Count",
"(",
"val",
",",
"\"",
"\\n",
"\"",
")",
";",
"c",
">",
"0",
"{",
"l",
".",
"line",
"+=",
"c",
"\n",
"lpos",
":=",
"strings",
".",
"LastIndex",
"(",
"val",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"l",
".",
"offset",
"=",
"len",
"(",
"val",
"[",
"lpos",
"+",
"1",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"l",
".",
"offset",
"+=",
"len",
"(",
"val",
")",
"\n",
"}",
"\n\n",
"l",
".",
"tokens",
"<-",
"tok",
"\n",
"l",
".",
"start",
"=",
"l",
".",
"pos",
"\n",
"if",
"tok",
".",
"tokenType",
"==",
"tokenEOF",
"{",
"close",
"(",
"l",
".",
"tokens",
")",
"\n",
"l",
".",
"mode",
"=",
"modeClosed",
"\n",
"}",
"\n",
"}"
] |
// emit will create a token with a value starting from the last emission
// until the current cursor position.
|
[
"emit",
"will",
"create",
"a",
"token",
"with",
"a",
"value",
"starting",
"from",
"the",
"last",
"emission",
"until",
"the",
"current",
"cursor",
"position",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/lex.go#L171-L193
|
16,588 |
tyler-sommer/stick
|
parse/lex.go
|
tryLexOperator
|
func (l *lexer) tryLexOperator() bool {
op := operatorMatcher.FindString(l.input[l.pos:])
if op == "" {
return false
} else if op == "%" {
// Ensure this is not a tag close token "%}".
// Go's regexp engine does not support negative lookahead.
if l.input[l.pos+1:l.pos+2] == "}" {
return false
}
} else if op == "in" || op == "is" {
// Avoid matching "include" or functions like "is_currently_on"
if l.input[l.pos+2:l.pos+3] != " " {
return false
}
} else if op == delimTrimWhitespace {
switch l.input[l.pos+1 : l.pos+3] {
case delimClosePrint, delimCloseTag:
return false
}
}
l.pos += len(op)
l.emit(tokenOperator)
return true
}
|
go
|
func (l *lexer) tryLexOperator() bool {
op := operatorMatcher.FindString(l.input[l.pos:])
if op == "" {
return false
} else if op == "%" {
// Ensure this is not a tag close token "%}".
// Go's regexp engine does not support negative lookahead.
if l.input[l.pos+1:l.pos+2] == "}" {
return false
}
} else if op == "in" || op == "is" {
// Avoid matching "include" or functions like "is_currently_on"
if l.input[l.pos+2:l.pos+3] != " " {
return false
}
} else if op == delimTrimWhitespace {
switch l.input[l.pos+1 : l.pos+3] {
case delimClosePrint, delimCloseTag:
return false
}
}
l.pos += len(op)
l.emit(tokenOperator)
return true
}
|
[
"func",
"(",
"l",
"*",
"lexer",
")",
"tryLexOperator",
"(",
")",
"bool",
"{",
"op",
":=",
"operatorMatcher",
".",
"FindString",
"(",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"]",
")",
"\n",
"if",
"op",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"else",
"if",
"op",
"==",
"\"",
"\"",
"{",
"// Ensure this is not a tag close token \"%}\".",
"// Go's regexp engine does not support negative lookahead.",
"if",
"l",
".",
"input",
"[",
"l",
".",
"pos",
"+",
"1",
":",
"l",
".",
"pos",
"+",
"2",
"]",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"if",
"op",
"==",
"\"",
"\"",
"||",
"op",
"==",
"\"",
"\"",
"{",
"// Avoid matching \"include\" or functions like \"is_currently_on\"",
"if",
"l",
".",
"input",
"[",
"l",
".",
"pos",
"+",
"2",
":",
"l",
".",
"pos",
"+",
"3",
"]",
"!=",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"if",
"op",
"==",
"delimTrimWhitespace",
"{",
"switch",
"l",
".",
"input",
"[",
"l",
".",
"pos",
"+",
"1",
":",
"l",
".",
"pos",
"+",
"3",
"]",
"{",
"case",
"delimClosePrint",
",",
"delimCloseTag",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"l",
".",
"pos",
"+=",
"len",
"(",
"op",
")",
"\n",
"l",
".",
"emit",
"(",
"tokenOperator",
")",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// tryLexOperator attempts to match the next sequence of characters to a list of operators.
// This is implemented this way because Twig supports many alphabetical operators like "in",
// which require more than just a check of the next character.
|
[
"tryLexOperator",
"attempts",
"to",
"match",
"the",
"next",
"sequence",
"of",
"characters",
"to",
"a",
"list",
"of",
"operators",
".",
"This",
"is",
"implemented",
"this",
"way",
"because",
"Twig",
"supports",
"many",
"alphabetical",
"operators",
"like",
"in",
"which",
"require",
"more",
"than",
"just",
"a",
"check",
"of",
"the",
"next",
"character",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/lex.go#L291-L316
|
16,589 |
tyler-sommer/stick
|
parse/parse_expr.go
|
parseExpr
|
func (t *Tree) parseExpr() (Expr, error) {
expr, err := t.parseInnerExpr()
if err != nil {
return nil, err
}
return t.parseOuterExpr(expr)
}
|
go
|
func (t *Tree) parseExpr() (Expr, error) {
expr, err := t.parseInnerExpr()
if err != nil {
return nil, err
}
return t.parseOuterExpr(expr)
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parseExpr",
"(",
")",
"(",
"Expr",
",",
"error",
")",
"{",
"expr",
",",
"err",
":=",
"t",
".",
"parseInnerExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"t",
".",
"parseOuterExpr",
"(",
"expr",
")",
"\n",
"}"
] |
// parseExpr parses an expression.
|
[
"parseExpr",
"parses",
"an",
"expression",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_expr.go#L6-L13
|
16,590 |
tyler-sommer/stick
|
parse/parse_expr.go
|
parseFunc
|
func (t *Tree) parseFunc(name *NameExpr) (Expr, error) {
var args []Expr
for {
switch tok := t.peek(); tok.tokenType {
case tokenEOF:
return nil, newUnexpectedEOFError(tok)
case tokenParensClose:
// do nothing
default:
argexp, err := t.parseExpr()
if err != nil {
return nil, err
}
args = append(args, argexp)
}
switch tok := t.nextNonSpace(); tok.tokenType {
case tokenEOF:
return nil, newUnexpectedEOFError(tok)
case tokenPunctuation:
if tok.value != "," {
return nil, newUnexpectedValueError(tok, ",")
}
case tokenParensClose:
return NewFuncExpr(name.Name, args, name.Pos), nil
default:
return nil, newUnexpectedTokenError(tok, tokenPunctuation, tokenParensClose)
}
}
}
|
go
|
func (t *Tree) parseFunc(name *NameExpr) (Expr, error) {
var args []Expr
for {
switch tok := t.peek(); tok.tokenType {
case tokenEOF:
return nil, newUnexpectedEOFError(tok)
case tokenParensClose:
// do nothing
default:
argexp, err := t.parseExpr()
if err != nil {
return nil, err
}
args = append(args, argexp)
}
switch tok := t.nextNonSpace(); tok.tokenType {
case tokenEOF:
return nil, newUnexpectedEOFError(tok)
case tokenPunctuation:
if tok.value != "," {
return nil, newUnexpectedValueError(tok, ",")
}
case tokenParensClose:
return NewFuncExpr(name.Name, args, name.Pos), nil
default:
return nil, newUnexpectedTokenError(tok, tokenPunctuation, tokenParensClose)
}
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parseFunc",
"(",
"name",
"*",
"NameExpr",
")",
"(",
"Expr",
",",
"error",
")",
"{",
"var",
"args",
"[",
"]",
"Expr",
"\n",
"for",
"{",
"switch",
"tok",
":=",
"t",
".",
"peek",
"(",
")",
";",
"tok",
".",
"tokenType",
"{",
"case",
"tokenEOF",
":",
"return",
"nil",
",",
"newUnexpectedEOFError",
"(",
"tok",
")",
"\n\n",
"case",
"tokenParensClose",
":",
"// do nothing",
"default",
":",
"argexp",
",",
"err",
":=",
"t",
".",
"parseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"argexp",
")",
"\n",
"}",
"\n\n",
"switch",
"tok",
":=",
"t",
".",
"nextNonSpace",
"(",
")",
";",
"tok",
".",
"tokenType",
"{",
"case",
"tokenEOF",
":",
"return",
"nil",
",",
"newUnexpectedEOFError",
"(",
"tok",
")",
"\n\n",
"case",
"tokenPunctuation",
":",
"if",
"tok",
".",
"value",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"newUnexpectedValueError",
"(",
"tok",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"case",
"tokenParensClose",
":",
"return",
"NewFuncExpr",
"(",
"name",
".",
"Name",
",",
"args",
",",
"name",
".",
"Pos",
")",
",",
"nil",
"\n\n",
"default",
":",
"return",
"nil",
",",
"newUnexpectedTokenError",
"(",
"tok",
",",
"tokenPunctuation",
",",
"tokenParensClose",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// parseFunc parses a function call expression from the first argument expression until the closing parenthesis.
|
[
"parseFunc",
"parses",
"a",
"function",
"call",
"expression",
"from",
"the",
"first",
"argument",
"expression",
"until",
"the",
"closing",
"parenthesis",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_expr.go#L344-L379
|
16,591 |
tyler-sommer/stick
|
twig/twig_compat.go
|
New
|
func New(loader stick.Loader) *stick.Env {
if loader == nil {
loader = &stick.StringLoader{}
}
env := &stick.Env{
Loader: loader,
Functions: make(map[string]stick.Func),
Filters: filter.TwigFilters(),
Tests: make(map[string]stick.Test),
Visitors: make([]parse.NodeVisitor, 0),
}
env.Register(NewAutoEscapeExtension())
return env
}
|
go
|
func New(loader stick.Loader) *stick.Env {
if loader == nil {
loader = &stick.StringLoader{}
}
env := &stick.Env{
Loader: loader,
Functions: make(map[string]stick.Func),
Filters: filter.TwigFilters(),
Tests: make(map[string]stick.Test),
Visitors: make([]parse.NodeVisitor, 0),
}
env.Register(NewAutoEscapeExtension())
return env
}
|
[
"func",
"New",
"(",
"loader",
"stick",
".",
"Loader",
")",
"*",
"stick",
".",
"Env",
"{",
"if",
"loader",
"==",
"nil",
"{",
"loader",
"=",
"&",
"stick",
".",
"StringLoader",
"{",
"}",
"\n",
"}",
"\n",
"env",
":=",
"&",
"stick",
".",
"Env",
"{",
"Loader",
":",
"loader",
",",
"Functions",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"stick",
".",
"Func",
")",
",",
"Filters",
":",
"filter",
".",
"TwigFilters",
"(",
")",
",",
"Tests",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"stick",
".",
"Test",
")",
",",
"Visitors",
":",
"make",
"(",
"[",
"]",
"parse",
".",
"NodeVisitor",
",",
"0",
")",
",",
"}",
"\n",
"env",
".",
"Register",
"(",
"NewAutoEscapeExtension",
"(",
")",
")",
"\n",
"return",
"env",
"\n",
"}"
] |
// New creates a new, default Env that aims to be compatible with Twig.
// If nil is passed as loader, a StringLoader is used.
|
[
"New",
"creates",
"a",
"new",
"default",
"Env",
"that",
"aims",
"to",
"be",
"compatible",
"with",
"Twig",
".",
"If",
"nil",
"is",
"passed",
"as",
"loader",
"a",
"StringLoader",
"is",
"used",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/twig_compat.go#L36-L49
|
16,592 |
pkg/xattr
|
xattr_bsd.go
|
sysGet
|
func sysGet(syscallNum uintptr, path string, name string, data []byte) (int, error) {
ptr, nbytes := bytePtrFromSlice(data)
/*
ssize_t extattr_get_file(
const char *path,
int attrnamespace,
const char *attrname,
void *data,
size_t nbytes);
ssize_t extattr_get_link(
const char *path,
int attrnamespace,
const char *attrname,
void *data,
size_t nbytes);
*/
r0, _, err := syscall.Syscall6(syscallNum, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
EXTATTR_NAMESPACE_USER, uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(ptr)), uintptr(nbytes), 0)
if err != syscall.Errno(0) {
return int(r0), err
}
return int(r0), nil
}
|
go
|
func sysGet(syscallNum uintptr, path string, name string, data []byte) (int, error) {
ptr, nbytes := bytePtrFromSlice(data)
/*
ssize_t extattr_get_file(
const char *path,
int attrnamespace,
const char *attrname,
void *data,
size_t nbytes);
ssize_t extattr_get_link(
const char *path,
int attrnamespace,
const char *attrname,
void *data,
size_t nbytes);
*/
r0, _, err := syscall.Syscall6(syscallNum, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
EXTATTR_NAMESPACE_USER, uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
uintptr(unsafe.Pointer(ptr)), uintptr(nbytes), 0)
if err != syscall.Errno(0) {
return int(r0), err
}
return int(r0), nil
}
|
[
"func",
"sysGet",
"(",
"syscallNum",
"uintptr",
",",
"path",
"string",
",",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"ptr",
",",
"nbytes",
":=",
"bytePtrFromSlice",
"(",
"data",
")",
"\n",
"/*\n\t\tssize_t extattr_get_file(\n\t\t\tconst char *path,\n\t\t\tint attrnamespace,\n\t\t\tconst char *attrname,\n\t\t\tvoid *data,\n\t\t\tsize_t nbytes);\n\n\t\tssize_t extattr_get_link(\n\t\t\tconst char *path,\n\t\t\tint attrnamespace,\n\t\t\tconst char *attrname,\n\t\t\tvoid *data,\n\t\t\tsize_t nbytes);\n\t*/",
"r0",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall6",
"(",
"syscallNum",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringBytePtr",
"(",
"path",
")",
")",
")",
",",
"EXTATTR_NAMESPACE_USER",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringBytePtr",
"(",
"name",
")",
")",
")",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"ptr",
")",
")",
",",
"uintptr",
"(",
"nbytes",
")",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"syscall",
".",
"Errno",
"(",
"0",
")",
"{",
"return",
"int",
"(",
"r0",
")",
",",
"err",
"\n",
"}",
"\n",
"return",
"int",
"(",
"r0",
")",
",",
"nil",
"\n",
"}"
] |
// sysGet is called by getxattr and lgetxattr with the appropriate syscall
// number. This works because syscalls have the same signature and return
// values.
|
[
"sysGet",
"is",
"called",
"by",
"getxattr",
"and",
"lgetxattr",
"with",
"the",
"appropriate",
"syscall",
"number",
".",
"This",
"works",
"because",
"syscalls",
"have",
"the",
"same",
"signature",
"and",
"return",
"values",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr_bsd.go#L35-L59
|
16,593 |
pkg/xattr
|
xattr_bsd.go
|
sysRemove
|
func sysRemove(syscallNum uintptr, path string, name string) error {
/*
int extattr_delete_file(
const char *path,
int attrnamespace,
const char *attrname
);
int extattr_delete_link(
const char *path,
int attrnamespace,
const char *attrname
);
*/
_, _, err := syscall.Syscall(syscallNum, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
EXTATTR_NAMESPACE_USER, uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
)
if err != syscall.Errno(0) {
return err
}
return nil
}
|
go
|
func sysRemove(syscallNum uintptr, path string, name string) error {
/*
int extattr_delete_file(
const char *path,
int attrnamespace,
const char *attrname
);
int extattr_delete_link(
const char *path,
int attrnamespace,
const char *attrname
);
*/
_, _, err := syscall.Syscall(syscallNum, uintptr(unsafe.Pointer(syscall.StringBytePtr(path))),
EXTATTR_NAMESPACE_USER, uintptr(unsafe.Pointer(syscall.StringBytePtr(name))),
)
if err != syscall.Errno(0) {
return err
}
return nil
}
|
[
"func",
"sysRemove",
"(",
"syscallNum",
"uintptr",
",",
"path",
"string",
",",
"name",
"string",
")",
"error",
"{",
"/*\n\t\tint extattr_delete_file(\n\t\t\tconst char *path,\n\t\t\tint attrnamespace,\n\t\t\tconst char *attrname\n\t\t);\n\n\t\tint extattr_delete_link(\n\t\t\tconst char *path,\n\t\t\tint attrnamespace,\n\t\t\tconst char *attrname\n\t\t);\n\t*/",
"_",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall",
"(",
"syscallNum",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringBytePtr",
"(",
"path",
")",
")",
")",
",",
"EXTATTR_NAMESPACE_USER",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"syscall",
".",
"StringBytePtr",
"(",
"name",
")",
")",
")",
",",
")",
"\n",
"if",
"err",
"!=",
"syscall",
".",
"Errno",
"(",
"0",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// sysSet is called by removexattr and lremovexattr with the appropriate syscall
// number. This works because syscalls have the same signature and return
// values.
|
[
"sysSet",
"is",
"called",
"by",
"removexattr",
"and",
"lremovexattr",
"with",
"the",
"appropriate",
"syscall",
"number",
".",
"This",
"works",
"because",
"syscalls",
"have",
"the",
"same",
"signature",
"and",
"return",
"values",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr_bsd.go#L122-L143
|
16,594 |
pkg/xattr
|
xattr.go
|
Get
|
func Get(path, name string) ([]byte, error) {
return get(path, name, func(name string, data []byte) (int, error) {
return getxattr(path, name, data)
})
}
|
go
|
func Get(path, name string) ([]byte, error) {
return get(path, name, func(name string, data []byte) (int, error) {
return getxattr(path, name, data)
})
}
|
[
"func",
"Get",
"(",
"path",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"get",
"(",
"path",
",",
"name",
",",
"func",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"getxattr",
"(",
"path",
",",
"name",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// Get retrieves extended attribute data associated with path. It will follow
// all symlinks along the path.
|
[
"Get",
"retrieves",
"extended",
"attribute",
"data",
"associated",
"with",
"path",
".",
"It",
"will",
"follow",
"all",
"symlinks",
"along",
"the",
"path",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L38-L42
|
16,595 |
pkg/xattr
|
xattr.go
|
LGet
|
func LGet(path, name string) ([]byte, error) {
return get(path, name, func(name string, data []byte) (int, error) {
return lgetxattr(path, name, data)
})
}
|
go
|
func LGet(path, name string) ([]byte, error) {
return get(path, name, func(name string, data []byte) (int, error) {
return lgetxattr(path, name, data)
})
}
|
[
"func",
"LGet",
"(",
"path",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"get",
"(",
"path",
",",
"name",
",",
"func",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"lgetxattr",
"(",
"path",
",",
"name",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// LGet is like Get but does not follow a symlink at the end of the path.
|
[
"LGet",
"is",
"like",
"Get",
"but",
"does",
"not",
"follow",
"a",
"symlink",
"at",
"the",
"end",
"of",
"the",
"path",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L45-L49
|
16,596 |
pkg/xattr
|
xattr.go
|
FGet
|
func FGet(f *os.File, name string) ([]byte, error) {
return get(f.Name(), name, func(name string, data []byte) (int, error) {
return fgetxattr(f, name, data)
})
}
|
go
|
func FGet(f *os.File, name string) ([]byte, error) {
return get(f.Name(), name, func(name string, data []byte) (int, error) {
return fgetxattr(f, name, data)
})
}
|
[
"func",
"FGet",
"(",
"f",
"*",
"os",
".",
"File",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"get",
"(",
"f",
".",
"Name",
"(",
")",
",",
"name",
",",
"func",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"fgetxattr",
"(",
"f",
",",
"name",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// FGet is like Get but accepts a os.File instead of a file path.
|
[
"FGet",
"is",
"like",
"Get",
"but",
"accepts",
"a",
"os",
".",
"File",
"instead",
"of",
"a",
"file",
"path",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L52-L56
|
16,597 |
pkg/xattr
|
xattr.go
|
get
|
func get(path string, name string, getxattrFunc getxattrFunc) ([]byte, error) {
const (
// Start with a 1 KB buffer for the xattr value
initialBufSize = 1024
// The theoretical maximum xattr value size on MacOS is 64 MB. On Linux it's
// much smaller at 64 KB. Unless the kernel is evil or buggy, we should never
// hit the limit.
maxBufSize = 64 * 1024 * 1024
// Function name as reported in error messages
myname = "xattr.get"
)
size := initialBufSize
for {
data := make([]byte, size)
read, err := getxattrFunc(name, data)
// If the buffer was too small to fit the value, Linux and MacOS react
// differently:
// Linux: returns an ERANGE error and "-1" bytes.
// MacOS: truncates the value and returns "size" bytes. If the value
// happens to be exactly as big as the buffer, we cannot know if it was
// truncated, and we retry with a bigger buffer. Contrary to documentation,
// MacOS never seems to return ERANGE!
// To keep the code simple, we always check both conditions, and sometimes
// double the buffer size without it being strictly neccessary.
if err == syscall.ERANGE || read == size {
// The buffer was too small. Try again.
size <<= 1
if size >= maxBufSize {
return nil, &Error{myname, path, name, syscall.EOVERFLOW}
}
continue
}
if err != nil {
return nil, &Error{myname, path, name, err}
}
return data[:read], nil
}
}
|
go
|
func get(path string, name string, getxattrFunc getxattrFunc) ([]byte, error) {
const (
// Start with a 1 KB buffer for the xattr value
initialBufSize = 1024
// The theoretical maximum xattr value size on MacOS is 64 MB. On Linux it's
// much smaller at 64 KB. Unless the kernel is evil or buggy, we should never
// hit the limit.
maxBufSize = 64 * 1024 * 1024
// Function name as reported in error messages
myname = "xattr.get"
)
size := initialBufSize
for {
data := make([]byte, size)
read, err := getxattrFunc(name, data)
// If the buffer was too small to fit the value, Linux and MacOS react
// differently:
// Linux: returns an ERANGE error and "-1" bytes.
// MacOS: truncates the value and returns "size" bytes. If the value
// happens to be exactly as big as the buffer, we cannot know if it was
// truncated, and we retry with a bigger buffer. Contrary to documentation,
// MacOS never seems to return ERANGE!
// To keep the code simple, we always check both conditions, and sometimes
// double the buffer size without it being strictly neccessary.
if err == syscall.ERANGE || read == size {
// The buffer was too small. Try again.
size <<= 1
if size >= maxBufSize {
return nil, &Error{myname, path, name, syscall.EOVERFLOW}
}
continue
}
if err != nil {
return nil, &Error{myname, path, name, err}
}
return data[:read], nil
}
}
|
[
"func",
"get",
"(",
"path",
"string",
",",
"name",
"string",
",",
"getxattrFunc",
"getxattrFunc",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"const",
"(",
"// Start with a 1 KB buffer for the xattr value",
"initialBufSize",
"=",
"1024",
"\n\n",
"// The theoretical maximum xattr value size on MacOS is 64 MB. On Linux it's",
"// much smaller at 64 KB. Unless the kernel is evil or buggy, we should never",
"// hit the limit.",
"maxBufSize",
"=",
"64",
"*",
"1024",
"*",
"1024",
"\n\n",
"// Function name as reported in error messages",
"myname",
"=",
"\"",
"\"",
"\n",
")",
"\n\n",
"size",
":=",
"initialBufSize",
"\n",
"for",
"{",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"read",
",",
"err",
":=",
"getxattrFunc",
"(",
"name",
",",
"data",
")",
"\n\n",
"// If the buffer was too small to fit the value, Linux and MacOS react",
"// differently:",
"// Linux: returns an ERANGE error and \"-1\" bytes.",
"// MacOS: truncates the value and returns \"size\" bytes. If the value",
"// happens to be exactly as big as the buffer, we cannot know if it was",
"// truncated, and we retry with a bigger buffer. Contrary to documentation,",
"// MacOS never seems to return ERANGE!",
"// To keep the code simple, we always check both conditions, and sometimes",
"// double the buffer size without it being strictly neccessary.",
"if",
"err",
"==",
"syscall",
".",
"ERANGE",
"||",
"read",
"==",
"size",
"{",
"// The buffer was too small. Try again.",
"size",
"<<=",
"1",
"\n",
"if",
"size",
">=",
"maxBufSize",
"{",
"return",
"nil",
",",
"&",
"Error",
"{",
"myname",
",",
"path",
",",
"name",
",",
"syscall",
".",
"EOVERFLOW",
"}",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"Error",
"{",
"myname",
",",
"path",
",",
"name",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"data",
"[",
":",
"read",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// get contains the buffer allocation logic used by both Get and LGet.
|
[
"get",
"contains",
"the",
"buffer",
"allocation",
"logic",
"used",
"by",
"both",
"Get",
"and",
"LGet",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L61-L102
|
16,598 |
pkg/xattr
|
xattr.go
|
Set
|
func Set(path, name string, data []byte) error {
if err := setxattr(path, name, data, 0); err != nil {
return &Error{"xattr.Set", path, name, err}
}
return nil
}
|
go
|
func Set(path, name string, data []byte) error {
if err := setxattr(path, name, data, 0); err != nil {
return &Error{"xattr.Set", path, name, err}
}
return nil
}
|
[
"func",
"Set",
"(",
"path",
",",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"setxattr",
"(",
"path",
",",
"name",
",",
"data",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Error",
"{",
"\"",
"\"",
",",
"path",
",",
"name",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Set associates name and data together as an attribute of path.
|
[
"Set",
"associates",
"name",
"and",
"data",
"together",
"as",
"an",
"attribute",
"of",
"path",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L105-L110
|
16,599 |
pkg/xattr
|
xattr.go
|
LSet
|
func LSet(path, name string, data []byte) error {
if err := lsetxattr(path, name, data, 0); err != nil {
return &Error{"xattr.LSet", path, name, err}
}
return nil
}
|
go
|
func LSet(path, name string, data []byte) error {
if err := lsetxattr(path, name, data, 0); err != nil {
return &Error{"xattr.LSet", path, name, err}
}
return nil
}
|
[
"func",
"LSet",
"(",
"path",
",",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"lsetxattr",
"(",
"path",
",",
"name",
",",
"data",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Error",
"{",
"\"",
"\"",
",",
"path",
",",
"name",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// LSet is like Set but does not follow a symlink at
// the end of the path.
|
[
"LSet",
"is",
"like",
"Set",
"but",
"does",
"not",
"follow",
"a",
"symlink",
"at",
"the",
"end",
"of",
"the",
"path",
"."
] |
f2ae4ae548121ce70f98b72822c65d86900849c3
|
https://github.com/pkg/xattr/blob/f2ae4ae548121ce70f98b72822c65d86900849c3/xattr.go#L114-L119
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.