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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
500 | aymerick/raymond | helper.go | Eval | func (options *Options) Eval(ctx interface{}, field string) interface{} {
if ctx == nil {
return nil
}
if field == "" {
return nil
}
val := options.eval.evalField(reflect.ValueOf(ctx), field, false)
if !val.IsValid() {
return nil
}
return val.Interface()
} | go | func (options *Options) Eval(ctx interface{}, field string) interface{} {
if ctx == nil {
return nil
}
if field == "" {
return nil
}
val := options.eval.evalField(reflect.ValueOf(ctx), field, false)
if !val.IsValid() {
return nil
}
return val.Interface()
} | [
"func",
"(",
"options",
"*",
"Options",
")",
"Eval",
"(",
"ctx",
"interface",
"{",
"}",
",",
"field",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"field",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"val",
":=",
"options",
".",
"eval",
".",
"evalField",
"(",
"reflect",
".",
"ValueOf",
"(",
"ctx",
")",
",",
"field",
",",
"false",
")",
"\n",
"if",
"!",
"val",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"val",
".",
"Interface",
"(",
")",
"\n",
"}"
] | // Eval evaluates field for given context. | [
"Eval",
"evaluates",
"field",
"for",
"given",
"context",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/helper.go#L258-L273 |
501 | aymerick/raymond | helper.go | isIncludableZero | func (options *Options) isIncludableZero() bool {
b, ok := options.HashProp("includeZero").(bool)
if ok && b {
nb, ok := options.Param(0).(int)
if ok && nb == 0 {
return true
}
}
return false
} | go | func (options *Options) isIncludableZero() bool {
b, ok := options.HashProp("includeZero").(bool)
if ok && b {
nb, ok := options.Param(0).(int)
if ok && nb == 0 {
return true
}
}
return false
} | [
"func",
"(",
"options",
"*",
"Options",
")",
"isIncludableZero",
"(",
")",
"bool",
"{",
"b",
",",
"ok",
":=",
"options",
".",
"HashProp",
"(",
"\"",
"\"",
")",
".",
"(",
"bool",
")",
"\n",
"if",
"ok",
"&&",
"b",
"{",
"nb",
",",
"ok",
":=",
"options",
".",
"Param",
"(",
"0",
")",
".",
"(",
"int",
")",
"\n",
"if",
"ok",
"&&",
"nb",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | //
// Misc
//
// isIncludableZero returns true if 'includeZero' option is set and first param is the number 0 | [
"Misc",
"isIncludableZero",
"returns",
"true",
"if",
"includeZero",
"option",
"is",
"set",
"and",
"first",
"param",
"is",
"the",
"number",
"0"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/helper.go#L280-L290 |
502 | aymerick/raymond | lexer/lexer.go | run | func (l *Lexer) run() {
for l.nextFunc = lexContent; l.nextFunc != nil; {
l.nextFunc = l.nextFunc(l)
}
} | go | func (l *Lexer) run() {
for l.nextFunc = lexContent; l.nextFunc != nil; {
l.nextFunc = l.nextFunc(l)
}
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"run",
"(",
")",
"{",
"for",
"l",
".",
"nextFunc",
"=",
"lexContent",
";",
"l",
".",
"nextFunc",
"!=",
"nil",
";",
"{",
"l",
".",
"nextFunc",
"=",
"l",
".",
"nextFunc",
"(",
"l",
")",
"\n",
"}",
"\n",
"}"
] | // run starts lexical analysis | [
"run",
"starts",
"lexical",
"analysis"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L135-L139 |
503 | aymerick/raymond | lexer/lexer.go | emit | func (l *Lexer) emit(kind TokenKind) {
l.produce(kind, l.input[l.start:l.pos])
} | go | func (l *Lexer) emit(kind TokenKind) {
l.produce(kind, l.input[l.start:l.pos])
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"emit",
"(",
"kind",
"TokenKind",
")",
"{",
"l",
".",
"produce",
"(",
"kind",
",",
"l",
".",
"input",
"[",
"l",
".",
"start",
":",
"l",
".",
"pos",
"]",
")",
"\n",
"}"
] | // emit emits a new scanned token | [
"emit",
"emits",
"a",
"new",
"scanned",
"token"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L166-L168 |
504 | aymerick/raymond | lexer/lexer.go | emitContent | func (l *Lexer) emitContent() {
if l.pos > l.start {
l.emit(TokenContent)
}
} | go | func (l *Lexer) emitContent() {
if l.pos > l.start {
l.emit(TokenContent)
}
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"emitContent",
"(",
")",
"{",
"if",
"l",
".",
"pos",
">",
"l",
".",
"start",
"{",
"l",
".",
"emit",
"(",
"TokenContent",
")",
"\n",
"}",
"\n",
"}"
] | // emitContent emits scanned content | [
"emitContent",
"emits",
"scanned",
"content"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L171-L175 |
505 | aymerick/raymond | lexer/lexer.go | emitString | func (l *Lexer) emitString(delimiter rune) {
str := l.input[l.start:l.pos]
// replace escaped delimiters
str = strings.Replace(str, "\\"+string(delimiter), string(delimiter), -1)
l.produce(TokenString, str)
} | go | func (l *Lexer) emitString(delimiter rune) {
str := l.input[l.start:l.pos]
// replace escaped delimiters
str = strings.Replace(str, "\\"+string(delimiter), string(delimiter), -1)
l.produce(TokenString, str)
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"emitString",
"(",
"delimiter",
"rune",
")",
"{",
"str",
":=",
"l",
".",
"input",
"[",
"l",
".",
"start",
":",
"l",
".",
"pos",
"]",
"\n\n",
"// replace escaped delimiters",
"str",
"=",
"strings",
".",
"Replace",
"(",
"str",
",",
"\"",
"\\\\",
"\"",
"+",
"string",
"(",
"delimiter",
")",
",",
"string",
"(",
"delimiter",
")",
",",
"-",
"1",
")",
"\n\n",
"l",
".",
"produce",
"(",
"TokenString",
",",
"str",
")",
"\n",
"}"
] | // emitString emits a scanned string | [
"emitString",
"emits",
"a",
"scanned",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L178-L185 |
506 | aymerick/raymond | lexer/lexer.go | peek | func (l *Lexer) peek() rune {
r := l.next()
l.backup()
return r
} | go | func (l *Lexer) peek() rune {
r := l.next()
l.backup()
return r
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"peek",
"(",
")",
"rune",
"{",
"r",
":=",
"l",
".",
"next",
"(",
")",
"\n",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // peek returns but does not consume the next character in the input | [
"peek",
"returns",
"but",
"does",
"not",
"consume",
"the",
"next",
"character",
"in",
"the",
"input"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L188-L192 |
507 | aymerick/raymond | lexer/lexer.go | accept | func (l *Lexer) accept(valid string) bool {
if strings.IndexRune(valid, l.next()) >= 0 {
return true
}
l.backup()
return false
} | go | func (l *Lexer) accept(valid string) bool {
if strings.IndexRune(valid, l.next()) >= 0 {
return true
}
l.backup()
return false
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"accept",
"(",
"valid",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"IndexRune",
"(",
"valid",
",",
"l",
".",
"next",
"(",
")",
")",
">=",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"l",
".",
"backup",
"(",
")",
"\n\n",
"return",
"false",
"\n",
"}"
] | // accept scans the next character if it is included in given string | [
"accept",
"scans",
"the",
"next",
"character",
"if",
"it",
"is",
"included",
"in",
"given",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L207-L215 |
508 | aymerick/raymond | lexer/lexer.go | acceptRun | func (l *Lexer) acceptRun(valid string) {
for strings.IndexRune(valid, l.next()) >= 0 {
}
l.backup()
} | go | func (l *Lexer) acceptRun(valid string) {
for strings.IndexRune(valid, l.next()) >= 0 {
}
l.backup()
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"acceptRun",
"(",
"valid",
"string",
")",
"{",
"for",
"strings",
".",
"IndexRune",
"(",
"valid",
",",
"l",
".",
"next",
"(",
")",
")",
">=",
"0",
"{",
"}",
"\n\n",
"l",
".",
"backup",
"(",
")",
"\n",
"}"
] | // acceptRun scans all following characters that are part of given string | [
"acceptRun",
"scans",
"all",
"following",
"characters",
"that",
"are",
"part",
"of",
"given",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L218-L223 |
509 | aymerick/raymond | lexer/lexer.go | errorf | func (l *Lexer) errorf(format string, args ...interface{}) lexFunc {
l.tokens <- Token{TokenError, fmt.Sprintf(format, args...), l.start, l.line}
return nil
} | go | func (l *Lexer) errorf(format string, args ...interface{}) lexFunc {
l.tokens <- Token{TokenError, fmt.Sprintf(format, args...), l.start, l.line}
return nil
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"errorf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"lexFunc",
"{",
"l",
".",
"tokens",
"<-",
"Token",
"{",
"TokenError",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
",",
"l",
".",
"start",
",",
"l",
".",
"line",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // errorf emits an error token | [
"errorf",
"emits",
"an",
"error",
"token"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L226-L229 |
510 | aymerick/raymond | lexer/lexer.go | isString | func (l *Lexer) isString(str string) bool {
return strings.HasPrefix(l.input[l.pos:], str)
} | go | func (l *Lexer) isString(str string) bool {
return strings.HasPrefix(l.input[l.pos:], str)
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"isString",
"(",
"str",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"]",
",",
"str",
")",
"\n",
"}"
] | // isString returns true if content at current scanning position starts with given string | [
"isString",
"returns",
"true",
"if",
"content",
"at",
"current",
"scanning",
"position",
"starts",
"with",
"given",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L232-L234 |
511 | aymerick/raymond | lexer/lexer.go | findRegexp | func (l *Lexer) findRegexp(r *regexp.Regexp) string {
return r.FindString(l.input[l.pos:])
} | go | func (l *Lexer) findRegexp(r *regexp.Regexp) string {
return r.FindString(l.input[l.pos:])
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"findRegexp",
"(",
"r",
"*",
"regexp",
".",
"Regexp",
")",
"string",
"{",
"return",
"r",
".",
"FindString",
"(",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"]",
")",
"\n",
"}"
] | // findRegexp returns the first string from current scanning position that matches given regular expression | [
"findRegexp",
"returns",
"the",
"first",
"string",
"from",
"current",
"scanning",
"position",
"that",
"matches",
"given",
"regular",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L237-L239 |
512 | aymerick/raymond | lexer/lexer.go | indexRegexp | func (l *Lexer) indexRegexp(r *regexp.Regexp) int {
loc := r.FindStringIndex(l.input[l.pos:])
if loc == nil {
return -1
}
return loc[0]
} | go | func (l *Lexer) indexRegexp(r *regexp.Regexp) int {
loc := r.FindStringIndex(l.input[l.pos:])
if loc == nil {
return -1
}
return loc[0]
} | [
"func",
"(",
"l",
"*",
"Lexer",
")",
"indexRegexp",
"(",
"r",
"*",
"regexp",
".",
"Regexp",
")",
"int",
"{",
"loc",
":=",
"r",
".",
"FindStringIndex",
"(",
"l",
".",
"input",
"[",
"l",
".",
"pos",
":",
"]",
")",
"\n",
"if",
"loc",
"==",
"nil",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"loc",
"[",
"0",
"]",
"\n",
"}"
] | // indexRegexp returns the index of the first string from current scanning position that matches given regular expression
//
// It returns -1 if not found | [
"indexRegexp",
"returns",
"the",
"index",
"of",
"the",
"first",
"string",
"from",
"current",
"scanning",
"position",
"that",
"matches",
"given",
"regular",
"expression",
"It",
"returns",
"-",
"1",
"if",
"not",
"found"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L244-L250 |
513 | aymerick/raymond | lexer/lexer.go | lexCloseMustache | func lexCloseMustache(l *Lexer) lexFunc {
var str string
var tok TokenKind
if str = l.findRegexp(rCloseRaw); str != "" {
// }}}}
tok = TokenCloseRawBlock
} else if str = l.findRegexp(rCloseUnescaped); str != "" {
// }}}
tok = TokenCloseUnescaped
} else if str = l.findRegexp(rClose); str != "" {
// }}
tok = TokenClose
} else {
// this is rotten
panic("Current pos MUST be a closing mustache")
}
l.pos += len(str)
l.emit(tok)
return lexContent
} | go | func lexCloseMustache(l *Lexer) lexFunc {
var str string
var tok TokenKind
if str = l.findRegexp(rCloseRaw); str != "" {
// }}}}
tok = TokenCloseRawBlock
} else if str = l.findRegexp(rCloseUnescaped); str != "" {
// }}}
tok = TokenCloseUnescaped
} else if str = l.findRegexp(rClose); str != "" {
// }}
tok = TokenClose
} else {
// this is rotten
panic("Current pos MUST be a closing mustache")
}
l.pos += len(str)
l.emit(tok)
return lexContent
} | [
"func",
"lexCloseMustache",
"(",
"l",
"*",
"Lexer",
")",
"lexFunc",
"{",
"var",
"str",
"string",
"\n",
"var",
"tok",
"TokenKind",
"\n\n",
"if",
"str",
"=",
"l",
".",
"findRegexp",
"(",
"rCloseRaw",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"// }}}}",
"tok",
"=",
"TokenCloseRawBlock",
"\n",
"}",
"else",
"if",
"str",
"=",
"l",
".",
"findRegexp",
"(",
"rCloseUnescaped",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"// }}}",
"tok",
"=",
"TokenCloseUnescaped",
"\n",
"}",
"else",
"if",
"str",
"=",
"l",
".",
"findRegexp",
"(",
"rClose",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"// }}",
"tok",
"=",
"TokenClose",
"\n",
"}",
"else",
"{",
"// this is rotten",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"l",
".",
"pos",
"+=",
"len",
"(",
"str",
")",
"\n",
"l",
".",
"emit",
"(",
"tok",
")",
"\n\n",
"return",
"lexContent",
"\n",
"}"
] | // lexCloseMustache scans }} or ~}} | [
"lexCloseMustache",
"scans",
"}}",
"or",
"~",
"}}"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L373-L395 |
514 | aymerick/raymond | lexer/lexer.go | lexExpression | func lexExpression(l *Lexer) lexFunc {
// search close mustache delimiter
if l.isString(closeMustache) || l.isString(closeStripMustache) || l.isString(closeUnescapedStripMustache) {
return lexCloseMustache
}
// search some patterns before advancing scanning position
// "as |"
if str := l.findRegexp(rOpenBlockParams); str != "" {
l.pos += len(str)
l.emit(TokenOpenBlockParams)
return lexExpression
}
// ..
if l.isString("..") {
l.pos += len("..")
l.emit(TokenID)
return lexExpression
}
// .
if str := l.findRegexp(rDotID); str != "" {
l.pos += len(".")
l.emit(TokenID)
return lexExpression
}
// true
if str := l.findRegexp(rTrue); str != "" {
l.pos += len("true")
l.emit(TokenBoolean)
return lexExpression
}
// false
if str := l.findRegexp(rFalse); str != "" {
l.pos += len("false")
l.emit(TokenBoolean)
return lexExpression
}
// let's scan next character
switch r := l.next(); {
case r == eof:
return l.errorf("Unclosed expression")
case isIgnorable(r):
return lexIgnorable
case r == '(':
l.emit(TokenOpenSexpr)
case r == ')':
l.emit(TokenCloseSexpr)
case r == '=':
l.emit(TokenEquals)
case r == '@':
l.emit(TokenData)
case r == '"' || r == '\'':
l.backup()
return lexString
case r == '/' || r == '.':
l.emit(TokenSep)
case r == '|':
l.emit(TokenCloseBlockParams)
case r == '+' || r == '-' || (r >= '0' && r <= '9'):
l.backup()
return lexNumber
case r == '[':
return lexPathLiteral
case strings.IndexRune(unallowedIDChars, r) < 0:
l.backup()
return lexIdentifier
default:
return l.errorf("Unexpected character in expression: '%c'", r)
}
return lexExpression
} | go | func lexExpression(l *Lexer) lexFunc {
// search close mustache delimiter
if l.isString(closeMustache) || l.isString(closeStripMustache) || l.isString(closeUnescapedStripMustache) {
return lexCloseMustache
}
// search some patterns before advancing scanning position
// "as |"
if str := l.findRegexp(rOpenBlockParams); str != "" {
l.pos += len(str)
l.emit(TokenOpenBlockParams)
return lexExpression
}
// ..
if l.isString("..") {
l.pos += len("..")
l.emit(TokenID)
return lexExpression
}
// .
if str := l.findRegexp(rDotID); str != "" {
l.pos += len(".")
l.emit(TokenID)
return lexExpression
}
// true
if str := l.findRegexp(rTrue); str != "" {
l.pos += len("true")
l.emit(TokenBoolean)
return lexExpression
}
// false
if str := l.findRegexp(rFalse); str != "" {
l.pos += len("false")
l.emit(TokenBoolean)
return lexExpression
}
// let's scan next character
switch r := l.next(); {
case r == eof:
return l.errorf("Unclosed expression")
case isIgnorable(r):
return lexIgnorable
case r == '(':
l.emit(TokenOpenSexpr)
case r == ')':
l.emit(TokenCloseSexpr)
case r == '=':
l.emit(TokenEquals)
case r == '@':
l.emit(TokenData)
case r == '"' || r == '\'':
l.backup()
return lexString
case r == '/' || r == '.':
l.emit(TokenSep)
case r == '|':
l.emit(TokenCloseBlockParams)
case r == '+' || r == '-' || (r >= '0' && r <= '9'):
l.backup()
return lexNumber
case r == '[':
return lexPathLiteral
case strings.IndexRune(unallowedIDChars, r) < 0:
l.backup()
return lexIdentifier
default:
return l.errorf("Unexpected character in expression: '%c'", r)
}
return lexExpression
} | [
"func",
"lexExpression",
"(",
"l",
"*",
"Lexer",
")",
"lexFunc",
"{",
"// search close mustache delimiter",
"if",
"l",
".",
"isString",
"(",
"closeMustache",
")",
"||",
"l",
".",
"isString",
"(",
"closeStripMustache",
")",
"||",
"l",
".",
"isString",
"(",
"closeUnescapedStripMustache",
")",
"{",
"return",
"lexCloseMustache",
"\n",
"}",
"\n\n",
"// search some patterns before advancing scanning position",
"// \"as |\"",
"if",
"str",
":=",
"l",
".",
"findRegexp",
"(",
"rOpenBlockParams",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"l",
".",
"pos",
"+=",
"len",
"(",
"str",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenOpenBlockParams",
")",
"\n",
"return",
"lexExpression",
"\n",
"}",
"\n\n",
"// ..",
"if",
"l",
".",
"isString",
"(",
"\"",
"\"",
")",
"{",
"l",
".",
"pos",
"+=",
"len",
"(",
"\"",
"\"",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenID",
")",
"\n",
"return",
"lexExpression",
"\n",
"}",
"\n\n",
"// .",
"if",
"str",
":=",
"l",
".",
"findRegexp",
"(",
"rDotID",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"l",
".",
"pos",
"+=",
"len",
"(",
"\"",
"\"",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenID",
")",
"\n",
"return",
"lexExpression",
"\n",
"}",
"\n\n",
"// true",
"if",
"str",
":=",
"l",
".",
"findRegexp",
"(",
"rTrue",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"l",
".",
"pos",
"+=",
"len",
"(",
"\"",
"\"",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenBoolean",
")",
"\n",
"return",
"lexExpression",
"\n",
"}",
"\n\n",
"// false",
"if",
"str",
":=",
"l",
".",
"findRegexp",
"(",
"rFalse",
")",
";",
"str",
"!=",
"\"",
"\"",
"{",
"l",
".",
"pos",
"+=",
"len",
"(",
"\"",
"\"",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenBoolean",
")",
"\n",
"return",
"lexExpression",
"\n",
"}",
"\n\n",
"// let's scan next character",
"switch",
"r",
":=",
"l",
".",
"next",
"(",
")",
";",
"{",
"case",
"r",
"==",
"eof",
":",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"isIgnorable",
"(",
"r",
")",
":",
"return",
"lexIgnorable",
"\n",
"case",
"r",
"==",
"'('",
":",
"l",
".",
"emit",
"(",
"TokenOpenSexpr",
")",
"\n",
"case",
"r",
"==",
"')'",
":",
"l",
".",
"emit",
"(",
"TokenCloseSexpr",
")",
"\n",
"case",
"r",
"==",
"'='",
":",
"l",
".",
"emit",
"(",
"TokenEquals",
")",
"\n",
"case",
"r",
"==",
"'@'",
":",
"l",
".",
"emit",
"(",
"TokenData",
")",
"\n",
"case",
"r",
"==",
"'\"'",
"||",
"r",
"==",
"'\\''",
":",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"lexString",
"\n",
"case",
"r",
"==",
"'/'",
"||",
"r",
"==",
"'.'",
":",
"l",
".",
"emit",
"(",
"TokenSep",
")",
"\n",
"case",
"r",
"==",
"'|'",
":",
"l",
".",
"emit",
"(",
"TokenCloseBlockParams",
")",
"\n",
"case",
"r",
"==",
"'+'",
"||",
"r",
"==",
"'-'",
"||",
"(",
"r",
">=",
"'0'",
"&&",
"r",
"<=",
"'9'",
")",
":",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"lexNumber",
"\n",
"case",
"r",
"==",
"'['",
":",
"return",
"lexPathLiteral",
"\n",
"case",
"strings",
".",
"IndexRune",
"(",
"unallowedIDChars",
",",
"r",
")",
"<",
"0",
":",
"l",
".",
"backup",
"(",
")",
"\n",
"return",
"lexIdentifier",
"\n",
"default",
":",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n\n",
"return",
"lexExpression",
"\n",
"}"
] | // lexExpression scans inside mustaches | [
"lexExpression",
"scans",
"inside",
"mustaches"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L398-L475 |
515 | aymerick/raymond | lexer/lexer.go | lexIgnorable | func lexIgnorable(l *Lexer) lexFunc {
for isIgnorable(l.peek()) {
l.next()
}
l.ignore()
return lexExpression
} | go | func lexIgnorable(l *Lexer) lexFunc {
for isIgnorable(l.peek()) {
l.next()
}
l.ignore()
return lexExpression
} | [
"func",
"lexIgnorable",
"(",
"l",
"*",
"Lexer",
")",
"lexFunc",
"{",
"for",
"isIgnorable",
"(",
"l",
".",
"peek",
"(",
")",
")",
"{",
"l",
".",
"next",
"(",
")",
"\n",
"}",
"\n",
"l",
".",
"ignore",
"(",
")",
"\n\n",
"return",
"lexExpression",
"\n",
"}"
] | // lexIgnorable scans all following ignorable characters | [
"lexIgnorable",
"scans",
"all",
"following",
"ignorable",
"characters"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L494-L501 |
516 | aymerick/raymond | lexer/lexer.go | lexString | func lexString(l *Lexer) lexFunc {
// get string delimiter
delim := l.next()
var prev rune
// ignore delimiter
l.ignore()
for {
r := l.next()
if r == eof || r == '\n' {
return l.errorf("Unterminated string")
}
if (r == delim) && (prev != '\\') {
break
}
prev = r
}
// remove end delimiter
l.backup()
// emit string
l.emitString(delim)
// skip end delimiter
l.next()
l.ignore()
return lexExpression
} | go | func lexString(l *Lexer) lexFunc {
// get string delimiter
delim := l.next()
var prev rune
// ignore delimiter
l.ignore()
for {
r := l.next()
if r == eof || r == '\n' {
return l.errorf("Unterminated string")
}
if (r == delim) && (prev != '\\') {
break
}
prev = r
}
// remove end delimiter
l.backup()
// emit string
l.emitString(delim)
// skip end delimiter
l.next()
l.ignore()
return lexExpression
} | [
"func",
"lexString",
"(",
"l",
"*",
"Lexer",
")",
"lexFunc",
"{",
"// get string delimiter",
"delim",
":=",
"l",
".",
"next",
"(",
")",
"\n",
"var",
"prev",
"rune",
"\n\n",
"// ignore delimiter",
"l",
".",
"ignore",
"(",
")",
"\n\n",
"for",
"{",
"r",
":=",
"l",
".",
"next",
"(",
")",
"\n",
"if",
"r",
"==",
"eof",
"||",
"r",
"==",
"'\\n'",
"{",
"return",
"l",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"(",
"r",
"==",
"delim",
")",
"&&",
"(",
"prev",
"!=",
"'\\\\'",
")",
"{",
"break",
"\n",
"}",
"\n\n",
"prev",
"=",
"r",
"\n",
"}",
"\n\n",
"// remove end delimiter",
"l",
".",
"backup",
"(",
")",
"\n\n",
"// emit string",
"l",
".",
"emitString",
"(",
"delim",
")",
"\n\n",
"// skip end delimiter",
"l",
".",
"next",
"(",
")",
"\n",
"l",
".",
"ignore",
"(",
")",
"\n\n",
"return",
"lexExpression",
"\n",
"}"
] | // lexString scans a string | [
"lexString",
"scans",
"a",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L504-L536 |
517 | aymerick/raymond | lexer/lexer.go | lexIdentifier | func lexIdentifier(l *Lexer) lexFunc {
str := l.findRegexp(rID)
if len(str) == 0 {
// this is rotten
panic("Identifier expected")
}
l.pos += len(str)
l.emit(TokenID)
return lexExpression
} | go | func lexIdentifier(l *Lexer) lexFunc {
str := l.findRegexp(rID)
if len(str) == 0 {
// this is rotten
panic("Identifier expected")
}
l.pos += len(str)
l.emit(TokenID)
return lexExpression
} | [
"func",
"lexIdentifier",
"(",
"l",
"*",
"Lexer",
")",
"lexFunc",
"{",
"str",
":=",
"l",
".",
"findRegexp",
"(",
"rID",
")",
"\n",
"if",
"len",
"(",
"str",
")",
"==",
"0",
"{",
"// this is rotten",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"l",
".",
"pos",
"+=",
"len",
"(",
"str",
")",
"\n",
"l",
".",
"emit",
"(",
"TokenID",
")",
"\n\n",
"return",
"lexExpression",
"\n",
"}"
] | // lexIdentifier scans an ID | [
"lexIdentifier",
"scans",
"an",
"ID"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/lexer.go#L598-L609 |
518 | aymerick/raymond | utils.go | IsTrue | func IsTrue(obj interface{}) bool {
thruth, ok := isTrueValue(reflect.ValueOf(obj))
if !ok {
return false
}
return thruth
} | go | func IsTrue(obj interface{}) bool {
thruth, ok := isTrueValue(reflect.ValueOf(obj))
if !ok {
return false
}
return thruth
} | [
"func",
"IsTrue",
"(",
"obj",
"interface",
"{",
"}",
")",
"bool",
"{",
"thruth",
",",
"ok",
":=",
"isTrueValue",
"(",
"reflect",
".",
"ValueOf",
"(",
"obj",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"thruth",
"\n",
"}"
] | // IsTrue returns true if obj is a truthy value. | [
"IsTrue",
"returns",
"true",
"if",
"obj",
"is",
"a",
"truthy",
"value",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/utils.go#L26-L32 |
519 | aymerick/raymond | lexer/token.go | String | func (k TokenKind) String() string {
s := tokenName[k]
if s == "" {
return fmt.Sprintf("Token-%d", int(k))
}
return s
} | go | func (k TokenKind) String() string {
s := tokenName[k]
if s == "" {
return fmt.Sprintf("Token-%d", int(k))
}
return s
} | [
"func",
"(",
"k",
"TokenKind",
")",
"String",
"(",
")",
"string",
"{",
"s",
":=",
"tokenName",
"[",
"k",
"]",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"int",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // String returns the token kind string representation for debugging. | [
"String",
"returns",
"the",
"token",
"kind",
"string",
"representation",
"for",
"debugging",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/token.go#L156-L162 |
520 | aymerick/raymond | lexer/token.go | String | func (t Token) String() string {
result := ""
if dumpTokenPos {
result += fmt.Sprintf("%d:", t.Pos)
}
result += fmt.Sprintf("%s", t.Kind)
if (dumpAllTokensVal || (t.Kind >= TokenContent)) && len(t.Val) > 0 {
if len(t.Val) > 100 {
result += fmt.Sprintf("{%.20q...}", t.Val)
} else {
result += fmt.Sprintf("{%q}", t.Val)
}
}
return result
} | go | func (t Token) String() string {
result := ""
if dumpTokenPos {
result += fmt.Sprintf("%d:", t.Pos)
}
result += fmt.Sprintf("%s", t.Kind)
if (dumpAllTokensVal || (t.Kind >= TokenContent)) && len(t.Val) > 0 {
if len(t.Val) > 100 {
result += fmt.Sprintf("{%.20q...}", t.Val)
} else {
result += fmt.Sprintf("{%q}", t.Val)
}
}
return result
} | [
"func",
"(",
"t",
"Token",
")",
"String",
"(",
")",
"string",
"{",
"result",
":=",
"\"",
"\"",
"\n\n",
"if",
"dumpTokenPos",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Pos",
")",
"\n",
"}",
"\n\n",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Kind",
")",
"\n\n",
"if",
"(",
"dumpAllTokensVal",
"||",
"(",
"t",
".",
"Kind",
">=",
"TokenContent",
")",
")",
"&&",
"len",
"(",
"t",
".",
"Val",
")",
">",
"0",
"{",
"if",
"len",
"(",
"t",
".",
"Val",
")",
">",
"100",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Val",
")",
"\n",
"}",
"else",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Val",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // String returns the token string representation for debugging. | [
"String",
"returns",
"the",
"token",
"string",
"representation",
"for",
"debugging",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/lexer/token.go#L165-L183 |
521 | aymerick/raymond | template.go | newTemplate | func newTemplate(source string) *Template {
return &Template{
source: source,
helpers: make(map[string]reflect.Value),
partials: make(map[string]*partial),
}
} | go | func newTemplate(source string) *Template {
return &Template{
source: source,
helpers: make(map[string]reflect.Value),
partials: make(map[string]*partial),
}
} | [
"func",
"newTemplate",
"(",
"source",
"string",
")",
"*",
"Template",
"{",
"return",
"&",
"Template",
"{",
"source",
":",
"source",
",",
"helpers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"reflect",
".",
"Value",
")",
",",
"partials",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"partial",
")",
",",
"}",
"\n",
"}"
] | // newTemplate instanciate a new template without parsing it | [
"newTemplate",
"instanciate",
"a",
"new",
"template",
"without",
"parsing",
"it"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L24-L30 |
522 | aymerick/raymond | template.go | Parse | func Parse(source string) (*Template, error) {
tpl := newTemplate(source)
// parse template
if err := tpl.parse(); err != nil {
return nil, err
}
return tpl, nil
} | go | func Parse(source string) (*Template, error) {
tpl := newTemplate(source)
// parse template
if err := tpl.parse(); err != nil {
return nil, err
}
return tpl, nil
} | [
"func",
"Parse",
"(",
"source",
"string",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"tpl",
":=",
"newTemplate",
"(",
"source",
")",
"\n\n",
"// parse template",
"if",
"err",
":=",
"tpl",
".",
"parse",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"tpl",
",",
"nil",
"\n",
"}"
] | // Parse instanciates a template by parsing given source. | [
"Parse",
"instanciates",
"a",
"template",
"by",
"parsing",
"given",
"source",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L33-L42 |
523 | aymerick/raymond | template.go | MustParse | func MustParse(source string) *Template {
result, err := Parse(source)
if err != nil {
panic(err)
}
return result
} | go | func MustParse(source string) *Template {
result, err := Parse(source)
if err != nil {
panic(err)
}
return result
} | [
"func",
"MustParse",
"(",
"source",
"string",
")",
"*",
"Template",
"{",
"result",
",",
"err",
":=",
"Parse",
"(",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // MustParse instanciates a template by parsing given source. It panics on error. | [
"MustParse",
"instanciates",
"a",
"template",
"by",
"parsing",
"given",
"source",
".",
"It",
"panics",
"on",
"error",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L45-L51 |
524 | aymerick/raymond | template.go | ParseFile | func ParseFile(filePath string) (*Template, error) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
return Parse(string(b))
} | go | func ParseFile(filePath string) (*Template, error) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
return Parse(string(b))
} | [
"func",
"ParseFile",
"(",
"filePath",
"string",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"Parse",
"(",
"string",
"(",
"b",
")",
")",
"\n",
"}"
] | // ParseFile reads given file and returns parsed template. | [
"ParseFile",
"reads",
"given",
"file",
"and",
"returns",
"parsed",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L54-L61 |
525 | aymerick/raymond | template.go | parse | func (tpl *Template) parse() error {
if tpl.program == nil {
var err error
tpl.program, err = parser.Parse(tpl.source)
if err != nil {
return err
}
}
return nil
} | go | func (tpl *Template) parse() error {
if tpl.program == nil {
var err error
tpl.program, err = parser.Parse(tpl.source)
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"parse",
"(",
")",
"error",
"{",
"if",
"tpl",
".",
"program",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n\n",
"tpl",
".",
"program",
",",
"err",
"=",
"parser",
".",
"Parse",
"(",
"tpl",
".",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // parse parses the template
//
// It can be called several times, the parsing will be done only once. | [
"parse",
"parses",
"the",
"template",
"It",
"can",
"be",
"called",
"several",
"times",
"the",
"parsing",
"will",
"be",
"done",
"only",
"once",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L66-L77 |
526 | aymerick/raymond | template.go | Clone | func (tpl *Template) Clone() *Template {
result := newTemplate(tpl.source)
result.program = tpl.program
tpl.mutex.RLock()
defer tpl.mutex.RUnlock()
for name, helper := range tpl.helpers {
result.RegisterHelper(name, helper.Interface())
}
for name, partial := range tpl.partials {
result.addPartial(name, partial.source, partial.tpl)
}
return result
} | go | func (tpl *Template) Clone() *Template {
result := newTemplate(tpl.source)
result.program = tpl.program
tpl.mutex.RLock()
defer tpl.mutex.RUnlock()
for name, helper := range tpl.helpers {
result.RegisterHelper(name, helper.Interface())
}
for name, partial := range tpl.partials {
result.addPartial(name, partial.source, partial.tpl)
}
return result
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"Clone",
"(",
")",
"*",
"Template",
"{",
"result",
":=",
"newTemplate",
"(",
"tpl",
".",
"source",
")",
"\n\n",
"result",
".",
"program",
"=",
"tpl",
".",
"program",
"\n\n",
"tpl",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tpl",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"name",
",",
"helper",
":=",
"range",
"tpl",
".",
"helpers",
"{",
"result",
".",
"RegisterHelper",
"(",
"name",
",",
"helper",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n\n",
"for",
"name",
",",
"partial",
":=",
"range",
"tpl",
".",
"partials",
"{",
"result",
".",
"addPartial",
"(",
"name",
",",
"partial",
".",
"source",
",",
"partial",
".",
"tpl",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // Clone returns a copy of that template. | [
"Clone",
"returns",
"a",
"copy",
"of",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L80-L97 |
527 | aymerick/raymond | template.go | RegisterHelper | func (tpl *Template) RegisterHelper(name string, helper interface{}) {
tpl.mutex.Lock()
defer tpl.mutex.Unlock()
if tpl.helpers[name] != zero {
panic(fmt.Sprintf("Helper %s already registered", name))
}
val := reflect.ValueOf(helper)
ensureValidHelper(name, val)
tpl.helpers[name] = val
} | go | func (tpl *Template) RegisterHelper(name string, helper interface{}) {
tpl.mutex.Lock()
defer tpl.mutex.Unlock()
if tpl.helpers[name] != zero {
panic(fmt.Sprintf("Helper %s already registered", name))
}
val := reflect.ValueOf(helper)
ensureValidHelper(name, val)
tpl.helpers[name] = val
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterHelper",
"(",
"name",
"string",
",",
"helper",
"interface",
"{",
"}",
")",
"{",
"tpl",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tpl",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"tpl",
".",
"helpers",
"[",
"name",
"]",
"!=",
"zero",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n\n",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"helper",
")",
"\n",
"ensureValidHelper",
"(",
"name",
",",
"val",
")",
"\n\n",
"tpl",
".",
"helpers",
"[",
"name",
"]",
"=",
"val",
"\n",
"}"
] | // RegisterHelper registers a helper for that template. | [
"RegisterHelper",
"registers",
"a",
"helper",
"for",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L107-L119 |
528 | aymerick/raymond | template.go | RegisterHelpers | func (tpl *Template) RegisterHelpers(helpers map[string]interface{}) {
for name, helper := range helpers {
tpl.RegisterHelper(name, helper)
}
} | go | func (tpl *Template) RegisterHelpers(helpers map[string]interface{}) {
for name, helper := range helpers {
tpl.RegisterHelper(name, helper)
}
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterHelpers",
"(",
"helpers",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"for",
"name",
",",
"helper",
":=",
"range",
"helpers",
"{",
"tpl",
".",
"RegisterHelper",
"(",
"name",
",",
"helper",
")",
"\n",
"}",
"\n",
"}"
] | // RegisterHelpers registers several helpers for that template. | [
"RegisterHelpers",
"registers",
"several",
"helpers",
"for",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L122-L126 |
529 | aymerick/raymond | template.go | RegisterPartial | func (tpl *Template) RegisterPartial(name string, source string) {
tpl.addPartial(name, source, nil)
} | go | func (tpl *Template) RegisterPartial(name string, source string) {
tpl.addPartial(name, source, nil)
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterPartial",
"(",
"name",
"string",
",",
"source",
"string",
")",
"{",
"tpl",
".",
"addPartial",
"(",
"name",
",",
"source",
",",
"nil",
")",
"\n",
"}"
] | // RegisterPartial registers a partial for that template. | [
"RegisterPartial",
"registers",
"a",
"partial",
"for",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L147-L149 |
530 | aymerick/raymond | template.go | RegisterPartials | func (tpl *Template) RegisterPartials(partials map[string]string) {
for name, partial := range partials {
tpl.RegisterPartial(name, partial)
}
} | go | func (tpl *Template) RegisterPartials(partials map[string]string) {
for name, partial := range partials {
tpl.RegisterPartial(name, partial)
}
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterPartials",
"(",
"partials",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"for",
"name",
",",
"partial",
":=",
"range",
"partials",
"{",
"tpl",
".",
"RegisterPartial",
"(",
"name",
",",
"partial",
")",
"\n",
"}",
"\n",
"}"
] | // RegisterPartials registers several partials for that template. | [
"RegisterPartials",
"registers",
"several",
"partials",
"for",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L152-L156 |
531 | aymerick/raymond | template.go | RegisterPartialFile | func (tpl *Template) RegisterPartialFile(filePath string, name string) error {
b, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
tpl.RegisterPartial(name, string(b))
return nil
} | go | func (tpl *Template) RegisterPartialFile(filePath string, name string) error {
b, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
tpl.RegisterPartial(name, string(b))
return nil
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterPartialFile",
"(",
"filePath",
"string",
",",
"name",
"string",
")",
"error",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tpl",
".",
"RegisterPartial",
"(",
"name",
",",
"string",
"(",
"b",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // RegisterPartialFile reads given file and registers its content as a partial with given name. | [
"RegisterPartialFile",
"reads",
"given",
"file",
"and",
"registers",
"its",
"content",
"as",
"a",
"partial",
"with",
"given",
"name",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L159-L168 |
532 | aymerick/raymond | template.go | RegisterPartialFiles | func (tpl *Template) RegisterPartialFiles(filePaths ...string) error {
if len(filePaths) == 0 {
return nil
}
for _, filePath := range filePaths {
name := fileBase(filePath)
if err := tpl.RegisterPartialFile(filePath, name); err != nil {
return err
}
}
return nil
} | go | func (tpl *Template) RegisterPartialFiles(filePaths ...string) error {
if len(filePaths) == 0 {
return nil
}
for _, filePath := range filePaths {
name := fileBase(filePath)
if err := tpl.RegisterPartialFile(filePath, name); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterPartialFiles",
"(",
"filePaths",
"...",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"filePaths",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"filePath",
":=",
"range",
"filePaths",
"{",
"name",
":=",
"fileBase",
"(",
"filePath",
")",
"\n\n",
"if",
"err",
":=",
"tpl",
".",
"RegisterPartialFile",
"(",
"filePath",
",",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // RegisterPartialFiles reads several files and registers them as partials, the filename base is used as the partial name. | [
"RegisterPartialFiles",
"reads",
"several",
"files",
"and",
"registers",
"them",
"as",
"partials",
"the",
"filename",
"base",
"is",
"used",
"as",
"the",
"partial",
"name",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L171-L185 |
533 | aymerick/raymond | template.go | RegisterPartialTemplate | func (tpl *Template) RegisterPartialTemplate(name string, template *Template) {
tpl.addPartial(name, "", template)
} | go | func (tpl *Template) RegisterPartialTemplate(name string, template *Template) {
tpl.addPartial(name, "", template)
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"RegisterPartialTemplate",
"(",
"name",
"string",
",",
"template",
"*",
"Template",
")",
"{",
"tpl",
".",
"addPartial",
"(",
"name",
",",
"\"",
"\"",
",",
"template",
")",
"\n",
"}"
] | // RegisterPartialTemplate registers an already parsed partial for that template. | [
"RegisterPartialTemplate",
"registers",
"an",
"already",
"parsed",
"partial",
"for",
"that",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L188-L190 |
534 | aymerick/raymond | template.go | Exec | func (tpl *Template) Exec(ctx interface{}) (result string, err error) {
return tpl.ExecWith(ctx, nil)
} | go | func (tpl *Template) Exec(ctx interface{}) (result string, err error) {
return tpl.ExecWith(ctx, nil)
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"Exec",
"(",
"ctx",
"interface",
"{",
"}",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"return",
"tpl",
".",
"ExecWith",
"(",
"ctx",
",",
"nil",
")",
"\n",
"}"
] | // Exec evaluates template with given context. | [
"Exec",
"evaluates",
"template",
"with",
"given",
"context",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L193-L195 |
535 | aymerick/raymond | template.go | MustExec | func (tpl *Template) MustExec(ctx interface{}) string {
result, err := tpl.Exec(ctx)
if err != nil {
panic(err)
}
return result
} | go | func (tpl *Template) MustExec(ctx interface{}) string {
result, err := tpl.Exec(ctx)
if err != nil {
panic(err)
}
return result
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"MustExec",
"(",
"ctx",
"interface",
"{",
"}",
")",
"string",
"{",
"result",
",",
"err",
":=",
"tpl",
".",
"Exec",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // MustExec evaluates template with given context. It panics on error. | [
"MustExec",
"evaluates",
"template",
"with",
"given",
"context",
".",
"It",
"panics",
"on",
"error",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L198-L204 |
536 | aymerick/raymond | template.go | ExecWith | func (tpl *Template) ExecWith(ctx interface{}, privData *DataFrame) (result string, err error) {
defer errRecover(&err)
// parses template if necessary
err = tpl.parse()
if err != nil {
return
}
// setup visitor
v := newEvalVisitor(tpl, ctx, privData)
// visit AST
result, _ = tpl.program.Accept(v).(string)
// named return values
return
} | go | func (tpl *Template) ExecWith(ctx interface{}, privData *DataFrame) (result string, err error) {
defer errRecover(&err)
// parses template if necessary
err = tpl.parse()
if err != nil {
return
}
// setup visitor
v := newEvalVisitor(tpl, ctx, privData)
// visit AST
result, _ = tpl.program.Accept(v).(string)
// named return values
return
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"ExecWith",
"(",
"ctx",
"interface",
"{",
"}",
",",
"privData",
"*",
"DataFrame",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"defer",
"errRecover",
"(",
"&",
"err",
")",
"\n\n",
"// parses template if necessary",
"err",
"=",
"tpl",
".",
"parse",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// setup visitor",
"v",
":=",
"newEvalVisitor",
"(",
"tpl",
",",
"ctx",
",",
"privData",
")",
"\n\n",
"// visit AST",
"result",
",",
"_",
"=",
"tpl",
".",
"program",
".",
"Accept",
"(",
"v",
")",
".",
"(",
"string",
")",
"\n\n",
"// named return values",
"return",
"\n",
"}"
] | // ExecWith evaluates template with given context and private data frame. | [
"ExecWith",
"evaluates",
"template",
"with",
"given",
"context",
"and",
"private",
"data",
"frame",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L207-L224 |
537 | aymerick/raymond | template.go | PrintAST | func (tpl *Template) PrintAST() string {
if err := tpl.parse(); err != nil {
return fmt.Sprintf("PARSER ERROR: %s", err)
}
return ast.Print(tpl.program)
} | go | func (tpl *Template) PrintAST() string {
if err := tpl.parse(); err != nil {
return fmt.Sprintf("PARSER ERROR: %s", err)
}
return ast.Print(tpl.program)
} | [
"func",
"(",
"tpl",
"*",
"Template",
")",
"PrintAST",
"(",
")",
"string",
"{",
"if",
"err",
":=",
"tpl",
".",
"parse",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"ast",
".",
"Print",
"(",
"tpl",
".",
"program",
")",
"\n",
"}"
] | // PrintAST returns string representation of parsed template. | [
"PrintAST",
"returns",
"string",
"representation",
"of",
"parsed",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/template.go#L242-L248 |
538 | aymerick/raymond | ast/print.go | Print | func Print(node Node) string {
visitor := newPrintVisitor()
node.Accept(visitor)
return visitor.output()
} | go | func Print(node Node) string {
visitor := newPrintVisitor()
node.Accept(visitor)
return visitor.output()
} | [
"func",
"Print",
"(",
"node",
"Node",
")",
"string",
"{",
"visitor",
":=",
"newPrintVisitor",
"(",
")",
"\n",
"node",
".",
"Accept",
"(",
"visitor",
")",
"\n",
"return",
"visitor",
".",
"output",
"(",
")",
"\n",
"}"
] | // Print returns a string representation of given AST, that can be used for debugging purpose. | [
"Print",
"returns",
"a",
"string",
"representation",
"of",
"given",
"AST",
"that",
"can",
"be",
"used",
"for",
"debugging",
"purpose",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/print.go#L22-L26 |
539 | aymerick/raymond | ast/print.go | VisitComment | func (v *printVisitor) VisitComment(node *CommentStatement) interface{} {
v.line("{{! '" + node.Value + "' }}")
return nil
} | go | func (v *printVisitor) VisitComment(node *CommentStatement) interface{} {
v.line("{{! '" + node.Value + "' }}")
return nil
} | [
"func",
"(",
"v",
"*",
"printVisitor",
")",
"VisitComment",
"(",
"node",
"*",
"CommentStatement",
")",
"interface",
"{",
"}",
"{",
"v",
".",
"line",
"(",
"\"",
"\"",
"+",
"node",
".",
"Value",
"+",
"\"",
"\"",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // VisitComment implements corresponding Visitor interface method | [
"VisitComment",
"implements",
"corresponding",
"Visitor",
"interface",
"method"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/print.go#L155-L159 |
540 | aymerick/raymond | string.go | isSafeString | func isSafeString(value interface{}) bool {
if _, ok := value.(SafeString); ok {
return true
}
return false
} | go | func isSafeString(value interface{}) bool {
if _, ok := value.(SafeString); ok {
return true
}
return false
} | [
"func",
"isSafeString",
"(",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"_",
",",
"ok",
":=",
"value",
".",
"(",
"SafeString",
")",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isSafeString returns true if argument is a SafeString | [
"isSafeString",
"returns",
"true",
"if",
"argument",
"is",
"a",
"SafeString"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/string.go#L15-L20 |
541 | aymerick/raymond | string.go | strValue | func strValue(value reflect.Value) string {
result := ""
ival, ok := printableValue(value)
if !ok {
panic(fmt.Errorf("Can't print value: %q", value))
}
val := reflect.ValueOf(ival)
switch val.Kind() {
case reflect.Array, reflect.Slice:
for i := 0; i < val.Len(); i++ {
result += strValue(val.Index(i))
}
case reflect.Bool:
result = "false"
if val.Bool() {
result = "true"
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
result = fmt.Sprintf("%d", ival)
case reflect.Float32, reflect.Float64:
result = strconv.FormatFloat(val.Float(), 'f', -1, 64)
case reflect.Invalid:
result = ""
default:
result = fmt.Sprintf("%s", ival)
}
return result
} | go | func strValue(value reflect.Value) string {
result := ""
ival, ok := printableValue(value)
if !ok {
panic(fmt.Errorf("Can't print value: %q", value))
}
val := reflect.ValueOf(ival)
switch val.Kind() {
case reflect.Array, reflect.Slice:
for i := 0; i < val.Len(); i++ {
result += strValue(val.Index(i))
}
case reflect.Bool:
result = "false"
if val.Bool() {
result = "true"
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
result = fmt.Sprintf("%d", ival)
case reflect.Float32, reflect.Float64:
result = strconv.FormatFloat(val.Float(), 'f', -1, 64)
case reflect.Invalid:
result = ""
default:
result = fmt.Sprintf("%s", ival)
}
return result
} | [
"func",
"strValue",
"(",
"value",
"reflect",
".",
"Value",
")",
"string",
"{",
"result",
":=",
"\"",
"\"",
"\n\n",
"ival",
",",
"ok",
":=",
"printableValue",
"(",
"value",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
")",
")",
"\n",
"}",
"\n\n",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"ival",
")",
"\n\n",
"switch",
"val",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Slice",
":",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"val",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"result",
"+=",
"strValue",
"(",
"val",
".",
"Index",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Bool",
":",
"result",
"=",
"\"",
"\"",
"\n",
"if",
"val",
".",
"Bool",
"(",
")",
"{",
"result",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
",",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"result",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ival",
")",
"\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"result",
"=",
"strconv",
".",
"FormatFloat",
"(",
"val",
".",
"Float",
"(",
")",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
"\n",
"case",
"reflect",
".",
"Invalid",
":",
"result",
"=",
"\"",
"\"",
"\n",
"default",
":",
"result",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ival",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // strValue returns string representation of a reflect.Value | [
"strValue",
"returns",
"string",
"representation",
"of",
"a",
"reflect",
".",
"Value"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/string.go#L28-L59 |
542 | aymerick/raymond | partial.go | newPartial | func newPartial(name string, source string, tpl *Template) *partial {
return &partial{
name: name,
source: source,
tpl: tpl,
}
} | go | func newPartial(name string, source string, tpl *Template) *partial {
return &partial{
name: name,
source: source,
tpl: tpl,
}
} | [
"func",
"newPartial",
"(",
"name",
"string",
",",
"source",
"string",
",",
"tpl",
"*",
"Template",
")",
"*",
"partial",
"{",
"return",
"&",
"partial",
"{",
"name",
":",
"name",
",",
"source",
":",
"source",
",",
"tpl",
":",
"tpl",
",",
"}",
"\n",
"}"
] | // newPartial instanciates a new partial | [
"newPartial",
"instanciates",
"a",
"new",
"partial"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L26-L32 |
543 | aymerick/raymond | partial.go | RegisterPartial | func RegisterPartial(name string, source string) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
if partials[name] != nil {
panic(fmt.Errorf("Partial already registered: %s", name))
}
partials[name] = newPartial(name, source, nil)
} | go | func RegisterPartial(name string, source string) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
if partials[name] != nil {
panic(fmt.Errorf("Partial already registered: %s", name))
}
partials[name] = newPartial(name, source, nil)
} | [
"func",
"RegisterPartial",
"(",
"name",
"string",
",",
"source",
"string",
")",
"{",
"partialsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"partialsMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"partials",
"[",
"name",
"]",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n\n",
"partials",
"[",
"name",
"]",
"=",
"newPartial",
"(",
"name",
",",
"source",
",",
"nil",
")",
"\n",
"}"
] | // RegisterPartial registers a global partial. That partial will be available to all templates. | [
"RegisterPartial",
"registers",
"a",
"global",
"partial",
".",
"That",
"partial",
"will",
"be",
"available",
"to",
"all",
"templates",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L35-L44 |
544 | aymerick/raymond | partial.go | RegisterPartials | func RegisterPartials(partials map[string]string) {
for name, p := range partials {
RegisterPartial(name, p)
}
} | go | func RegisterPartials(partials map[string]string) {
for name, p := range partials {
RegisterPartial(name, p)
}
} | [
"func",
"RegisterPartials",
"(",
"partials",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"for",
"name",
",",
"p",
":=",
"range",
"partials",
"{",
"RegisterPartial",
"(",
"name",
",",
"p",
")",
"\n",
"}",
"\n",
"}"
] | // RegisterPartials registers several global partials. Those partials will be available to all templates. | [
"RegisterPartials",
"registers",
"several",
"global",
"partials",
".",
"Those",
"partials",
"will",
"be",
"available",
"to",
"all",
"templates",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L47-L51 |
545 | aymerick/raymond | partial.go | RegisterPartialTemplate | func RegisterPartialTemplate(name string, tpl *Template) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
if partials[name] != nil {
panic(fmt.Errorf("Partial already registered: %s", name))
}
partials[name] = newPartial(name, "", tpl)
} | go | func RegisterPartialTemplate(name string, tpl *Template) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
if partials[name] != nil {
panic(fmt.Errorf("Partial already registered: %s", name))
}
partials[name] = newPartial(name, "", tpl)
} | [
"func",
"RegisterPartialTemplate",
"(",
"name",
"string",
",",
"tpl",
"*",
"Template",
")",
"{",
"partialsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"partialsMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"partials",
"[",
"name",
"]",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n\n",
"partials",
"[",
"name",
"]",
"=",
"newPartial",
"(",
"name",
",",
"\"",
"\"",
",",
"tpl",
")",
"\n",
"}"
] | // RegisterPartialTemplate registers a global partial with given parsed template. That partial will be available to all templates. | [
"RegisterPartialTemplate",
"registers",
"a",
"global",
"partial",
"with",
"given",
"parsed",
"template",
".",
"That",
"partial",
"will",
"be",
"available",
"to",
"all",
"templates",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L54-L63 |
546 | aymerick/raymond | partial.go | RemovePartial | func RemovePartial(name string) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
delete(partials, name)
} | go | func RemovePartial(name string) {
partialsMutex.Lock()
defer partialsMutex.Unlock()
delete(partials, name)
} | [
"func",
"RemovePartial",
"(",
"name",
"string",
")",
"{",
"partialsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"partialsMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"partials",
",",
"name",
")",
"\n",
"}"
] | // RemovePartial removes the partial registered under the given name. The partial will not be available globally anymore. This does not affect partials registered on a specific template. | [
"RemovePartial",
"removes",
"the",
"partial",
"registered",
"under",
"the",
"given",
"name",
".",
"The",
"partial",
"will",
"not",
"be",
"available",
"globally",
"anymore",
".",
"This",
"does",
"not",
"affect",
"partials",
"registered",
"on",
"a",
"specific",
"template",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L66-L71 |
547 | aymerick/raymond | partial.go | findPartial | func findPartial(name string) *partial {
partialsMutex.RLock()
defer partialsMutex.RUnlock()
return partials[name]
} | go | func findPartial(name string) *partial {
partialsMutex.RLock()
defer partialsMutex.RUnlock()
return partials[name]
} | [
"func",
"findPartial",
"(",
"name",
"string",
")",
"*",
"partial",
"{",
"partialsMutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"partialsMutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"partials",
"[",
"name",
"]",
"\n",
"}"
] | // findPartial finds a registered global partial | [
"findPartial",
"finds",
"a",
"registered",
"global",
"partial"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L82-L87 |
548 | aymerick/raymond | partial.go | template | func (p *partial) template() (*Template, error) {
if p.tpl == nil {
var err error
p.tpl, err = Parse(p.source)
if err != nil {
return nil, err
}
}
return p.tpl, nil
} | go | func (p *partial) template() (*Template, error) {
if p.tpl == nil {
var err error
p.tpl, err = Parse(p.source)
if err != nil {
return nil, err
}
}
return p.tpl, nil
} | [
"func",
"(",
"p",
"*",
"partial",
")",
"template",
"(",
")",
"(",
"*",
"Template",
",",
"error",
")",
"{",
"if",
"p",
".",
"tpl",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n\n",
"p",
".",
"tpl",
",",
"err",
"=",
"Parse",
"(",
"p",
".",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"p",
".",
"tpl",
",",
"nil",
"\n",
"}"
] | // template returns parsed partial template | [
"template",
"returns",
"parsed",
"partial",
"template"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/partial.go#L90-L101 |
549 | aymerick/raymond | eval.go | newEvalVisitor | func newEvalVisitor(tpl *Template, ctx interface{}, privData *DataFrame) *evalVisitor {
frame := privData
if frame == nil {
frame = NewDataFrame()
}
return &evalVisitor{
tpl: tpl,
ctx: []reflect.Value{reflect.ValueOf(ctx)},
dataFrame: frame,
exprFunc: make(map[*ast.Expression]bool),
}
} | go | func newEvalVisitor(tpl *Template, ctx interface{}, privData *DataFrame) *evalVisitor {
frame := privData
if frame == nil {
frame = NewDataFrame()
}
return &evalVisitor{
tpl: tpl,
ctx: []reflect.Value{reflect.ValueOf(ctx)},
dataFrame: frame,
exprFunc: make(map[*ast.Expression]bool),
}
} | [
"func",
"newEvalVisitor",
"(",
"tpl",
"*",
"Template",
",",
"ctx",
"interface",
"{",
"}",
",",
"privData",
"*",
"DataFrame",
")",
"*",
"evalVisitor",
"{",
"frame",
":=",
"privData",
"\n",
"if",
"frame",
"==",
"nil",
"{",
"frame",
"=",
"NewDataFrame",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"evalVisitor",
"{",
"tpl",
":",
"tpl",
",",
"ctx",
":",
"[",
"]",
"reflect",
".",
"Value",
"{",
"reflect",
".",
"ValueOf",
"(",
"ctx",
")",
"}",
",",
"dataFrame",
":",
"frame",
",",
"exprFunc",
":",
"make",
"(",
"map",
"[",
"*",
"ast",
".",
"Expression",
"]",
"bool",
")",
",",
"}",
"\n",
"}"
] | // NewEvalVisitor instanciate a new evaluation visitor with given context and initial private data frame
//
// If privData is nil, then a default data frame is created | [
"NewEvalVisitor",
"instanciate",
"a",
"new",
"evaluation",
"visitor",
"with",
"given",
"context",
"and",
"initial",
"private",
"data",
"frame",
"If",
"privData",
"is",
"nil",
"then",
"a",
"default",
"data",
"frame",
"is",
"created"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L50-L62 |
550 | aymerick/raymond | eval.go | pushCtx | func (v *evalVisitor) pushCtx(ctx reflect.Value) {
v.ctx = append(v.ctx, ctx)
} | go | func (v *evalVisitor) pushCtx(ctx reflect.Value) {
v.ctx = append(v.ctx, ctx)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"pushCtx",
"(",
"ctx",
"reflect",
".",
"Value",
")",
"{",
"v",
".",
"ctx",
"=",
"append",
"(",
"v",
".",
"ctx",
",",
"ctx",
")",
"\n",
"}"
] | //
// Contexts stack
//
// pushCtx pushes new context to the stack | [
"Contexts",
"stack",
"pushCtx",
"pushes",
"new",
"context",
"to",
"the",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L74-L76 |
551 | aymerick/raymond | eval.go | popCtx | func (v *evalVisitor) popCtx() reflect.Value {
if len(v.ctx) == 0 {
return zero
}
var result reflect.Value
result, v.ctx = v.ctx[len(v.ctx)-1], v.ctx[:len(v.ctx)-1]
return result
} | go | func (v *evalVisitor) popCtx() reflect.Value {
if len(v.ctx) == 0 {
return zero
}
var result reflect.Value
result, v.ctx = v.ctx[len(v.ctx)-1], v.ctx[:len(v.ctx)-1]
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"popCtx",
"(",
")",
"reflect",
".",
"Value",
"{",
"if",
"len",
"(",
"v",
".",
"ctx",
")",
"==",
"0",
"{",
"return",
"zero",
"\n",
"}",
"\n\n",
"var",
"result",
"reflect",
".",
"Value",
"\n",
"result",
",",
"v",
".",
"ctx",
"=",
"v",
".",
"ctx",
"[",
"len",
"(",
"v",
".",
"ctx",
")",
"-",
"1",
"]",
",",
"v",
".",
"ctx",
"[",
":",
"len",
"(",
"v",
".",
"ctx",
")",
"-",
"1",
"]",
"\n\n",
"return",
"result",
"\n",
"}"
] | // popCtx pops last context from stack | [
"popCtx",
"pops",
"last",
"context",
"from",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L79-L88 |
552 | aymerick/raymond | eval.go | ancestorCtx | func (v *evalVisitor) ancestorCtx(depth int) reflect.Value {
index := len(v.ctx) - 1 - depth
if index < 0 {
return zero
}
return v.ctx[index]
} | go | func (v *evalVisitor) ancestorCtx(depth int) reflect.Value {
index := len(v.ctx) - 1 - depth
if index < 0 {
return zero
}
return v.ctx[index]
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"ancestorCtx",
"(",
"depth",
"int",
")",
"reflect",
".",
"Value",
"{",
"index",
":=",
"len",
"(",
"v",
".",
"ctx",
")",
"-",
"1",
"-",
"depth",
"\n",
"if",
"index",
"<",
"0",
"{",
"return",
"zero",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"ctx",
"[",
"index",
"]",
"\n",
"}"
] | // ancestorCtx returns ancestor context | [
"ancestorCtx",
"returns",
"ancestor",
"context"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L101-L108 |
553 | aymerick/raymond | eval.go | pushBlockParams | func (v *evalVisitor) pushBlockParams(params map[string]interface{}) {
v.blockParams = append(v.blockParams, params)
} | go | func (v *evalVisitor) pushBlockParams(params map[string]interface{}) {
v.blockParams = append(v.blockParams, params)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"pushBlockParams",
"(",
"params",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"v",
".",
"blockParams",
"=",
"append",
"(",
"v",
".",
"blockParams",
",",
"params",
")",
"\n",
"}"
] | //
// Block Parameters stack
//
// pushBlockParams pushes new block params to the stack | [
"Block",
"Parameters",
"stack",
"pushBlockParams",
"pushes",
"new",
"block",
"params",
"to",
"the",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L129-L131 |
554 | aymerick/raymond | eval.go | popBlockParams | func (v *evalVisitor) popBlockParams() map[string]interface{} {
var result map[string]interface{}
if len(v.blockParams) == 0 {
return result
}
result, v.blockParams = v.blockParams[len(v.blockParams)-1], v.blockParams[:len(v.blockParams)-1]
return result
} | go | func (v *evalVisitor) popBlockParams() map[string]interface{} {
var result map[string]interface{}
if len(v.blockParams) == 0 {
return result
}
result, v.blockParams = v.blockParams[len(v.blockParams)-1], v.blockParams[:len(v.blockParams)-1]
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"popBlockParams",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"var",
"result",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n\n",
"if",
"len",
"(",
"v",
".",
"blockParams",
")",
"==",
"0",
"{",
"return",
"result",
"\n",
"}",
"\n\n",
"result",
",",
"v",
".",
"blockParams",
"=",
"v",
".",
"blockParams",
"[",
"len",
"(",
"v",
".",
"blockParams",
")",
"-",
"1",
"]",
",",
"v",
".",
"blockParams",
"[",
":",
"len",
"(",
"v",
".",
"blockParams",
")",
"-",
"1",
"]",
"\n",
"return",
"result",
"\n",
"}"
] | // popBlockParams pops last block params from stack | [
"popBlockParams",
"pops",
"last",
"block",
"params",
"from",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L134-L143 |
555 | aymerick/raymond | eval.go | blockParam | func (v *evalVisitor) blockParam(name string) interface{} {
for i := len(v.blockParams) - 1; i >= 0; i-- {
for k, v := range v.blockParams[i] {
if name == k {
return v
}
}
}
return nil
} | go | func (v *evalVisitor) blockParam(name string) interface{} {
for i := len(v.blockParams) - 1; i >= 0; i-- {
for k, v := range v.blockParams[i] {
if name == k {
return v
}
}
}
return nil
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"blockParam",
"(",
"name",
"string",
")",
"interface",
"{",
"}",
"{",
"for",
"i",
":=",
"len",
"(",
"v",
".",
"blockParams",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"v",
".",
"blockParams",
"[",
"i",
"]",
"{",
"if",
"name",
"==",
"k",
"{",
"return",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // blockParam iterates on stack to find given block parameter, and returns its value or nil if not founc | [
"blockParam",
"iterates",
"on",
"stack",
"to",
"find",
"given",
"block",
"parameter",
"and",
"returns",
"its",
"value",
"or",
"nil",
"if",
"not",
"founc"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L146-L156 |
556 | aymerick/raymond | eval.go | pushBlock | func (v *evalVisitor) pushBlock(block *ast.BlockStatement) {
v.blocks = append(v.blocks, block)
} | go | func (v *evalVisitor) pushBlock(block *ast.BlockStatement) {
v.blocks = append(v.blocks, block)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"pushBlock",
"(",
"block",
"*",
"ast",
".",
"BlockStatement",
")",
"{",
"v",
".",
"blocks",
"=",
"append",
"(",
"v",
".",
"blocks",
",",
"block",
")",
"\n",
"}"
] | //
// Blocks stack
//
// pushBlock pushes new block statement to stack | [
"Blocks",
"stack",
"pushBlock",
"pushes",
"new",
"block",
"statement",
"to",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L163-L165 |
557 | aymerick/raymond | eval.go | popBlock | func (v *evalVisitor) popBlock() *ast.BlockStatement {
if len(v.blocks) == 0 {
return nil
}
var result *ast.BlockStatement
result, v.blocks = v.blocks[len(v.blocks)-1], v.blocks[:len(v.blocks)-1]
return result
} | go | func (v *evalVisitor) popBlock() *ast.BlockStatement {
if len(v.blocks) == 0 {
return nil
}
var result *ast.BlockStatement
result, v.blocks = v.blocks[len(v.blocks)-1], v.blocks[:len(v.blocks)-1]
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"popBlock",
"(",
")",
"*",
"ast",
".",
"BlockStatement",
"{",
"if",
"len",
"(",
"v",
".",
"blocks",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"result",
"*",
"ast",
".",
"BlockStatement",
"\n",
"result",
",",
"v",
".",
"blocks",
"=",
"v",
".",
"blocks",
"[",
"len",
"(",
"v",
".",
"blocks",
")",
"-",
"1",
"]",
",",
"v",
".",
"blocks",
"[",
":",
"len",
"(",
"v",
".",
"blocks",
")",
"-",
"1",
"]",
"\n\n",
"return",
"result",
"\n",
"}"
] | // popBlock pops last block statement from stack | [
"popBlock",
"pops",
"last",
"block",
"statement",
"from",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L168-L177 |
558 | aymerick/raymond | eval.go | curBlock | func (v *evalVisitor) curBlock() *ast.BlockStatement {
if len(v.blocks) == 0 {
return nil
}
return v.blocks[len(v.blocks)-1]
} | go | func (v *evalVisitor) curBlock() *ast.BlockStatement {
if len(v.blocks) == 0 {
return nil
}
return v.blocks[len(v.blocks)-1]
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"curBlock",
"(",
")",
"*",
"ast",
".",
"BlockStatement",
"{",
"if",
"len",
"(",
"v",
".",
"blocks",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"blocks",
"[",
"len",
"(",
"v",
".",
"blocks",
")",
"-",
"1",
"]",
"\n",
"}"
] | // curBlock returns current block statement | [
"curBlock",
"returns",
"current",
"block",
"statement"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L180-L186 |
559 | aymerick/raymond | eval.go | pushExpr | func (v *evalVisitor) pushExpr(expression *ast.Expression) {
v.exprs = append(v.exprs, expression)
} | go | func (v *evalVisitor) pushExpr(expression *ast.Expression) {
v.exprs = append(v.exprs, expression)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"pushExpr",
"(",
"expression",
"*",
"ast",
".",
"Expression",
")",
"{",
"v",
".",
"exprs",
"=",
"append",
"(",
"v",
".",
"exprs",
",",
"expression",
")",
"\n",
"}"
] | //
// Expressions stack
//
// pushExpr pushes new expression to stack | [
"Expressions",
"stack",
"pushExpr",
"pushes",
"new",
"expression",
"to",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L193-L195 |
560 | aymerick/raymond | eval.go | popExpr | func (v *evalVisitor) popExpr() *ast.Expression {
if len(v.exprs) == 0 {
return nil
}
var result *ast.Expression
result, v.exprs = v.exprs[len(v.exprs)-1], v.exprs[:len(v.exprs)-1]
return result
} | go | func (v *evalVisitor) popExpr() *ast.Expression {
if len(v.exprs) == 0 {
return nil
}
var result *ast.Expression
result, v.exprs = v.exprs[len(v.exprs)-1], v.exprs[:len(v.exprs)-1]
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"popExpr",
"(",
")",
"*",
"ast",
".",
"Expression",
"{",
"if",
"len",
"(",
"v",
".",
"exprs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"result",
"*",
"ast",
".",
"Expression",
"\n",
"result",
",",
"v",
".",
"exprs",
"=",
"v",
".",
"exprs",
"[",
"len",
"(",
"v",
".",
"exprs",
")",
"-",
"1",
"]",
",",
"v",
".",
"exprs",
"[",
":",
"len",
"(",
"v",
".",
"exprs",
")",
"-",
"1",
"]",
"\n\n",
"return",
"result",
"\n",
"}"
] | // popExpr pops last expression from stack | [
"popExpr",
"pops",
"last",
"expression",
"from",
"stack"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L198-L207 |
561 | aymerick/raymond | eval.go | curExpr | func (v *evalVisitor) curExpr() *ast.Expression {
if len(v.exprs) == 0 {
return nil
}
return v.exprs[len(v.exprs)-1]
} | go | func (v *evalVisitor) curExpr() *ast.Expression {
if len(v.exprs) == 0 {
return nil
}
return v.exprs[len(v.exprs)-1]
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"curExpr",
"(",
")",
"*",
"ast",
".",
"Expression",
"{",
"if",
"len",
"(",
"v",
".",
"exprs",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"exprs",
"[",
"len",
"(",
"v",
".",
"exprs",
")",
"-",
"1",
"]",
"\n",
"}"
] | // curExpr returns current expression | [
"curExpr",
"returns",
"current",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L210-L216 |
562 | aymerick/raymond | eval.go | errPanic | func (v *evalVisitor) errPanic(err error) {
panic(fmt.Errorf("Evaluation error: %s\nCurrent node:\n\t%s", err, v.curNode))
} | go | func (v *evalVisitor) errPanic(err error) {
panic(fmt.Errorf("Evaluation error: %s\nCurrent node:\n\t%s", err, v.curNode))
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"errPanic",
"(",
"err",
"error",
")",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\t",
"\"",
",",
"err",
",",
"v",
".",
"curNode",
")",
")",
"\n",
"}"
] | //
// Error functions
//
// errPanic panics | [
"Error",
"functions",
"errPanic",
"panics"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L223-L225 |
563 | aymerick/raymond | eval.go | errorf | func (v *evalVisitor) errorf(format string, args ...interface{}) {
v.errPanic(fmt.Errorf(format, args...))
} | go | func (v *evalVisitor) errorf(format string, args ...interface{}) {
v.errPanic(fmt.Errorf(format, args...))
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"errorf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"v",
".",
"errPanic",
"(",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"args",
"...",
")",
")",
"\n",
"}"
] | // errorf panics with a custom message | [
"errorf",
"panics",
"with",
"a",
"custom",
"message"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L228-L230 |
564 | aymerick/raymond | eval.go | evalProgram | func (v *evalVisitor) evalProgram(program *ast.Program, ctx interface{}, data *DataFrame, key interface{}) string {
blockParams := make(map[string]interface{})
// compute block params
if len(program.BlockParams) > 0 {
blockParams[program.BlockParams[0]] = ctx
}
if (len(program.BlockParams) > 1) && (key != nil) {
blockParams[program.BlockParams[1]] = key
}
// push contexts
if len(blockParams) > 0 {
v.pushBlockParams(blockParams)
}
ctxVal := reflect.ValueOf(ctx)
if ctxVal.IsValid() {
v.pushCtx(ctxVal)
}
if data != nil {
v.setDataFrame(data)
}
// evaluate program
result, _ := program.Accept(v).(string)
// pop contexts
if data != nil {
v.popDataFrame()
}
if ctxVal.IsValid() {
v.popCtx()
}
if len(blockParams) > 0 {
v.popBlockParams()
}
return result
} | go | func (v *evalVisitor) evalProgram(program *ast.Program, ctx interface{}, data *DataFrame, key interface{}) string {
blockParams := make(map[string]interface{})
// compute block params
if len(program.BlockParams) > 0 {
blockParams[program.BlockParams[0]] = ctx
}
if (len(program.BlockParams) > 1) && (key != nil) {
blockParams[program.BlockParams[1]] = key
}
// push contexts
if len(blockParams) > 0 {
v.pushBlockParams(blockParams)
}
ctxVal := reflect.ValueOf(ctx)
if ctxVal.IsValid() {
v.pushCtx(ctxVal)
}
if data != nil {
v.setDataFrame(data)
}
// evaluate program
result, _ := program.Accept(v).(string)
// pop contexts
if data != nil {
v.popDataFrame()
}
if ctxVal.IsValid() {
v.popCtx()
}
if len(blockParams) > 0 {
v.popBlockParams()
}
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalProgram",
"(",
"program",
"*",
"ast",
".",
"Program",
",",
"ctx",
"interface",
"{",
"}",
",",
"data",
"*",
"DataFrame",
",",
"key",
"interface",
"{",
"}",
")",
"string",
"{",
"blockParams",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"// compute block params",
"if",
"len",
"(",
"program",
".",
"BlockParams",
")",
">",
"0",
"{",
"blockParams",
"[",
"program",
".",
"BlockParams",
"[",
"0",
"]",
"]",
"=",
"ctx",
"\n",
"}",
"\n\n",
"if",
"(",
"len",
"(",
"program",
".",
"BlockParams",
")",
">",
"1",
")",
"&&",
"(",
"key",
"!=",
"nil",
")",
"{",
"blockParams",
"[",
"program",
".",
"BlockParams",
"[",
"1",
"]",
"]",
"=",
"key",
"\n",
"}",
"\n\n",
"// push contexts",
"if",
"len",
"(",
"blockParams",
")",
">",
"0",
"{",
"v",
".",
"pushBlockParams",
"(",
"blockParams",
")",
"\n",
"}",
"\n\n",
"ctxVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"ctx",
")",
"\n",
"if",
"ctxVal",
".",
"IsValid",
"(",
")",
"{",
"v",
".",
"pushCtx",
"(",
"ctxVal",
")",
"\n",
"}",
"\n\n",
"if",
"data",
"!=",
"nil",
"{",
"v",
".",
"setDataFrame",
"(",
"data",
")",
"\n",
"}",
"\n\n",
"// evaluate program",
"result",
",",
"_",
":=",
"program",
".",
"Accept",
"(",
"v",
")",
".",
"(",
"string",
")",
"\n\n",
"// pop contexts",
"if",
"data",
"!=",
"nil",
"{",
"v",
".",
"popDataFrame",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"ctxVal",
".",
"IsValid",
"(",
")",
"{",
"v",
".",
"popCtx",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"blockParams",
")",
">",
"0",
"{",
"v",
".",
"popBlockParams",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | //
// Evaluation
//
// evalProgram eEvaluates program with given context and returns string result | [
"Evaluation",
"evalProgram",
"eEvaluates",
"program",
"with",
"given",
"context",
"and",
"returns",
"string",
"result"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L237-L280 |
565 | aymerick/raymond | eval.go | evalPath | func (v *evalVisitor) evalPath(ctx reflect.Value, parts []string, exprRoot bool) (reflect.Value, bool) {
partResolved := false
for i := 0; i < len(parts); i++ {
part := parts[i]
// "[foo bar]"" => "foo bar"
if (len(part) >= 2) && (part[0] == '[') && (part[len(part)-1] == ']') {
part = part[1 : len(part)-1]
}
ctx = v.evalField(ctx, part, exprRoot)
if !ctx.IsValid() {
break
}
// we resolved at least one part of path
partResolved = true
}
return ctx, partResolved
} | go | func (v *evalVisitor) evalPath(ctx reflect.Value, parts []string, exprRoot bool) (reflect.Value, bool) {
partResolved := false
for i := 0; i < len(parts); i++ {
part := parts[i]
// "[foo bar]"" => "foo bar"
if (len(part) >= 2) && (part[0] == '[') && (part[len(part)-1] == ']') {
part = part[1 : len(part)-1]
}
ctx = v.evalField(ctx, part, exprRoot)
if !ctx.IsValid() {
break
}
// we resolved at least one part of path
partResolved = true
}
return ctx, partResolved
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalPath",
"(",
"ctx",
"reflect",
".",
"Value",
",",
"parts",
"[",
"]",
"string",
",",
"exprRoot",
"bool",
")",
"(",
"reflect",
".",
"Value",
",",
"bool",
")",
"{",
"partResolved",
":=",
"false",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"parts",
")",
";",
"i",
"++",
"{",
"part",
":=",
"parts",
"[",
"i",
"]",
"\n\n",
"// \"[foo bar]\"\" => \"foo bar\"",
"if",
"(",
"len",
"(",
"part",
")",
">=",
"2",
")",
"&&",
"(",
"part",
"[",
"0",
"]",
"==",
"'['",
")",
"&&",
"(",
"part",
"[",
"len",
"(",
"part",
")",
"-",
"1",
"]",
"==",
"']'",
")",
"{",
"part",
"=",
"part",
"[",
"1",
":",
"len",
"(",
"part",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"ctx",
"=",
"v",
".",
"evalField",
"(",
"ctx",
",",
"part",
",",
"exprRoot",
")",
"\n",
"if",
"!",
"ctx",
".",
"IsValid",
"(",
")",
"{",
"break",
"\n",
"}",
"\n\n",
"// we resolved at least one part of path",
"partResolved",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"ctx",
",",
"partResolved",
"\n",
"}"
] | // evalPath evaluates all path parts with given context | [
"evalPath",
"evaluates",
"all",
"path",
"parts",
"with",
"given",
"context"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L283-L304 |
566 | aymerick/raymond | eval.go | evalField | func (v *evalVisitor) evalField(ctx reflect.Value, fieldName string, exprRoot bool) reflect.Value {
result := zero
ctx, _ = indirect(ctx)
if !ctx.IsValid() {
return result
}
// check if this is a method call
result, isMeth := v.evalMethod(ctx, fieldName, exprRoot)
if !isMeth {
switch ctx.Kind() {
case reflect.Struct:
// example: firstName => FirstName
expFieldName := strings.Title(fieldName)
// check if struct have this field and that it is exported
if tField, ok := ctx.Type().FieldByName(expFieldName); ok && (tField.PkgPath == "") {
// struct field
result = ctx.FieldByIndex(tField.Index)
break
}
// attempts to find template variable name as a struct tag
result = v.evalStructTag(ctx, fieldName)
case reflect.Map:
nameVal := reflect.ValueOf(fieldName)
if nameVal.Type().AssignableTo(ctx.Type().Key()) {
// map key
result = ctx.MapIndex(nameVal)
}
case reflect.Array, reflect.Slice:
if i, err := strconv.Atoi(fieldName); (err == nil) && (i < ctx.Len()) {
result = ctx.Index(i)
}
}
}
// check if result is a function
result, _ = indirect(result)
if result.Kind() == reflect.Func {
result = v.evalFieldFunc(fieldName, result, exprRoot)
}
return result
} | go | func (v *evalVisitor) evalField(ctx reflect.Value, fieldName string, exprRoot bool) reflect.Value {
result := zero
ctx, _ = indirect(ctx)
if !ctx.IsValid() {
return result
}
// check if this is a method call
result, isMeth := v.evalMethod(ctx, fieldName, exprRoot)
if !isMeth {
switch ctx.Kind() {
case reflect.Struct:
// example: firstName => FirstName
expFieldName := strings.Title(fieldName)
// check if struct have this field and that it is exported
if tField, ok := ctx.Type().FieldByName(expFieldName); ok && (tField.PkgPath == "") {
// struct field
result = ctx.FieldByIndex(tField.Index)
break
}
// attempts to find template variable name as a struct tag
result = v.evalStructTag(ctx, fieldName)
case reflect.Map:
nameVal := reflect.ValueOf(fieldName)
if nameVal.Type().AssignableTo(ctx.Type().Key()) {
// map key
result = ctx.MapIndex(nameVal)
}
case reflect.Array, reflect.Slice:
if i, err := strconv.Atoi(fieldName); (err == nil) && (i < ctx.Len()) {
result = ctx.Index(i)
}
}
}
// check if result is a function
result, _ = indirect(result)
if result.Kind() == reflect.Func {
result = v.evalFieldFunc(fieldName, result, exprRoot)
}
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalField",
"(",
"ctx",
"reflect",
".",
"Value",
",",
"fieldName",
"string",
",",
"exprRoot",
"bool",
")",
"reflect",
".",
"Value",
"{",
"result",
":=",
"zero",
"\n\n",
"ctx",
",",
"_",
"=",
"indirect",
"(",
"ctx",
")",
"\n",
"if",
"!",
"ctx",
".",
"IsValid",
"(",
")",
"{",
"return",
"result",
"\n",
"}",
"\n\n",
"// check if this is a method call",
"result",
",",
"isMeth",
":=",
"v",
".",
"evalMethod",
"(",
"ctx",
",",
"fieldName",
",",
"exprRoot",
")",
"\n",
"if",
"!",
"isMeth",
"{",
"switch",
"ctx",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Struct",
":",
"// example: firstName => FirstName",
"expFieldName",
":=",
"strings",
".",
"Title",
"(",
"fieldName",
")",
"\n\n",
"// check if struct have this field and that it is exported",
"if",
"tField",
",",
"ok",
":=",
"ctx",
".",
"Type",
"(",
")",
".",
"FieldByName",
"(",
"expFieldName",
")",
";",
"ok",
"&&",
"(",
"tField",
".",
"PkgPath",
"==",
"\"",
"\"",
")",
"{",
"// struct field",
"result",
"=",
"ctx",
".",
"FieldByIndex",
"(",
"tField",
".",
"Index",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"// attempts to find template variable name as a struct tag",
"result",
"=",
"v",
".",
"evalStructTag",
"(",
"ctx",
",",
"fieldName",
")",
"\n",
"case",
"reflect",
".",
"Map",
":",
"nameVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"fieldName",
")",
"\n",
"if",
"nameVal",
".",
"Type",
"(",
")",
".",
"AssignableTo",
"(",
"ctx",
".",
"Type",
"(",
")",
".",
"Key",
"(",
")",
")",
"{",
"// map key",
"result",
"=",
"ctx",
".",
"MapIndex",
"(",
"nameVal",
")",
"\n",
"}",
"\n",
"case",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Slice",
":",
"if",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"fieldName",
")",
";",
"(",
"err",
"==",
"nil",
")",
"&&",
"(",
"i",
"<",
"ctx",
".",
"Len",
"(",
")",
")",
"{",
"result",
"=",
"ctx",
".",
"Index",
"(",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// check if result is a function",
"result",
",",
"_",
"=",
"indirect",
"(",
"result",
")",
"\n",
"if",
"result",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Func",
"{",
"result",
"=",
"v",
".",
"evalFieldFunc",
"(",
"fieldName",
",",
"result",
",",
"exprRoot",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // evalField evaluates field with given context | [
"evalField",
"evaluates",
"field",
"with",
"given",
"context"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L307-L352 |
567 | aymerick/raymond | eval.go | evalMethod | func (v *evalVisitor) evalMethod(ctx reflect.Value, name string, exprRoot bool) (reflect.Value, bool) {
if ctx.Kind() != reflect.Interface && ctx.CanAddr() {
ctx = ctx.Addr()
}
method := ctx.MethodByName(name)
if !method.IsValid() {
// example: subject() => Subject()
method = ctx.MethodByName(strings.Title(name))
}
if !method.IsValid() {
return zero, false
}
return v.evalFieldFunc(name, method, exprRoot), true
} | go | func (v *evalVisitor) evalMethod(ctx reflect.Value, name string, exprRoot bool) (reflect.Value, bool) {
if ctx.Kind() != reflect.Interface && ctx.CanAddr() {
ctx = ctx.Addr()
}
method := ctx.MethodByName(name)
if !method.IsValid() {
// example: subject() => Subject()
method = ctx.MethodByName(strings.Title(name))
}
if !method.IsValid() {
return zero, false
}
return v.evalFieldFunc(name, method, exprRoot), true
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalMethod",
"(",
"ctx",
"reflect",
".",
"Value",
",",
"name",
"string",
",",
"exprRoot",
"bool",
")",
"(",
"reflect",
".",
"Value",
",",
"bool",
")",
"{",
"if",
"ctx",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Interface",
"&&",
"ctx",
".",
"CanAddr",
"(",
")",
"{",
"ctx",
"=",
"ctx",
".",
"Addr",
"(",
")",
"\n",
"}",
"\n\n",
"method",
":=",
"ctx",
".",
"MethodByName",
"(",
"name",
")",
"\n",
"if",
"!",
"method",
".",
"IsValid",
"(",
")",
"{",
"// example: subject() => Subject()",
"method",
"=",
"ctx",
".",
"MethodByName",
"(",
"strings",
".",
"Title",
"(",
"name",
")",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"method",
".",
"IsValid",
"(",
")",
"{",
"return",
"zero",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"evalFieldFunc",
"(",
"name",
",",
"method",
",",
"exprRoot",
")",
",",
"true",
"\n",
"}"
] | // evalFieldFunc tries to evaluate given method name, and a boolean to indicate if this was a method call | [
"evalFieldFunc",
"tries",
"to",
"evaluate",
"given",
"method",
"name",
"and",
"a",
"boolean",
"to",
"indicate",
"if",
"this",
"was",
"a",
"method",
"call"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L355-L371 |
568 | aymerick/raymond | eval.go | evalFieldFunc | func (v *evalVisitor) evalFieldFunc(name string, funcVal reflect.Value, exprRoot bool) reflect.Value {
ensureValidHelper(name, funcVal)
var options *Options
if exprRoot {
// create function arg with all params/hash
expr := v.curExpr()
options = v.helperOptions(expr)
// ok, that expression was a function call
v.exprFunc[expr] = true
} else {
// we are not at root of expression, so we are a parameter... and we don't like
// infinite loops caused by trying to parse ourself forever
options = newEmptyOptions(v)
}
return v.callFunc(name, funcVal, options)
} | go | func (v *evalVisitor) evalFieldFunc(name string, funcVal reflect.Value, exprRoot bool) reflect.Value {
ensureValidHelper(name, funcVal)
var options *Options
if exprRoot {
// create function arg with all params/hash
expr := v.curExpr()
options = v.helperOptions(expr)
// ok, that expression was a function call
v.exprFunc[expr] = true
} else {
// we are not at root of expression, so we are a parameter... and we don't like
// infinite loops caused by trying to parse ourself forever
options = newEmptyOptions(v)
}
return v.callFunc(name, funcVal, options)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalFieldFunc",
"(",
"name",
"string",
",",
"funcVal",
"reflect",
".",
"Value",
",",
"exprRoot",
"bool",
")",
"reflect",
".",
"Value",
"{",
"ensureValidHelper",
"(",
"name",
",",
"funcVal",
")",
"\n\n",
"var",
"options",
"*",
"Options",
"\n",
"if",
"exprRoot",
"{",
"// create function arg with all params/hash",
"expr",
":=",
"v",
".",
"curExpr",
"(",
")",
"\n",
"options",
"=",
"v",
".",
"helperOptions",
"(",
"expr",
")",
"\n\n",
"// ok, that expression was a function call",
"v",
".",
"exprFunc",
"[",
"expr",
"]",
"=",
"true",
"\n",
"}",
"else",
"{",
"// we are not at root of expression, so we are a parameter... and we don't like",
"// infinite loops caused by trying to parse ourself forever",
"options",
"=",
"newEmptyOptions",
"(",
"v",
")",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"callFunc",
"(",
"name",
",",
"funcVal",
",",
"options",
")",
"\n",
"}"
] | // evalFieldFunc evaluates given function | [
"evalFieldFunc",
"evaluates",
"given",
"function"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L374-L392 |
569 | aymerick/raymond | eval.go | evalStructTag | func (v *evalVisitor) evalStructTag(ctx reflect.Value, name string) reflect.Value {
val := reflect.ValueOf(ctx.Interface())
for i := 0; i < val.NumField(); i++ {
field := val.Type().Field(i)
tag := field.Tag.Get("handlebars")
if tag == name {
return val.Field(i)
}
}
return zero
} | go | func (v *evalVisitor) evalStructTag(ctx reflect.Value, name string) reflect.Value {
val := reflect.ValueOf(ctx.Interface())
for i := 0; i < val.NumField(); i++ {
field := val.Type().Field(i)
tag := field.Tag.Get("handlebars")
if tag == name {
return val.Field(i)
}
}
return zero
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalStructTag",
"(",
"ctx",
"reflect",
".",
"Value",
",",
"name",
"string",
")",
"reflect",
".",
"Value",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"ctx",
".",
"Interface",
"(",
")",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"val",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"field",
":=",
"val",
".",
"Type",
"(",
")",
".",
"Field",
"(",
"i",
")",
"\n",
"tag",
":=",
"field",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"tag",
"==",
"name",
"{",
"return",
"val",
".",
"Field",
"(",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"zero",
"\n",
"}"
] | // evalStructTag checks for the existence of a struct tag containing the
// name of the variable in the template. This allows for a template variable to
// be separated from the field in the struct. | [
"evalStructTag",
"checks",
"for",
"the",
"existence",
"of",
"a",
"struct",
"tag",
"containing",
"the",
"name",
"of",
"the",
"variable",
"in",
"the",
"template",
".",
"This",
"allows",
"for",
"a",
"template",
"variable",
"to",
"be",
"separated",
"from",
"the",
"field",
"in",
"the",
"struct",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L397-L409 |
570 | aymerick/raymond | eval.go | findBlockParam | func (v *evalVisitor) findBlockParam(node *ast.PathExpression) (string, interface{}) {
if len(node.Parts) > 0 {
name := node.Parts[0]
if value := v.blockParam(name); value != nil {
return name, value
}
}
return "", nil
} | go | func (v *evalVisitor) findBlockParam(node *ast.PathExpression) (string, interface{}) {
if len(node.Parts) > 0 {
name := node.Parts[0]
if value := v.blockParam(name); value != nil {
return name, value
}
}
return "", nil
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"findBlockParam",
"(",
"node",
"*",
"ast",
".",
"PathExpression",
")",
"(",
"string",
",",
"interface",
"{",
"}",
")",
"{",
"if",
"len",
"(",
"node",
".",
"Parts",
")",
">",
"0",
"{",
"name",
":=",
"node",
".",
"Parts",
"[",
"0",
"]",
"\n",
"if",
"value",
":=",
"v",
".",
"blockParam",
"(",
"name",
")",
";",
"value",
"!=",
"nil",
"{",
"return",
"name",
",",
"value",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] | // findBlockParam returns node's block parameter | [
"findBlockParam",
"returns",
"node",
"s",
"block",
"parameter"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L412-L421 |
571 | aymerick/raymond | eval.go | evalPathExpression | func (v *evalVisitor) evalPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
var result interface{}
if name, value := v.findBlockParam(node); value != nil {
// block parameter value
// We push a new context so we can evaluate the path expression (note: this may be a bad idea).
//
// Example:
// {{#foo as |bar|}}
// {{bar.baz}}
// {{/foo}}
//
// With data:
// {"foo": {"baz": "bat"}}
newCtx := map[string]interface{}{name: value}
v.pushCtx(reflect.ValueOf(newCtx))
result = v.evalCtxPathExpression(node, exprRoot)
v.popCtx()
} else {
ctxTried := false
if node.IsDataRoot() {
// context path
result = v.evalCtxPathExpression(node, exprRoot)
ctxTried = true
}
if (result == nil) && node.Data {
// if it is @root, then we tried to evaluate with root context but nothing was found
// so let's try with private data
// private data
result = v.evalDataPathExpression(node, exprRoot)
}
if (result == nil) && !ctxTried {
// context path
result = v.evalCtxPathExpression(node, exprRoot)
}
}
return result
} | go | func (v *evalVisitor) evalPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
var result interface{}
if name, value := v.findBlockParam(node); value != nil {
// block parameter value
// We push a new context so we can evaluate the path expression (note: this may be a bad idea).
//
// Example:
// {{#foo as |bar|}}
// {{bar.baz}}
// {{/foo}}
//
// With data:
// {"foo": {"baz": "bat"}}
newCtx := map[string]interface{}{name: value}
v.pushCtx(reflect.ValueOf(newCtx))
result = v.evalCtxPathExpression(node, exprRoot)
v.popCtx()
} else {
ctxTried := false
if node.IsDataRoot() {
// context path
result = v.evalCtxPathExpression(node, exprRoot)
ctxTried = true
}
if (result == nil) && node.Data {
// if it is @root, then we tried to evaluate with root context but nothing was found
// so let's try with private data
// private data
result = v.evalDataPathExpression(node, exprRoot)
}
if (result == nil) && !ctxTried {
// context path
result = v.evalCtxPathExpression(node, exprRoot)
}
}
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalPathExpression",
"(",
"node",
"*",
"ast",
".",
"PathExpression",
",",
"exprRoot",
"bool",
")",
"interface",
"{",
"}",
"{",
"var",
"result",
"interface",
"{",
"}",
"\n\n",
"if",
"name",
",",
"value",
":=",
"v",
".",
"findBlockParam",
"(",
"node",
")",
";",
"value",
"!=",
"nil",
"{",
"// block parameter value",
"// We push a new context so we can evaluate the path expression (note: this may be a bad idea).",
"//",
"// Example:",
"// {{#foo as |bar|}}",
"// {{bar.baz}}",
"// {{/foo}}",
"//",
"// With data:",
"// {\"foo\": {\"baz\": \"bat\"}}",
"newCtx",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"name",
":",
"value",
"}",
"\n\n",
"v",
".",
"pushCtx",
"(",
"reflect",
".",
"ValueOf",
"(",
"newCtx",
")",
")",
"\n",
"result",
"=",
"v",
".",
"evalCtxPathExpression",
"(",
"node",
",",
"exprRoot",
")",
"\n",
"v",
".",
"popCtx",
"(",
")",
"\n",
"}",
"else",
"{",
"ctxTried",
":=",
"false",
"\n\n",
"if",
"node",
".",
"IsDataRoot",
"(",
")",
"{",
"// context path",
"result",
"=",
"v",
".",
"evalCtxPathExpression",
"(",
"node",
",",
"exprRoot",
")",
"\n\n",
"ctxTried",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"(",
"result",
"==",
"nil",
")",
"&&",
"node",
".",
"Data",
"{",
"// if it is @root, then we tried to evaluate with root context but nothing was found",
"// so let's try with private data",
"// private data",
"result",
"=",
"v",
".",
"evalDataPathExpression",
"(",
"node",
",",
"exprRoot",
")",
"\n",
"}",
"\n\n",
"if",
"(",
"result",
"==",
"nil",
")",
"&&",
"!",
"ctxTried",
"{",
"// context path",
"result",
"=",
"v",
".",
"evalCtxPathExpression",
"(",
"node",
",",
"exprRoot",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // evalPathExpression evaluates a path expression | [
"evalPathExpression",
"evaluates",
"a",
"path",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L424-L469 |
572 | aymerick/raymond | eval.go | evalDataPathExpression | func (v *evalVisitor) evalDataPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
// find data frame
frame := v.dataFrame
for i := node.Depth; i > 0; i-- {
if frame.parent == nil {
return nil
}
frame = frame.parent
}
// resolve data
// @note Can be changed to v.evalCtx() as context can't be an array
result, _ := v.evalCtxPath(reflect.ValueOf(frame.data), node.Parts, exprRoot)
return result
} | go | func (v *evalVisitor) evalDataPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
// find data frame
frame := v.dataFrame
for i := node.Depth; i > 0; i-- {
if frame.parent == nil {
return nil
}
frame = frame.parent
}
// resolve data
// @note Can be changed to v.evalCtx() as context can't be an array
result, _ := v.evalCtxPath(reflect.ValueOf(frame.data), node.Parts, exprRoot)
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalDataPathExpression",
"(",
"node",
"*",
"ast",
".",
"PathExpression",
",",
"exprRoot",
"bool",
")",
"interface",
"{",
"}",
"{",
"// find data frame",
"frame",
":=",
"v",
".",
"dataFrame",
"\n",
"for",
"i",
":=",
"node",
".",
"Depth",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"if",
"frame",
".",
"parent",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"frame",
"=",
"frame",
".",
"parent",
"\n",
"}",
"\n\n",
"// resolve data",
"// @note Can be changed to v.evalCtx() as context can't be an array",
"result",
",",
"_",
":=",
"v",
".",
"evalCtxPath",
"(",
"reflect",
".",
"ValueOf",
"(",
"frame",
".",
"data",
")",
",",
"node",
".",
"Parts",
",",
"exprRoot",
")",
"\n",
"return",
"result",
"\n",
"}"
] | // evalDataPathExpression evaluates a private data path expression | [
"evalDataPathExpression",
"evaluates",
"a",
"private",
"data",
"path",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L472-L486 |
573 | aymerick/raymond | eval.go | evalCtxPathExpression | func (v *evalVisitor) evalCtxPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
v.at(node)
if node.IsDataRoot() {
// `@root` - remove the first part
parts := node.Parts[1:len(node.Parts)]
result, _ := v.evalCtxPath(v.rootCtx(), parts, exprRoot)
return result
}
return v.evalDepthPath(node.Depth, node.Parts, exprRoot)
} | go | func (v *evalVisitor) evalCtxPathExpression(node *ast.PathExpression, exprRoot bool) interface{} {
v.at(node)
if node.IsDataRoot() {
// `@root` - remove the first part
parts := node.Parts[1:len(node.Parts)]
result, _ := v.evalCtxPath(v.rootCtx(), parts, exprRoot)
return result
}
return v.evalDepthPath(node.Depth, node.Parts, exprRoot)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalCtxPathExpression",
"(",
"node",
"*",
"ast",
".",
"PathExpression",
",",
"exprRoot",
"bool",
")",
"interface",
"{",
"}",
"{",
"v",
".",
"at",
"(",
"node",
")",
"\n\n",
"if",
"node",
".",
"IsDataRoot",
"(",
")",
"{",
"// `@root` - remove the first part",
"parts",
":=",
"node",
".",
"Parts",
"[",
"1",
":",
"len",
"(",
"node",
".",
"Parts",
")",
"]",
"\n\n",
"result",
",",
"_",
":=",
"v",
".",
"evalCtxPath",
"(",
"v",
".",
"rootCtx",
"(",
")",
",",
"parts",
",",
"exprRoot",
")",
"\n",
"return",
"result",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"evalDepthPath",
"(",
"node",
".",
"Depth",
",",
"node",
".",
"Parts",
",",
"exprRoot",
")",
"\n",
"}"
] | // evalCtxPathExpression evaluates a context path expression | [
"evalCtxPathExpression",
"evaluates",
"a",
"context",
"path",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L489-L501 |
574 | aymerick/raymond | eval.go | evalDepthPath | func (v *evalVisitor) evalDepthPath(depth int, parts []string, exprRoot bool) interface{} {
var result interface{}
partResolved := false
ctx := v.ancestorCtx(depth)
for (result == nil) && ctx.IsValid() && (depth <= len(v.ctx) && !partResolved) {
// try with context
result, partResolved = v.evalCtxPath(ctx, parts, exprRoot)
// As soon as we find the first part of a path, we must not try to resolve with parent context if result is finally `nil`
// Reference: "Dotted Names - Context Precedence" mustache test
if !partResolved && (result == nil) {
// try with previous context
depth++
ctx = v.ancestorCtx(depth)
}
}
return result
} | go | func (v *evalVisitor) evalDepthPath(depth int, parts []string, exprRoot bool) interface{} {
var result interface{}
partResolved := false
ctx := v.ancestorCtx(depth)
for (result == nil) && ctx.IsValid() && (depth <= len(v.ctx) && !partResolved) {
// try with context
result, partResolved = v.evalCtxPath(ctx, parts, exprRoot)
// As soon as we find the first part of a path, we must not try to resolve with parent context if result is finally `nil`
// Reference: "Dotted Names - Context Precedence" mustache test
if !partResolved && (result == nil) {
// try with previous context
depth++
ctx = v.ancestorCtx(depth)
}
}
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalDepthPath",
"(",
"depth",
"int",
",",
"parts",
"[",
"]",
"string",
",",
"exprRoot",
"bool",
")",
"interface",
"{",
"}",
"{",
"var",
"result",
"interface",
"{",
"}",
"\n",
"partResolved",
":=",
"false",
"\n\n",
"ctx",
":=",
"v",
".",
"ancestorCtx",
"(",
"depth",
")",
"\n\n",
"for",
"(",
"result",
"==",
"nil",
")",
"&&",
"ctx",
".",
"IsValid",
"(",
")",
"&&",
"(",
"depth",
"<=",
"len",
"(",
"v",
".",
"ctx",
")",
"&&",
"!",
"partResolved",
")",
"{",
"// try with context",
"result",
",",
"partResolved",
"=",
"v",
".",
"evalCtxPath",
"(",
"ctx",
",",
"parts",
",",
"exprRoot",
")",
"\n\n",
"// As soon as we find the first part of a path, we must not try to resolve with parent context if result is finally `nil`",
"// Reference: \"Dotted Names - Context Precedence\" mustache test",
"if",
"!",
"partResolved",
"&&",
"(",
"result",
"==",
"nil",
")",
"{",
"// try with previous context",
"depth",
"++",
"\n",
"ctx",
"=",
"v",
".",
"ancestorCtx",
"(",
"depth",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // evalDepthPath iterates on contexts, starting at given depth, until there is one that resolve given path parts | [
"evalDepthPath",
"iterates",
"on",
"contexts",
"starting",
"at",
"given",
"depth",
"until",
"there",
"is",
"one",
"that",
"resolve",
"given",
"path",
"parts"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L504-L524 |
575 | aymerick/raymond | eval.go | evalCtxPath | func (v *evalVisitor) evalCtxPath(ctx reflect.Value, parts []string, exprRoot bool) (interface{}, bool) {
var result interface{}
partResolved := false
switch ctx.Kind() {
case reflect.Array, reflect.Slice:
// Array context
var results []interface{}
for i := 0; i < ctx.Len(); i++ {
value, _ := v.evalPath(ctx.Index(i), parts, exprRoot)
if value.IsValid() {
results = append(results, value.Interface())
}
}
result = results
default:
// NOT array context
var value reflect.Value
value, partResolved = v.evalPath(ctx, parts, exprRoot)
if value.IsValid() {
result = value.Interface()
}
}
return result, partResolved
} | go | func (v *evalVisitor) evalCtxPath(ctx reflect.Value, parts []string, exprRoot bool) (interface{}, bool) {
var result interface{}
partResolved := false
switch ctx.Kind() {
case reflect.Array, reflect.Slice:
// Array context
var results []interface{}
for i := 0; i < ctx.Len(); i++ {
value, _ := v.evalPath(ctx.Index(i), parts, exprRoot)
if value.IsValid() {
results = append(results, value.Interface())
}
}
result = results
default:
// NOT array context
var value reflect.Value
value, partResolved = v.evalPath(ctx, parts, exprRoot)
if value.IsValid() {
result = value.Interface()
}
}
return result, partResolved
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalCtxPath",
"(",
"ctx",
"reflect",
".",
"Value",
",",
"parts",
"[",
"]",
"string",
",",
"exprRoot",
"bool",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"var",
"result",
"interface",
"{",
"}",
"\n",
"partResolved",
":=",
"false",
"\n\n",
"switch",
"ctx",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Slice",
":",
"// Array context",
"var",
"results",
"[",
"]",
"interface",
"{",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"ctx",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"value",
",",
"_",
":=",
"v",
".",
"evalPath",
"(",
"ctx",
".",
"Index",
"(",
"i",
")",
",",
"parts",
",",
"exprRoot",
")",
"\n",
"if",
"value",
".",
"IsValid",
"(",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"value",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"result",
"=",
"results",
"\n",
"default",
":",
"// NOT array context",
"var",
"value",
"reflect",
".",
"Value",
"\n\n",
"value",
",",
"partResolved",
"=",
"v",
".",
"evalPath",
"(",
"ctx",
",",
"parts",
",",
"exprRoot",
")",
"\n",
"if",
"value",
".",
"IsValid",
"(",
")",
"{",
"result",
"=",
"value",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"partResolved",
"\n",
"}"
] | // evalCtxPath evaluates path with given context | [
"evalCtxPath",
"evaluates",
"path",
"with",
"given",
"context"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L527-L555 |
576 | aymerick/raymond | eval.go | isHelperCall | func (v *evalVisitor) isHelperCall(node *ast.Expression) bool {
if helperName := node.HelperName(); helperName != "" {
return v.findHelper(helperName) != zero
}
return false
} | go | func (v *evalVisitor) isHelperCall(node *ast.Expression) bool {
if helperName := node.HelperName(); helperName != "" {
return v.findHelper(helperName) != zero
}
return false
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"isHelperCall",
"(",
"node",
"*",
"ast",
".",
"Expression",
")",
"bool",
"{",
"if",
"helperName",
":=",
"node",
".",
"HelperName",
"(",
")",
";",
"helperName",
"!=",
"\"",
"\"",
"{",
"return",
"v",
".",
"findHelper",
"(",
"helperName",
")",
"!=",
"zero",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | //
// Helpers
//
// isHelperCall returns true if given expression is a helper call | [
"Helpers",
"isHelperCall",
"returns",
"true",
"if",
"given",
"expression",
"is",
"a",
"helper",
"call"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L562-L567 |
577 | aymerick/raymond | eval.go | findHelper | func (v *evalVisitor) findHelper(name string) reflect.Value {
// check template helpers
if h := v.tpl.findHelper(name); h != zero {
return h
}
// check global helpers
return findHelper(name)
} | go | func (v *evalVisitor) findHelper(name string) reflect.Value {
// check template helpers
if h := v.tpl.findHelper(name); h != zero {
return h
}
// check global helpers
return findHelper(name)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"findHelper",
"(",
"name",
"string",
")",
"reflect",
".",
"Value",
"{",
"// check template helpers",
"if",
"h",
":=",
"v",
".",
"tpl",
".",
"findHelper",
"(",
"name",
")",
";",
"h",
"!=",
"zero",
"{",
"return",
"h",
"\n",
"}",
"\n\n",
"// check global helpers",
"return",
"findHelper",
"(",
"name",
")",
"\n",
"}"
] | // findHelper finds given helper | [
"findHelper",
"finds",
"given",
"helper"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L570-L578 |
578 | aymerick/raymond | eval.go | callFunc | func (v *evalVisitor) callFunc(name string, funcVal reflect.Value, options *Options) reflect.Value {
params := options.Params()
funcType := funcVal.Type()
// @todo Is there a better way to do that ?
strType := reflect.TypeOf("")
boolType := reflect.TypeOf(true)
// check parameters number
addOptions := false
numIn := funcType.NumIn()
if numIn == len(params)+1 {
lastArgType := funcType.In(numIn - 1)
if reflect.TypeOf(options).AssignableTo(lastArgType) {
addOptions = true
}
}
if !addOptions && (len(params) != numIn) {
v.errorf("Helper '%s' called with wrong number of arguments, needed %d but got %d", name, numIn, len(params))
}
// check and collect arguments
args := make([]reflect.Value, numIn)
for i, param := range params {
arg := reflect.ValueOf(param)
argType := funcType.In(i)
if !arg.IsValid() {
if canBeNil(argType) {
arg = reflect.Zero(argType)
} else if argType.Kind() == reflect.String {
arg = reflect.ValueOf("")
} else {
// @todo Maybe we can panic on that
return reflect.Zero(strType)
}
}
if !arg.Type().AssignableTo(argType) {
if strType.AssignableTo(argType) {
// convert parameter to string
arg = reflect.ValueOf(strValue(arg))
} else if boolType.AssignableTo(argType) {
// convert parameter to bool
val, _ := isTrueValue(arg)
arg = reflect.ValueOf(val)
} else {
v.errorf("Helper %s called with argument %d with type %s but it should be %s", name, i, arg.Type(), argType)
}
}
args[i] = arg
}
if addOptions {
args[numIn-1] = reflect.ValueOf(options)
}
result := funcVal.Call(args)
return result[0]
} | go | func (v *evalVisitor) callFunc(name string, funcVal reflect.Value, options *Options) reflect.Value {
params := options.Params()
funcType := funcVal.Type()
// @todo Is there a better way to do that ?
strType := reflect.TypeOf("")
boolType := reflect.TypeOf(true)
// check parameters number
addOptions := false
numIn := funcType.NumIn()
if numIn == len(params)+1 {
lastArgType := funcType.In(numIn - 1)
if reflect.TypeOf(options).AssignableTo(lastArgType) {
addOptions = true
}
}
if !addOptions && (len(params) != numIn) {
v.errorf("Helper '%s' called with wrong number of arguments, needed %d but got %d", name, numIn, len(params))
}
// check and collect arguments
args := make([]reflect.Value, numIn)
for i, param := range params {
arg := reflect.ValueOf(param)
argType := funcType.In(i)
if !arg.IsValid() {
if canBeNil(argType) {
arg = reflect.Zero(argType)
} else if argType.Kind() == reflect.String {
arg = reflect.ValueOf("")
} else {
// @todo Maybe we can panic on that
return reflect.Zero(strType)
}
}
if !arg.Type().AssignableTo(argType) {
if strType.AssignableTo(argType) {
// convert parameter to string
arg = reflect.ValueOf(strValue(arg))
} else if boolType.AssignableTo(argType) {
// convert parameter to bool
val, _ := isTrueValue(arg)
arg = reflect.ValueOf(val)
} else {
v.errorf("Helper %s called with argument %d with type %s but it should be %s", name, i, arg.Type(), argType)
}
}
args[i] = arg
}
if addOptions {
args[numIn-1] = reflect.ValueOf(options)
}
result := funcVal.Call(args)
return result[0]
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"callFunc",
"(",
"name",
"string",
",",
"funcVal",
"reflect",
".",
"Value",
",",
"options",
"*",
"Options",
")",
"reflect",
".",
"Value",
"{",
"params",
":=",
"options",
".",
"Params",
"(",
")",
"\n\n",
"funcType",
":=",
"funcVal",
".",
"Type",
"(",
")",
"\n\n",
"// @todo Is there a better way to do that ?",
"strType",
":=",
"reflect",
".",
"TypeOf",
"(",
"\"",
"\"",
")",
"\n",
"boolType",
":=",
"reflect",
".",
"TypeOf",
"(",
"true",
")",
"\n\n",
"// check parameters number",
"addOptions",
":=",
"false",
"\n",
"numIn",
":=",
"funcType",
".",
"NumIn",
"(",
")",
"\n\n",
"if",
"numIn",
"==",
"len",
"(",
"params",
")",
"+",
"1",
"{",
"lastArgType",
":=",
"funcType",
".",
"In",
"(",
"numIn",
"-",
"1",
")",
"\n",
"if",
"reflect",
".",
"TypeOf",
"(",
"options",
")",
".",
"AssignableTo",
"(",
"lastArgType",
")",
"{",
"addOptions",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"addOptions",
"&&",
"(",
"len",
"(",
"params",
")",
"!=",
"numIn",
")",
"{",
"v",
".",
"errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"numIn",
",",
"len",
"(",
"params",
")",
")",
"\n",
"}",
"\n\n",
"// check and collect arguments",
"args",
":=",
"make",
"(",
"[",
"]",
"reflect",
".",
"Value",
",",
"numIn",
")",
"\n",
"for",
"i",
",",
"param",
":=",
"range",
"params",
"{",
"arg",
":=",
"reflect",
".",
"ValueOf",
"(",
"param",
")",
"\n",
"argType",
":=",
"funcType",
".",
"In",
"(",
"i",
")",
"\n\n",
"if",
"!",
"arg",
".",
"IsValid",
"(",
")",
"{",
"if",
"canBeNil",
"(",
"argType",
")",
"{",
"arg",
"=",
"reflect",
".",
"Zero",
"(",
"argType",
")",
"\n",
"}",
"else",
"if",
"argType",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"String",
"{",
"arg",
"=",
"reflect",
".",
"ValueOf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"// @todo Maybe we can panic on that",
"return",
"reflect",
".",
"Zero",
"(",
"strType",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"arg",
".",
"Type",
"(",
")",
".",
"AssignableTo",
"(",
"argType",
")",
"{",
"if",
"strType",
".",
"AssignableTo",
"(",
"argType",
")",
"{",
"// convert parameter to string",
"arg",
"=",
"reflect",
".",
"ValueOf",
"(",
"strValue",
"(",
"arg",
")",
")",
"\n",
"}",
"else",
"if",
"boolType",
".",
"AssignableTo",
"(",
"argType",
")",
"{",
"// convert parameter to bool",
"val",
",",
"_",
":=",
"isTrueValue",
"(",
"arg",
")",
"\n",
"arg",
"=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n",
"}",
"else",
"{",
"v",
".",
"errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"i",
",",
"arg",
".",
"Type",
"(",
")",
",",
"argType",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"args",
"[",
"i",
"]",
"=",
"arg",
"\n",
"}",
"\n\n",
"if",
"addOptions",
"{",
"args",
"[",
"numIn",
"-",
"1",
"]",
"=",
"reflect",
".",
"ValueOf",
"(",
"options",
")",
"\n",
"}",
"\n\n",
"result",
":=",
"funcVal",
".",
"Call",
"(",
"args",
")",
"\n\n",
"return",
"result",
"[",
"0",
"]",
"\n",
"}"
] | // callFunc calls function with given options | [
"callFunc",
"calls",
"function",
"with",
"given",
"options"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L581-L645 |
579 | aymerick/raymond | eval.go | callHelper | func (v *evalVisitor) callHelper(name string, helper reflect.Value, node *ast.Expression) interface{} {
result := v.callFunc(name, helper, v.helperOptions(node))
if !result.IsValid() {
return nil
}
// @todo We maybe want to ensure here that helper returned a string or a SafeString
return result.Interface()
} | go | func (v *evalVisitor) callHelper(name string, helper reflect.Value, node *ast.Expression) interface{} {
result := v.callFunc(name, helper, v.helperOptions(node))
if !result.IsValid() {
return nil
}
// @todo We maybe want to ensure here that helper returned a string or a SafeString
return result.Interface()
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"callHelper",
"(",
"name",
"string",
",",
"helper",
"reflect",
".",
"Value",
",",
"node",
"*",
"ast",
".",
"Expression",
")",
"interface",
"{",
"}",
"{",
"result",
":=",
"v",
".",
"callFunc",
"(",
"name",
",",
"helper",
",",
"v",
".",
"helperOptions",
"(",
"node",
")",
")",
"\n",
"if",
"!",
"result",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// @todo We maybe want to ensure here that helper returned a string or a SafeString",
"return",
"result",
".",
"Interface",
"(",
")",
"\n",
"}"
] | // callHelper invoqs helper function for given expression node | [
"callHelper",
"invoqs",
"helper",
"function",
"for",
"given",
"expression",
"node"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L648-L656 |
580 | aymerick/raymond | eval.go | helperOptions | func (v *evalVisitor) helperOptions(node *ast.Expression) *Options {
var params []interface{}
var hash map[string]interface{}
for _, paramNode := range node.Params {
param := paramNode.Accept(v)
params = append(params, param)
}
if node.Hash != nil {
hash, _ = node.Hash.Accept(v).(map[string]interface{})
}
return newOptions(v, params, hash)
} | go | func (v *evalVisitor) helperOptions(node *ast.Expression) *Options {
var params []interface{}
var hash map[string]interface{}
for _, paramNode := range node.Params {
param := paramNode.Accept(v)
params = append(params, param)
}
if node.Hash != nil {
hash, _ = node.Hash.Accept(v).(map[string]interface{})
}
return newOptions(v, params, hash)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"helperOptions",
"(",
"node",
"*",
"ast",
".",
"Expression",
")",
"*",
"Options",
"{",
"var",
"params",
"[",
"]",
"interface",
"{",
"}",
"\n",
"var",
"hash",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n\n",
"for",
"_",
",",
"paramNode",
":=",
"range",
"node",
".",
"Params",
"{",
"param",
":=",
"paramNode",
".",
"Accept",
"(",
"v",
")",
"\n",
"params",
"=",
"append",
"(",
"params",
",",
"param",
")",
"\n",
"}",
"\n\n",
"if",
"node",
".",
"Hash",
"!=",
"nil",
"{",
"hash",
",",
"_",
"=",
"node",
".",
"Hash",
".",
"Accept",
"(",
"v",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"newOptions",
"(",
"v",
",",
"params",
",",
"hash",
")",
"\n",
"}"
] | // helperOptions computes helper options argument from an expression | [
"helperOptions",
"computes",
"helper",
"options",
"argument",
"from",
"an",
"expression"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L659-L673 |
581 | aymerick/raymond | eval.go | findPartial | func (v *evalVisitor) findPartial(name string) *partial {
// check template partials
if p := v.tpl.findPartial(name); p != nil {
return p
}
// check global partials
return findPartial(name)
} | go | func (v *evalVisitor) findPartial(name string) *partial {
// check template partials
if p := v.tpl.findPartial(name); p != nil {
return p
}
// check global partials
return findPartial(name)
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"findPartial",
"(",
"name",
"string",
")",
"*",
"partial",
"{",
"// check template partials",
"if",
"p",
":=",
"v",
".",
"tpl",
".",
"findPartial",
"(",
"name",
")",
";",
"p",
"!=",
"nil",
"{",
"return",
"p",
"\n",
"}",
"\n\n",
"// check global partials",
"return",
"findPartial",
"(",
"name",
")",
"\n",
"}"
] | //
// Partials
//
// findPartial finds given partial | [
"Partials",
"findPartial",
"finds",
"given",
"partial"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L680-L688 |
582 | aymerick/raymond | eval.go | partialContext | func (v *evalVisitor) partialContext(node *ast.PartialStatement) reflect.Value {
if nb := len(node.Params); nb > 1 {
v.errorf("Unsupported number of partial arguments: %d", nb)
}
if (len(node.Params) > 0) && (node.Hash != nil) {
v.errorf("Passing both context and named parameters to a partial is not allowed")
}
if len(node.Params) == 1 {
return reflect.ValueOf(node.Params[0].Accept(v))
}
if node.Hash != nil {
hash, _ := node.Hash.Accept(v).(map[string]interface{})
return reflect.ValueOf(hash)
}
return zero
} | go | func (v *evalVisitor) partialContext(node *ast.PartialStatement) reflect.Value {
if nb := len(node.Params); nb > 1 {
v.errorf("Unsupported number of partial arguments: %d", nb)
}
if (len(node.Params) > 0) && (node.Hash != nil) {
v.errorf("Passing both context and named parameters to a partial is not allowed")
}
if len(node.Params) == 1 {
return reflect.ValueOf(node.Params[0].Accept(v))
}
if node.Hash != nil {
hash, _ := node.Hash.Accept(v).(map[string]interface{})
return reflect.ValueOf(hash)
}
return zero
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"partialContext",
"(",
"node",
"*",
"ast",
".",
"PartialStatement",
")",
"reflect",
".",
"Value",
"{",
"if",
"nb",
":=",
"len",
"(",
"node",
".",
"Params",
")",
";",
"nb",
">",
"1",
"{",
"v",
".",
"errorf",
"(",
"\"",
"\"",
",",
"nb",
")",
"\n",
"}",
"\n\n",
"if",
"(",
"len",
"(",
"node",
".",
"Params",
")",
">",
"0",
")",
"&&",
"(",
"node",
".",
"Hash",
"!=",
"nil",
")",
"{",
"v",
".",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"node",
".",
"Params",
")",
"==",
"1",
"{",
"return",
"reflect",
".",
"ValueOf",
"(",
"node",
".",
"Params",
"[",
"0",
"]",
".",
"Accept",
"(",
"v",
")",
")",
"\n",
"}",
"\n\n",
"if",
"node",
".",
"Hash",
"!=",
"nil",
"{",
"hash",
",",
"_",
":=",
"node",
".",
"Hash",
".",
"Accept",
"(",
"v",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"return",
"reflect",
".",
"ValueOf",
"(",
"hash",
")",
"\n",
"}",
"\n\n",
"return",
"zero",
"\n",
"}"
] | // partialContext computes partial context | [
"partialContext",
"computes",
"partial",
"context"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L691-L710 |
583 | aymerick/raymond | eval.go | evalPartial | func (v *evalVisitor) evalPartial(p *partial, node *ast.PartialStatement) string {
// get partial template
partialTpl, err := p.template()
if err != nil {
v.errPanic(err)
}
// push partial context
ctx := v.partialContext(node)
if ctx.IsValid() {
v.pushCtx(ctx)
}
// evaluate partial template
result, _ := partialTpl.program.Accept(v).(string)
// ident partial
result = indentLines(result, node.Indent)
if ctx.IsValid() {
v.popCtx()
}
return result
} | go | func (v *evalVisitor) evalPartial(p *partial, node *ast.PartialStatement) string {
// get partial template
partialTpl, err := p.template()
if err != nil {
v.errPanic(err)
}
// push partial context
ctx := v.partialContext(node)
if ctx.IsValid() {
v.pushCtx(ctx)
}
// evaluate partial template
result, _ := partialTpl.program.Accept(v).(string)
// ident partial
result = indentLines(result, node.Indent)
if ctx.IsValid() {
v.popCtx()
}
return result
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"evalPartial",
"(",
"p",
"*",
"partial",
",",
"node",
"*",
"ast",
".",
"PartialStatement",
")",
"string",
"{",
"// get partial template",
"partialTpl",
",",
"err",
":=",
"p",
".",
"template",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"v",
".",
"errPanic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// push partial context",
"ctx",
":=",
"v",
".",
"partialContext",
"(",
"node",
")",
"\n",
"if",
"ctx",
".",
"IsValid",
"(",
")",
"{",
"v",
".",
"pushCtx",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"// evaluate partial template",
"result",
",",
"_",
":=",
"partialTpl",
".",
"program",
".",
"Accept",
"(",
"v",
")",
".",
"(",
"string",
")",
"\n\n",
"// ident partial",
"result",
"=",
"indentLines",
"(",
"result",
",",
"node",
".",
"Indent",
")",
"\n\n",
"if",
"ctx",
".",
"IsValid",
"(",
")",
"{",
"v",
".",
"popCtx",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // evalPartial evaluates a partial | [
"evalPartial",
"evaluates",
"a",
"partial"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L713-L737 |
584 | aymerick/raymond | eval.go | indentLines | func indentLines(str string, indent string) string {
if indent == "" {
return str
}
var indented []string
lines := strings.Split(str, "\n")
for i, line := range lines {
if (i == (len(lines) - 1)) && (line == "") {
// input string ends with a new line
indented = append(indented, line)
} else {
indented = append(indented, indent+line)
}
}
return strings.Join(indented, "\n")
} | go | func indentLines(str string, indent string) string {
if indent == "" {
return str
}
var indented []string
lines := strings.Split(str, "\n")
for i, line := range lines {
if (i == (len(lines) - 1)) && (line == "") {
// input string ends with a new line
indented = append(indented, line)
} else {
indented = append(indented, indent+line)
}
}
return strings.Join(indented, "\n")
} | [
"func",
"indentLines",
"(",
"str",
"string",
",",
"indent",
"string",
")",
"string",
"{",
"if",
"indent",
"==",
"\"",
"\"",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"var",
"indented",
"[",
"]",
"string",
"\n\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"str",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"(",
"i",
"==",
"(",
"len",
"(",
"lines",
")",
"-",
"1",
")",
")",
"&&",
"(",
"line",
"==",
"\"",
"\"",
")",
"{",
"// input string ends with a new line",
"indented",
"=",
"append",
"(",
"indented",
",",
"line",
")",
"\n",
"}",
"else",
"{",
"indented",
"=",
"append",
"(",
"indented",
",",
"indent",
"+",
"line",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"indented",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // indentLines indents all lines of given string | [
"indentLines",
"indents",
"all",
"lines",
"of",
"given",
"string"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L740-L758 |
585 | aymerick/raymond | eval.go | wasFuncCall | func (v *evalVisitor) wasFuncCall(node *ast.Expression) bool {
// check if expression was tagged as a function call
return v.exprFunc[node]
} | go | func (v *evalVisitor) wasFuncCall(node *ast.Expression) bool {
// check if expression was tagged as a function call
return v.exprFunc[node]
} | [
"func",
"(",
"v",
"*",
"evalVisitor",
")",
"wasFuncCall",
"(",
"node",
"*",
"ast",
".",
"Expression",
")",
"bool",
"{",
"// check if expression was tagged as a function call",
"return",
"v",
".",
"exprFunc",
"[",
"node",
"]",
"\n",
"}"
] | //
// Functions
//
// wasFuncCall returns true if given expression was a function call | [
"Functions",
"wasFuncCall",
"returns",
"true",
"if",
"given",
"expression",
"was",
"a",
"function",
"call"
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/eval.go#L765-L768 |
586 | aymerick/raymond | ast/node.go | NewStrip | func NewStrip(openStr, closeStr string) *Strip {
return &Strip{
Open: (len(openStr) > 2) && openStr[2] == '~',
Close: (len(closeStr) > 2) && closeStr[len(closeStr)-3] == '~',
}
} | go | func NewStrip(openStr, closeStr string) *Strip {
return &Strip{
Open: (len(openStr) > 2) && openStr[2] == '~',
Close: (len(closeStr) > 2) && closeStr[len(closeStr)-3] == '~',
}
} | [
"func",
"NewStrip",
"(",
"openStr",
",",
"closeStr",
"string",
")",
"*",
"Strip",
"{",
"return",
"&",
"Strip",
"{",
"Open",
":",
"(",
"len",
"(",
"openStr",
")",
">",
"2",
")",
"&&",
"openStr",
"[",
"2",
"]",
"==",
"'~'",
",",
"Close",
":",
"(",
"len",
"(",
"closeStr",
")",
">",
"2",
")",
"&&",
"closeStr",
"[",
"len",
"(",
"closeStr",
")",
"-",
"3",
"]",
"==",
"'~'",
",",
"}",
"\n",
"}"
] | // NewStrip instanciates a Strip for given open and close mustaches. | [
"NewStrip",
"instanciates",
"a",
"Strip",
"for",
"given",
"open",
"and",
"close",
"mustaches",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L129-L134 |
587 | aymerick/raymond | ast/node.go | NewStripForStr | func NewStripForStr(str string) *Strip {
return &Strip{
Open: (len(str) > 2) && str[2] == '~',
Close: (len(str) > 2) && str[len(str)-3] == '~',
}
} | go | func NewStripForStr(str string) *Strip {
return &Strip{
Open: (len(str) > 2) && str[2] == '~',
Close: (len(str) > 2) && str[len(str)-3] == '~',
}
} | [
"func",
"NewStripForStr",
"(",
"str",
"string",
")",
"*",
"Strip",
"{",
"return",
"&",
"Strip",
"{",
"Open",
":",
"(",
"len",
"(",
"str",
")",
">",
"2",
")",
"&&",
"str",
"[",
"2",
"]",
"==",
"'~'",
",",
"Close",
":",
"(",
"len",
"(",
"str",
")",
">",
"2",
")",
"&&",
"str",
"[",
"len",
"(",
"str",
")",
"-",
"3",
"]",
"==",
"'~'",
",",
"}",
"\n",
"}"
] | // NewStripForStr instanciates a Strip for given tag. | [
"NewStripForStr",
"instanciates",
"a",
"Strip",
"for",
"given",
"tag",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L137-L142 |
588 | aymerick/raymond | ast/node.go | NewProgram | func NewProgram(pos int, line int) *Program {
return &Program{
NodeType: NodeProgram,
Loc: Loc{pos, line},
}
} | go | func NewProgram(pos int, line int) *Program {
return &Program{
NodeType: NodeProgram,
Loc: Loc{pos, line},
}
} | [
"func",
"NewProgram",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"Program",
"{",
"return",
"&",
"Program",
"{",
"NodeType",
":",
"NodeProgram",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewProgram instanciates a new program node. | [
"NewProgram",
"instanciates",
"a",
"new",
"program",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L167-L172 |
589 | aymerick/raymond | ast/node.go | AddStatement | func (node *Program) AddStatement(statement Node) {
node.Body = append(node.Body, statement)
} | go | func (node *Program) AddStatement(statement Node) {
node.Body = append(node.Body, statement)
} | [
"func",
"(",
"node",
"*",
"Program",
")",
"AddStatement",
"(",
"statement",
"Node",
")",
"{",
"node",
".",
"Body",
"=",
"append",
"(",
"node",
".",
"Body",
",",
"statement",
")",
"\n",
"}"
] | // AddStatement adds given statement to program. | [
"AddStatement",
"adds",
"given",
"statement",
"to",
"program",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L185-L187 |
590 | aymerick/raymond | ast/node.go | NewMustacheStatement | func NewMustacheStatement(pos int, line int, unescaped bool) *MustacheStatement {
return &MustacheStatement{
NodeType: NodeMustache,
Loc: Loc{pos, line},
Unescaped: unescaped,
}
} | go | func NewMustacheStatement(pos int, line int, unescaped bool) *MustacheStatement {
return &MustacheStatement{
NodeType: NodeMustache,
Loc: Loc{pos, line},
Unescaped: unescaped,
}
} | [
"func",
"NewMustacheStatement",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"unescaped",
"bool",
")",
"*",
"MustacheStatement",
"{",
"return",
"&",
"MustacheStatement",
"{",
"NodeType",
":",
"NodeMustache",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Unescaped",
":",
"unescaped",
",",
"}",
"\n",
"}"
] | // NewMustacheStatement instanciates a new mustache node. | [
"NewMustacheStatement",
"instanciates",
"a",
"new",
"mustache",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L206-L212 |
591 | aymerick/raymond | ast/node.go | NewBlockStatement | func NewBlockStatement(pos int, line int) *BlockStatement {
return &BlockStatement{
NodeType: NodeBlock,
Loc: Loc{pos, line},
}
} | go | func NewBlockStatement(pos int, line int) *BlockStatement {
return &BlockStatement{
NodeType: NodeBlock,
Loc: Loc{pos, line},
}
} | [
"func",
"NewBlockStatement",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"BlockStatement",
"{",
"return",
"&",
"BlockStatement",
"{",
"NodeType",
":",
"NodeBlock",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewBlockStatement instanciates a new block node. | [
"NewBlockStatement",
"instanciates",
"a",
"new",
"block",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L245-L250 |
592 | aymerick/raymond | ast/node.go | NewPartialStatement | func NewPartialStatement(pos int, line int) *PartialStatement {
return &PartialStatement{
NodeType: NodePartial,
Loc: Loc{pos, line},
}
} | go | func NewPartialStatement(pos int, line int) *PartialStatement {
return &PartialStatement{
NodeType: NodePartial,
Loc: Loc{pos, line},
}
} | [
"func",
"NewPartialStatement",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"PartialStatement",
"{",
"return",
"&",
"PartialStatement",
"{",
"NodeType",
":",
"NodePartial",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewPartialStatement instanciates a new partial node. | [
"NewPartialStatement",
"instanciates",
"a",
"new",
"partial",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L281-L286 |
593 | aymerick/raymond | ast/node.go | NewContentStatement | func NewContentStatement(pos int, line int, val string) *ContentStatement {
return &ContentStatement{
NodeType: NodeContent,
Loc: Loc{pos, line},
Value: val,
Original: val,
}
} | go | func NewContentStatement(pos int, line int, val string) *ContentStatement {
return &ContentStatement{
NodeType: NodeContent,
Loc: Loc{pos, line},
Value: val,
Original: val,
}
} | [
"func",
"NewContentStatement",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"val",
"string",
")",
"*",
"ContentStatement",
"{",
"return",
"&",
"ContentStatement",
"{",
"NodeType",
":",
"NodeContent",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Value",
":",
"val",
",",
"Original",
":",
"val",
",",
"}",
"\n",
"}"
] | // NewContentStatement instanciates a new content node. | [
"NewContentStatement",
"instanciates",
"a",
"new",
"content",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L316-L324 |
594 | aymerick/raymond | ast/node.go | NewCommentStatement | func NewCommentStatement(pos int, line int, val string) *CommentStatement {
return &CommentStatement{
NodeType: NodeComment,
Loc: Loc{pos, line},
Value: val,
}
} | go | func NewCommentStatement(pos int, line int, val string) *CommentStatement {
return &CommentStatement{
NodeType: NodeComment,
Loc: Loc{pos, line},
Value: val,
}
} | [
"func",
"NewCommentStatement",
"(",
"pos",
"int",
",",
"line",
"int",
",",
"val",
"string",
")",
"*",
"CommentStatement",
"{",
"return",
"&",
"CommentStatement",
"{",
"NodeType",
":",
"NodeComment",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"Value",
":",
"val",
",",
"}",
"\n",
"}"
] | // NewCommentStatement instanciates a new comment node. | [
"NewCommentStatement",
"instanciates",
"a",
"new",
"comment",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L352-L359 |
595 | aymerick/raymond | ast/node.go | NewExpression | func NewExpression(pos int, line int) *Expression {
return &Expression{
NodeType: NodeExpression,
Loc: Loc{pos, line},
}
} | go | func NewExpression(pos int, line int) *Expression {
return &Expression{
NodeType: NodeExpression,
Loc: Loc{pos, line},
}
} | [
"func",
"NewExpression",
"(",
"pos",
"int",
",",
"line",
"int",
")",
"*",
"Expression",
"{",
"return",
"&",
"Expression",
"{",
"NodeType",
":",
"NodeExpression",
",",
"Loc",
":",
"Loc",
"{",
"pos",
",",
"line",
"}",
",",
"}",
"\n",
"}"
] | // NewExpression instanciates a new expression node. | [
"NewExpression",
"instanciates",
"a",
"new",
"expression",
"node",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L386-L391 |
596 | aymerick/raymond | ast/node.go | HelperName | func (node *Expression) HelperName() string {
path, ok := node.Path.(*PathExpression)
if !ok {
return ""
}
if path.Data || (len(path.Parts) != 1) || (path.Depth > 0) || path.Scoped {
return ""
}
return path.Parts[0]
} | go | func (node *Expression) HelperName() string {
path, ok := node.Path.(*PathExpression)
if !ok {
return ""
}
if path.Data || (len(path.Parts) != 1) || (path.Depth > 0) || path.Scoped {
return ""
}
return path.Parts[0]
} | [
"func",
"(",
"node",
"*",
"Expression",
")",
"HelperName",
"(",
")",
"string",
"{",
"path",
",",
"ok",
":=",
"node",
".",
"Path",
".",
"(",
"*",
"PathExpression",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"path",
".",
"Data",
"||",
"(",
"len",
"(",
"path",
".",
"Parts",
")",
"!=",
"1",
")",
"||",
"(",
"path",
".",
"Depth",
">",
"0",
")",
"||",
"path",
".",
"Scoped",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"path",
".",
"Parts",
"[",
"0",
"]",
"\n",
"}"
] | // HelperName returns helper name, or an empty string if this expression can't be a helper. | [
"HelperName",
"returns",
"helper",
"name",
"or",
"an",
"empty",
"string",
"if",
"this",
"expression",
"can",
"t",
"be",
"a",
"helper",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L404-L415 |
597 | aymerick/raymond | ast/node.go | FieldPath | func (node *Expression) FieldPath() *PathExpression {
path, ok := node.Path.(*PathExpression)
if !ok {
return nil
}
return path
} | go | func (node *Expression) FieldPath() *PathExpression {
path, ok := node.Path.(*PathExpression)
if !ok {
return nil
}
return path
} | [
"func",
"(",
"node",
"*",
"Expression",
")",
"FieldPath",
"(",
")",
"*",
"PathExpression",
"{",
"path",
",",
"ok",
":=",
"node",
".",
"Path",
".",
"(",
"*",
"PathExpression",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"path",
"\n",
"}"
] | // FieldPath returns path expression representing a field path, or nil if this is not a field path. | [
"FieldPath",
"returns",
"path",
"expression",
"representing",
"a",
"field",
"path",
"or",
"nil",
"if",
"this",
"is",
"not",
"a",
"field",
"path",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L418-L425 |
598 | aymerick/raymond | ast/node.go | Canonical | func (node *Expression) Canonical() string {
if str, ok := HelperNameStr(node.Path); ok {
return str
}
return ""
} | go | func (node *Expression) Canonical() string {
if str, ok := HelperNameStr(node.Path); ok {
return str
}
return ""
} | [
"func",
"(",
"node",
"*",
"Expression",
")",
"Canonical",
"(",
")",
"string",
"{",
"if",
"str",
",",
"ok",
":=",
"HelperNameStr",
"(",
"node",
".",
"Path",
")",
";",
"ok",
"{",
"return",
"str",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Canonical returns the canonical form of expression node as a string. | [
"Canonical",
"returns",
"the",
"canonical",
"form",
"of",
"expression",
"node",
"as",
"a",
"string",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L433-L439 |
599 | aymerick/raymond | ast/node.go | PathExpressionStr | func PathExpressionStr(node Node) (string, bool) {
if path, ok := node.(*PathExpression); ok {
result := path.Original
// "[foo bar]"" => "foo bar"
if (len(result) >= 2) && (result[0] == '[') && (result[len(result)-1] == ']') {
result = result[1 : len(result)-1]
}
return result, true
}
return "", false
} | go | func PathExpressionStr(node Node) (string, bool) {
if path, ok := node.(*PathExpression); ok {
result := path.Original
// "[foo bar]"" => "foo bar"
if (len(result) >= 2) && (result[0] == '[') && (result[len(result)-1] == ']') {
result = result[1 : len(result)-1]
}
return result, true
}
return "", false
} | [
"func",
"PathExpressionStr",
"(",
"node",
"Node",
")",
"(",
"string",
",",
"bool",
")",
"{",
"if",
"path",
",",
"ok",
":=",
"node",
".",
"(",
"*",
"PathExpression",
")",
";",
"ok",
"{",
"result",
":=",
"path",
".",
"Original",
"\n\n",
"// \"[foo bar]\"\" => \"foo bar\"",
"if",
"(",
"len",
"(",
"result",
")",
">=",
"2",
")",
"&&",
"(",
"result",
"[",
"0",
"]",
"==",
"'['",
")",
"&&",
"(",
"result",
"[",
"len",
"(",
"result",
")",
"-",
"1",
"]",
"==",
"']'",
")",
"{",
"result",
"=",
"result",
"[",
"1",
":",
"len",
"(",
"result",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"true",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // PathExpressionStr returns the string representation of path expression value, with a boolean set to false if this is not a path expression. | [
"PathExpressionStr",
"returns",
"the",
"string",
"representation",
"of",
"path",
"expression",
"value",
"with",
"a",
"boolean",
"set",
"to",
"false",
"if",
"this",
"is",
"not",
"a",
"path",
"expression",
"."
] | b565731e1464263de0bda75f2e45d97b54b60110 | https://github.com/aymerick/raymond/blob/b565731e1464263de0bda75f2e45d97b54b60110/ast/node.go#L459-L472 |