runtime.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Name returns the name of this scope.
  44. */
  45. Name() string
  46. /*
  47. NewChild creates a new child scope.
  48. */
  49. NewChild(name string) Scope
  50. /*
  51. Clear clears this scope of all stored values. This will clear children scopes
  52. but not remove parent scopes.
  53. */
  54. Clear()
  55. /*
  56. Parent returns the parent scope or nil.
  57. */
  58. Parent() Scope
  59. /*
  60. SetValue sets a new value for a variable.
  61. */
  62. SetValue(varName string, varValue interface{}) error
  63. /*
  64. GetValue gets the current value of a variable.
  65. */
  66. GetValue(varName string) (interface{}, bool, error)
  67. /*
  68. String returns a string representation of this scope.
  69. */
  70. String() string
  71. /*
  72. ToJSONObject returns this ASTNode and all its children as a JSON object.
  73. */
  74. ToJSONObject() map[string]interface{}
  75. }