runtime.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. package parser
  10. /*
  11. RuntimeProvider provides runtime components for a parse tree.
  12. */
  13. type RuntimeProvider interface {
  14. /*
  15. Runtime returns a runtime component for a given ASTNode.
  16. */
  17. Runtime(node *ASTNode) Runtime
  18. }
  19. /*
  20. Runtime provides the runtime for an ASTNode.
  21. */
  22. type Runtime interface {
  23. /*
  24. Validate this runtime component and all its child components.
  25. */
  26. Validate() error
  27. /*
  28. Eval evaluate this runtime component. It gets passed the current variable
  29. scope and the instance state.
  30. The instance state is created per execution instance and can be used
  31. for generator functions to store their current state.
  32. */
  33. Eval(VarsScope, map[string]interface{}) (interface{}, error)
  34. }
  35. /*
  36. VarsScope is used to store variable data and keep track of scoping.
  37. */
  38. type VarsScope interface {
  39. /*
  40. NewChild creates a new child variable scope.
  41. */
  42. NewChild(name string) VarsScope
  43. /*
  44. SetValue sets a new value for a variable.
  45. */
  46. SetValue(varName string, varValue interface{}) error
  47. /*
  48. GetValue gets the current value of a variable.
  49. */
  50. GetValue(varName string) (interface{}, bool, error)
  51. /*
  52. String returns a string representation of this variable scope.
  53. */
  54. String() string
  55. }