class NScript::Node
Constants
- TAB
Public Class Methods
children(*attributes)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 19 def self.children(*attributes) attr_reader(*attributes) attrs = attributes.map {|a| "[@#{a}]" }.join(', ') class_eval "def children; [#{attrs}].flatten.compact; end" end
statement()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 6 def self.statement class_eval "def statement?; true; end" end
statement_only()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 10 def self.statement_only statement class_eval "def statement_only?; true; end" end
top_sensitive()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 15 def self.top_sensitive class_eval "def top_sensitive?; true; end" end
Public Instance Methods
children()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 57 def children; []; end
compile(o={})
click to toggle source
# File lib/nscript/parser/nodes.rb, line 30 def compile(o={}) @options = o.dup @indent = o[:indent] top = self.top_sensitive? ? @options[:top] : @options.delete(:top) closure = statement? && !statement_only? && !top && !@options[:return] && !self.is_a?(CommentNode) closure &&= !contains? {|n| n.statement_only? } closure ? compile_closure(@options) : compile_node(@options) end
compile_closure(o={})
click to toggle source
# File lib/nscript/parser/nodes.rb, line 39 def compile_closure(o={}) @indent = o[:indent] ClosureNode.wrap(self).compile(o.merge(:shared_scope => o[:scope])) end
contains?() { |node| ... }
click to toggle source
# File lib/nscript/parser/nodes.rb, line 48 def contains?(&block) children.each do |node| return true if yield(node) return true if node.is_a?(Node) && node.contains?(&block) end false end
idt(tabs=0)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 44 def idt(tabs=0) @indent + (TAB * tabs) end
statement?()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 58 def statement?; false; end
statement_only?()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 59 def statement_only?; false; end
top_sensitive?()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 60 def top_sensitive?; false; end
unwrap()
click to toggle source
# File lib/nscript/parser/nodes.rb, line 56 def unwrap; self; end
write(code)
click to toggle source
# File lib/nscript/parser/nodes.rb, line 25 def write(code) puts "#{self.class.to_s}:\n#{@options.inspect}\n#{code}\n\n" if ENV['VERBOSE'] code end