Class: JSE::Ast::ExpressionNode
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from AstNode
Instance Method Summary collapse
- #apply(call_env) ⇒ Object
-
#initialize(operator, value, metadata, env) ⇒ ExpressionNode
constructor
A new instance of ExpressionNode.
- #to_json ⇒ Object
Constructor Details
#initialize(operator, value, metadata, env) ⇒ ExpressionNode
Returns a new instance of ExpressionNode.
98 99 100 101 102 103 |
# File 'lib/jse/ast/nodes.rb', line 98 def initialize(operator, value, , env) super(env) @operator = operator @value = value @metadata = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
105 106 107 |
# File 'lib/jse/ast/nodes.rb', line 105 def @metadata end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
105 106 107 |
# File 'lib/jse/ast/nodes.rb', line 105 def operator @operator end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
105 106 107 |
# File 'lib/jse/ast/nodes.rb', line 105 def value @value end |
Instance Method Details
#apply(call_env) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/jse/ast/nodes.rb', line 107 def apply(call_env) functor = call_env.resolve(@operator) raise NameError, "Unknown operator: #{@operator}" if functor.nil? = @metadata.transform_values { |v| deep_eval(call_env, v) } call_env.() begin args = case @operator when "$quote" [@value] when "$expr" [call_env.eval(@value)] when "$sql" # $sql receives raw JSON stored in LiteralNode by parser if @value.is_a?(LiteralNode) [@value.value] else [@value] end else if @value.is_a?(ArrayNode) @value.elements.map { |e| deep_eval(call_env, e) } else [call_env.eval(@value)] end end functor.call(call_env, *args) ensure call_env. end end |
#to_json ⇒ Object
140 141 142 143 144 |
# File 'lib/jse/ast/nodes.rb', line 140 def to_json result = { @operator => @value.to_json } @metadata.each { |k, v| result[k] = v } result end |