MCPcopy Create free account
hub / github.com/araddon/qlbridge / Func

Method Func

expr/parse.go:657–773  ·  view source on GitHub ↗
(depth int, funcTok lex.Token)

Source from the content-addressed store, hash-verified

655}
656
657func (t *tree) Func(depth int, funcTok lex.Token) (fn *FuncNode) {
658 debugf(depth, "Func: tok: %v cur:%v peek:%v", funcTok.V, t.Cur(), t.Peek())
659 if t.Cur().T != lex.TokenLeftParenthesis {
660 t.unexpected(t.Cur(), "must have left paren on function")
661 }
662 var node Node
663 var tok lex.Token
664
665 funcImpl, ok := t.getFunction(funcTok.V)
666 if !ok {
667 if t.funcCheck {
668 t.errorf("non existent function %s", funcTok.V)
669 } else {
670 // if we aren't testing for validity, make a "fake" func
671 // we may not be using vm, just ast
672 //u.Warnf("non func? %v", funcTok.V)
673 funcImpl = Func{Name: funcTok.V, Eval: EmptyEvalFunc}
674 }
675 }
676 fn = NewFuncNode(funcTok.V, funcImpl)
677 fn.Missing = !ok
678
679 t.expect(lex.TokenLeftParenthesis, "func")
680 t.Next() // Are we sure we consume?
681
682 defer func() {
683 if err := fn.Validate(); err != nil {
684 t.error(err) // will panic
685 }
686 }()
687
688 switch {
689 // Ugh, we need a way of identifying which functions get this special
690 // parser?
691 case t.Peek().T == lex.TokenAs && strings.ToLower(fn.Name) == "cast":
692 // We are not in a comma style function
693 // CAST(<expression> AS <identity>)
694
695 node = t.O(depth + 1)
696 if node != nil {
697 fn.append(node)
698 }
699 if t.Cur().T != lex.TokenAs {
700 t.unexpected(t.Cur(), "func AS")
701 }
702 // This really isn't correct, we probably need an OperatorNode?
703 fn.append(NewStringNodeToken(t.Next()))
704 if t.Cur().T != lex.TokenIdentity {
705 t.unexpected(t.Cur(), "func AS exected Identity")
706 }
707 fn.append(NewStringNodeToken(t.Next()))
708 return fn
709 default:
710 lastComma := false
711 for {
712 node = nil
713
714 switch firstToken := t.Cur(); firstToken.T {

Callers 2

cInnerMethod · 0.95
vMethod · 0.95

Calls 14

unexpectedMethod · 0.95
getFunctionMethod · 0.95
errorfMethod · 0.95
expectMethod · 0.95
errorMethod · 0.95
OMethod · 0.95
NewFuncNodeFunction · 0.85
NewStringNodeTokenFunction · 0.85
debugfFunction · 0.70
CurMethod · 0.65
PeekMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected