runtime.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 an instance state and a thread ID.
  31. The instance state is created per execution instance and can be used
  32. for generator functions to store their current state. It gets replaced
  33. by a new object in certain situations (e.g. a function call).
  34. The thread ID can be used to identify a running process.
  35. */
  36. Eval(Scope, map[string]interface{}, uint64) (interface{}, error)
  37. }
  38. /*
  39. Scope models an environment which stores data.
  40. */
  41. type Scope interface {
  42. /*
  43. NewChild creates a new child scope.
  44. */
  45. NewChild(name string) Scope
  46. /*
  47. Parent returns the parent scope or nil.
  48. */
  49. Parent() Scope
  50. /*
  51. SetValue sets a new value for a variable.
  52. */
  53. SetValue(varName string, varValue interface{}) error
  54. /*
  55. GetValue gets the current value of a variable.
  56. */
  57. GetValue(varName string) (interface{}, bool, error)
  58. /*
  59. String returns a string representation of this scope.
  60. */
  61. String() string
  62. /*
  63. ToJSONObject returns this ASTNode and all its children as a JSON object.
  64. */
  65. ToJSONObject() map[string]interface{}
  66. }