rt_const.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package interpreter
  11. import "devt.de/krotik/ecal/parser"
  12. /*
  13. trueRuntime is the runtime component for the true constant.
  14. */
  15. type trueRuntime struct {
  16. *baseRuntime
  17. }
  18. /*
  19. trueRuntimeInst returns a new runtime component instance.
  20. */
  21. func trueRuntimeInst(erp *ECALRuntimeProvider, node *parser.ASTNode) parser.Runtime {
  22. return &trueRuntime{newBaseRuntime(erp, node)}
  23. }
  24. /*
  25. Eval evaluate this runtime component.
  26. */
  27. func (rt *trueRuntime) Eval(vs parser.Scope, is map[string]interface{}) (interface{}, error) {
  28. _, err := rt.baseRuntime.Eval(vs, is)
  29. return true, err
  30. }
  31. /*
  32. falseRuntime is the runtime component for the false constant.
  33. */
  34. type falseRuntime struct {
  35. *baseRuntime
  36. }
  37. /*
  38. falseRuntimeInst returns a new runtime component instance.
  39. */
  40. func falseRuntimeInst(erp *ECALRuntimeProvider, node *parser.ASTNode) parser.Runtime {
  41. return &falseRuntime{newBaseRuntime(erp, node)}
  42. }
  43. /*
  44. Eval evaluate this runtime component.
  45. */
  46. func (rt *falseRuntime) Eval(vs parser.Scope, is map[string]interface{}) (interface{}, error) {
  47. _, err := rt.baseRuntime.Eval(vs, is)
  48. return false, err
  49. }
  50. /*
  51. nullRuntime is the runtime component for the null constant.
  52. */
  53. type nullRuntime struct {
  54. *baseRuntime
  55. }
  56. /*
  57. nullRuntimeInst returns a new runtime component instance.
  58. */
  59. func nullRuntimeInst(erp *ECALRuntimeProvider, node *parser.ASTNode) parser.Runtime {
  60. return &nullRuntime{newBaseRuntime(erp, node)}
  61. }
  62. /*
  63. Eval evaluate this runtime component.
  64. */
  65. func (rt *nullRuntime) Eval(vs parser.Scope, is map[string]interface{}) (interface{}, error) {
  66. _, err := rt.baseRuntime.Eval(vs, is)
  67. return nil, err
  68. }