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

Function ValueArray

expr/parse.go:819–868  ·  view source on GitHub ↗

ValueArray IN ("a","b","c") ["a","b","c"]

(depth int, pg TokenPager)

Source from the content-addressed store, hash-verified

817// IN ("a","b","c")
818// ["a","b","c"]
819func ValueArray(depth int, pg TokenPager) (value.Value, error) {
820
821 vals := make([]value.Value, 0)
822arrayLoop:
823 for {
824 tok := pg.Next() // consume token
825 debugf(depth, "ValueArray: len(%d), cur:%v", len(vals), tok)
826 switch tok.T {
827 case lex.TokenComma:
828 // continue
829 case lex.TokenRightParenthesis:
830 break arrayLoop
831 case lex.TokenEOF, lex.TokenEOS, lex.TokenFrom, lex.TokenAs:
832 break arrayLoop
833 case lex.TokenValue:
834 vals = append(vals, value.NewStringValue(tok.V))
835 case lex.TokenValueEscaped:
836 newVal, _ := StringUnEscape('"', tok.V)
837 vals = append(vals, value.NewStringValue(newVal))
838 case lex.TokenInteger:
839 fv, err := strconv.ParseFloat(tok.V, 64)
840 if err == nil {
841 vals = append(vals, value.NewNumberValue(fv))
842 } else {
843 return value.NilValueVal, err
844 }
845 case lex.TokenFloat:
846 fv, err := strconv.ParseFloat(tok.V, 64)
847 if err == nil {
848 vals = append(vals, value.NewNumberValue(fv))
849 } else {
850 return value.NilValueVal, err
851 }
852 default:
853 return value.NilValueVal, fmt.Errorf("Could not recognize token: %v", tok)
854 }
855
856 tok = pg.Next()
857 switch tok.T {
858 case lex.TokenComma:
859 // fine, consume the comma
860 case lex.TokenRightBracket:
861 break arrayLoop
862 default:
863 u.Warnf("unrecognized token: %v", tok)
864 return value.NilValueVal, fmt.Errorf("unrecognized token %v", tok)
865 }
866 }
867 return value.NewSliceValues(vals), nil
868}
869
870func nodeArray(t *tree, depth int) ([]Node, error, bool) {
871

Callers 3

parseValueListMethod · 0.92
cInnerMethod · 0.85
vMethod · 0.85

Calls 7

NewStringValueFunction · 0.92
NewNumberValueFunction · 0.92
NewSliceValuesFunction · 0.92
StringUnEscapeFunction · 0.85
ErrorfMethod · 0.80
debugfFunction · 0.70
NextMethod · 0.65

Tested by

no test coverage detected