github.com/kubeshop/testkube@v1.17.23/pkg/tcl/expressionstcl/tokens.go (about) 1 // Copyright 2024 Testkube. 2 // 3 // Licensed as a Testkube Pro file under the Testkube Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt 8 9 package expressionstcl 10 11 type tokenType uint8 12 13 const ( 14 // Primitives 15 tokenTypeAccessor tokenType = iota 16 tokenTypePropertyAccessor 17 tokenTypeJson 18 19 // Math 20 tokenTypeNot 21 tokenTypeMath 22 tokenTypeOpen 23 tokenTypeClose 24 25 // Logical 26 tokenTypeTernary 27 tokenTypeTernarySeparator 28 29 // Functions 30 tokenTypeComma 31 tokenTypeSpread 32 ) 33 34 type token struct { 35 Type tokenType 36 Value interface{} 37 } 38 39 var ( 40 tokenNot = token{Type: tokenTypeNot} 41 tokenOpen = token{Type: tokenTypeOpen} 42 tokenClose = token{Type: tokenTypeClose} 43 tokenTernary = token{Type: tokenTypeTernary} 44 tokenTernarySeparator = token{Type: tokenTypeTernarySeparator} 45 tokenComma = token{Type: tokenTypeComma} 46 tokenSpread = token{Type: tokenTypeSpread} 47 ) 48 49 func tokenMath(op string) token { 50 return token{Type: tokenTypeMath, Value: op} 51 } 52 53 func tokenJson(value interface{}) token { 54 return token{Type: tokenTypeJson, Value: value} 55 } 56 57 func tokenAccessor(value interface{}) token { 58 return token{Type: tokenTypeAccessor, Value: value} 59 } 60 61 func tokenPropertyAccessor(value interface{}) token { 62 return token{Type: tokenTypePropertyAccessor, Value: value} 63 }