Browse Source

feat: Change scope interface for ECAL

Matthias Ladkau 3 years ago
parent
commit
11a13c920d
2 changed files with 12 additions and 7 deletions
  1. 1 1
      lang/ecal/README.md
  2. 11 6
      lang/ecal/parser/runtime.go

+ 1 - 1
lang/ecal/README.md

@@ -12,7 +12,7 @@ Source code is Unicode text encoded in UTF-8. Single language statements are sep
 
 Constant values are usually enclosed in double quotes "" or single quotes '', both supporting escape sequences. Constant values can also be provided as raw strings prefixing a single or double quote with an 'r'. A raw string can contain any character including newlines and does not contain escape sequences.
 
-Blocks are denoted with curley brackets. Most language constructs (conditions, loops, etc.) are very similar to other languages.
+Blocks are denoted with curly brackets. Most language constructs (conditions, loops, etc.) are very similar to other languages.
 
 Scope and imports
 --

+ 11 - 6
lang/ecal/parser/runtime.go

@@ -37,18 +37,23 @@ type Runtime interface {
 		The instance state is created per execution instance and can be used
 		for generator functions to store their current state.
 	*/
-	Eval(VarsScope, map[string]interface{}) (interface{}, error)
+	Eval(Scope, map[string]interface{}) (interface{}, error)
 }
 
 /*
-VarsScope is used to store variable data and keep track of scoping.
+Scope models an environment which stores data.
 */
-type VarsScope interface {
+type Scope interface {
 
 	/*
-	   NewChild creates a new child variable scope.
+	   NewChild creates a new child scope.
 	*/
-	NewChild(name string) VarsScope
+	NewChild(name string) Scope
+
+	/*
+	   Parent returns the parent scope or nil.
+	*/
+	Parent(name string) Scope
 
 	/*
 	   SetValue sets a new value for a variable.
@@ -61,7 +66,7 @@ type VarsScope interface {
 	GetValue(varName string) (interface{}, bool, error)
 
 	/*
-	   String returns a string representation of this variable scope.
+	   String returns a string representation of this scope.
 	*/
 	String() string
 }