runtime.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(Scope, map[string]interface{}) (interface{}, error)
  34. }
  35. /*
  36. Scope models an environment which stores data.
  37. */
  38. type Scope interface {
  39. /*
  40. NewChild creates a new child scope.
  41. */
  42. NewChild(name string) Scope
  43. /*
  44. Parent returns the parent scope or nil.
  45. */
  46. Parent() Scope
  47. /*
  48. SetValue sets a new value for a variable.
  49. */
  50. SetValue(varName string, varValue interface{}) error
  51. /*
  52. GetValue gets the current value of a variable.
  53. */
  54. GetValue(varName string) (interface{}, bool, error)
  55. /*
  56. String returns a string representation of this scope.
  57. */
  58. String() string
  59. }