Context
public class Context
The only responsibility of the InterpreterContext class is to store variables, and keep them during the execution, where multiple expressions might use the same set of variables.
-
The stored variables
Declaration
Swift
public var variables: [String : Any] -
Debug information for recognised patterns
Declaration
Swift
public var debugInfo: [String : ExpressionInfo] -
Context can behave as a stack. If
pushis called, it saves a snapshot of the current state of variables to a stack and lets you modify the content, while the previous values are stored, safely. Whenpopis called, it restores the last snapshot, destorying all the changes that happened after the last snapshot. Useful for temporal variables!Declaration
Swift
var stack: [(variables: [String : Any], debugInfo: [String : ExpressionInfo])] -
Users of the context may optionally provide an initial set of variables
Declaration
Swift
public init(variables: [String : Any] = [:])Parameters
variablesVariable names and values
-
Context can behave as a stack. If
pushis called, it saves a snapshot of the current state of variables to a stack and lets you modify the content, while the previous values are stored, safely. Whenpopis called, it restores the last snapshot, destorying all the changes that happened after the last snapshot. Useful for temporal variables! It should be called before setting the temporal variablesDeclaration
Swift
public func push() -
Context can behave as a stack. If
pushis called, it saves a snapshot of the current state of variables to a stack and lets you modify the content, while the previous values are stored, safely. Whenpopis called, it restores the last snapshot, destorying all the changes that happened after the last snapshot. Useful for temporal variables! It should be called when the temporal variables are not needed anymoreDeclaration
Swift
public func pop() -
Creates a new context instance by merging their variable dictionaries. The one in the parameter overrides the duplicated items of the existing one
Declaration
Swift
public func merging(with other: Context?) -> ContextParameters
withThe other context to merge with
Return Value
A new
InterpreterContextinstance with the current and the parameter variables merged inside -
Modifies the current context instance by merging its variable dictionary with the parameter. The one in the parameter overrides the duplicated items of the existing one
Declaration
Swift
public func merge(with other: Context?, merge: (_ existing: Any, _ new: Any) throws -> Any)Parameters
withThe other context to merge with
existingDuring the merge the parameter on the existing dictionary (same terminolody with Dictionary.merge)
newDuring the merge the parameter on the merged dictionary (same terminolody with Dictionary.merge)
Return Value
The same
InterpreterContextinstance after merging the variables dictionary with the variables in the context given as parameter
View on GitHub
Install in Dash
Context Class Reference