Class: NScript::ValueNode
- Inherits:
-
Node
- Object
- Node
- NScript::ValueNode
show all
- Defined in:
- lib/nscript/parser/nodes.rb
Constant Summary
collapse
- SOAK =
" == undefined ? undefined : "
Constants inherited
from Node
Node::TAB
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #write
Constructor Details
#initialize(base, properties = []) ⇒ ValueNode
Returns a new instance of ValueNode.
277
278
279
|
# File 'lib/nscript/parser/nodes.rb', line 277
def initialize(base, properties=[])
@base, @properties = base, [properties].flatten
end
|
Instance Attribute Details
#last ⇒ Object
Returns the value of attribute last.
273
274
275
|
# File 'lib/nscript/parser/nodes.rb', line 273
def last
@last
end
|
#source ⇒ Object
Returns the value of attribute source.
273
274
275
|
# File 'lib/nscript/parser/nodes.rb', line 273
def source
@source
end
|
Instance Method Details
#<<(other) ⇒ Object
281
282
283
284
|
# File 'lib/nscript/parser/nodes.rb', line 281
def <<(other)
@properties << other
self
end
|
#arguments? ⇒ Boolean
302
303
304
|
# File 'lib/nscript/parser/nodes.rb', line 302
def arguments?
@base.to_s == 'arguments'
end
|
#array? ⇒ Boolean
290
291
292
|
# File 'lib/nscript/parser/nodes.rb', line 290
def array?
@base.is_a?(ArrayNode) && !properties?
end
|
#compile_node(o) ⇒ Object
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/nscript/parser/nodes.rb', line 314
def compile_node(o)
soaked = false
only = o.delete(:only_first)
props = only ? @properties[0...-1] : @properties
baseline = @base.compile(o)
parts = [baseline.dup]
props.each do |prop|
if prop.is_a?(AccessorNode) && prop.soak
soaked = true
if @base.is_a?(CallNode) && prop == props.first
temp = o[:scope].free_variable
parts[-1] = "(#{temp} = #{baseline})#{SOAK}#{baseline = temp.to_s + prop.compile(o)}"
else
parts[-1] << "#{SOAK}#{baseline += prop.compile(o)}"
end
else
part = prop.compile(o)
baseline += part
parts << part
end
end
@last = parts.last
@source = parts.length > 1 ? parts[0...-1].join('') : nil
code = parts.join('').gsub(')())', '()))')
write(soaked ? "(#{code})" : code)
end
|
#object? ⇒ Boolean
294
295
296
|
# File 'lib/nscript/parser/nodes.rb', line 294
def object?
@base.is_a?(ObjectNode) && !properties?
end
|
#properties? ⇒ Boolean
286
287
288
|
# File 'lib/nscript/parser/nodes.rb', line 286
def properties?
return !@properties.empty? || @base.is_a?(ThisNode)
end
|
#splice? ⇒ Boolean
298
299
300
|
# File 'lib/nscript/parser/nodes.rb', line 298
def splice?
properties? && @properties.last.is_a?(SliceNode)
end
|
#statement? ⇒ Boolean
310
311
312
|
# File 'lib/nscript/parser/nodes.rb', line 310
def statement?
@base.is_a?(Node) && @base.statement? && !properties?
end
|
#unwrap ⇒ Object
306
307
308
|
# File 'lib/nscript/parser/nodes.rb', line 306
def unwrap
@properties.empty? ? @base : self
end
|