github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/functions/function.go (about) 1 // go:generate stringify 2 3 package functions 4 5 import "strings" 6 7 type FunctionT struct { 8 Command []rune 9 Parameters [][]rune 10 NamedPipes []string 11 Cast []rune 12 Properties Property 13 LineN int 14 ColumnN int 15 Raw []rune 16 } 17 18 func (fn FunctionT) CommandName() []rune { 19 name := fn.Command 20 if len(name) > 0 && name[len(name)-1] == ':' { 21 name = name[:len(name)-1] 22 } 23 return name 24 } 25 26 type Property int 27 28 const ( 29 P_NEW_CHAIN Property = 1 << iota 30 P_METHOD 31 P_FOLLOW_ON 32 P_PIPE_OUT 33 P_PIPE_ERR 34 P_LOGIC_AND 35 P_LOGIC_OR 36 ) 37 38 func (prop Property) NewChain() bool { return prop&P_NEW_CHAIN != 0 } 39 func (prop Property) Method() bool { return prop&P_METHOD != 0 } 40 func (prop Property) FollowOnFn() bool { return prop&P_FOLLOW_ON != 0 } 41 func (prop Property) PipeOut() bool { return prop&P_PIPE_OUT != 0 } 42 func (prop Property) PipeErr() bool { return prop&P_PIPE_ERR != 0 } 43 func (prop Property) LogicAnd() bool { return prop&P_LOGIC_AND != 0 } 44 func (prop Property) LogicOr() bool { return prop&P_LOGIC_OR != 0 } 45 46 func (prop Property) Decompose() string { 47 var a []string 48 49 if prop.NewChain() { 50 a = append(a, "new pipeline (`\\n`, `;`)") 51 } 52 53 if prop.PipeOut() || prop.Method() { 54 a = append(a, "pipe out (`|`, `->`, `=>`, `|>`, `>>`)") 55 } 56 57 if prop.PipeErr() || prop.Method() { 58 a = append(a, "pipe err (`?`)") 59 } 60 61 if prop.LogicAnd() { 62 a = append(a, "logic AND (`&&`)") 63 } 64 65 if prop.LogicOr() { 66 a = append(a, "logic OR (`||`)") 67 } 68 69 s := strings.Join(a, ", ") 70 71 return s 72 }