funcArgsValidator.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ast
  15. func IsNumericArg(arg Expr) bool {
  16. if _, ok := arg.(*NumberLiteral); ok {
  17. return true
  18. } else if _, ok := arg.(*IntegerLiteral); ok {
  19. return true
  20. }
  21. return false
  22. }
  23. func IsIntegerArg(arg Expr) bool {
  24. if _, ok := arg.(*IntegerLiteral); ok {
  25. return true
  26. }
  27. return false
  28. }
  29. func IsFloatArg(arg Expr) bool {
  30. if _, ok := arg.(*NumberLiteral); ok {
  31. return true
  32. }
  33. return false
  34. }
  35. func IsBooleanArg(arg Expr) bool {
  36. switch t := arg.(type) {
  37. case *BooleanLiteral:
  38. return true
  39. case *BinaryExpr:
  40. switch t.OP {
  41. case AND, OR, EQ, NEQ, LT, LTE, GT, GTE:
  42. return true
  43. default:
  44. return false
  45. }
  46. default:
  47. return false
  48. }
  49. }
  50. func IsStringArg(arg Expr) bool {
  51. if _, ok := arg.(*StringLiteral); ok {
  52. return true
  53. }
  54. return false
  55. }
  56. func IsTimeArg(arg Expr) bool {
  57. if _, ok := arg.(*TimeLiteral); ok {
  58. return true
  59. }
  60. return false
  61. }