runtime.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 parser
  11. /*
  12. RuntimeProvider provides runtime components for a parse tree.
  13. */
  14. type RuntimeProvider interface {
  15. /*
  16. Runtime returns a runtime component for a given ASTNode.
  17. */
  18. Runtime(node *ASTNode) Runtime
  19. }
  20. /*
  21. Runtime provides the runtime for an ASTNode.
  22. */
  23. type Runtime interface {
  24. /*
  25. Validate this runtime component and all its child components.
  26. */
  27. Validate() error
  28. /*
  29. Eval evaluate this runtime component. It gets passed the current variable
  30. scope and the instance state.
  31. The instance state is created per execution instance and can be used
  32. for generator functions to store their current state.
  33. */
  34. Eval(Scope, map[string]interface{}) (interface{}, error)
  35. }
  36. /*
  37. Scope models an environment which stores data.
  38. */
  39. type Scope interface {
  40. /*
  41. NewChild creates a new child scope.
  42. */
  43. NewChild(name string) Scope
  44. /*
  45. Parent returns the parent scope or nil.
  46. */
  47. Parent() Scope
  48. /*
  49. SetValue sets a new value for a variable.
  50. */
  51. SetValue(varName string, varValue interface{}) error
  52. /*
  53. GetValue gets the current value of a variable.
  54. */
  55. GetValue(varName string) (interface{}, bool, error)
  56. /*
  57. String returns a string representation of this scope.
  58. */
  59. String() string
  60. }