Class: Nydp::LexicalContext
- Includes:
- Helper
- Defined in:
- lib/nydp/lexical_context.rb
Instance Attribute Summary collapse
-
#at_0 ⇒ Object
Returns the value of attribute at_0.
-
#at_1 ⇒ Object
Returns the value of attribute at_1.
-
#at_2 ⇒ Object
Returns the value of attribute at_2.
-
#at_3 ⇒ Object
Returns the value of attribute at_3.
-
#at_4 ⇒ Object
Returns the value of attribute at_4.
-
#at_5 ⇒ Object
Returns the value of attribute at_5.
-
#at_6 ⇒ Object
Returns the value of attribute at_6.
-
#at_7 ⇒ Object
Returns the value of attribute at_7.
-
#at_8 ⇒ Object
Returns the value of attribute at_8.
-
#at_9 ⇒ Object
Returns the value of attribute at_9.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #at_index(index) ⇒ Object
-
#initialize(parent) ⇒ LexicalContext
constructor
A new instance of LexicalContext.
- #method_missing(mname, *args) ⇒ Object
- #nth(n) ⇒ Object
- #pretty ⇒ Object
- #set_index(index, value) ⇒ Object
- #to_s ⇒ Object
- #to_s_with_indent(str) ⇒ Object
Methods included from Helper
#cons, #list, #literal?, #pair?, #sig, #sym, #sym?
Methods included from Converter
Constructor Details
#initialize(parent) ⇒ LexicalContext
Returns a new instance of LexicalContext.
7 8 9 |
# File 'lib/nydp/lexical_context.rb', line 7 def initialize parent @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mname, *args) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/nydp/lexical_context.rb', line 30 def method_missing mname, *args if mname.to_s =~ /at_\d+=/ instance_variable_set :"@#{mname.to_s.sub(/=/, '')}", args[0] elsif mname.to_s =~ /at_\d+/ instance_variable_get :"@#{mname}" else super end end |
Instance Attribute Details
#at_0 ⇒ Object
Returns the value of attribute at_0.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_0 @at_0 end |
#at_1 ⇒ Object
Returns the value of attribute at_1.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_1 @at_1 end |
#at_2 ⇒ Object
Returns the value of attribute at_2.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_2 @at_2 end |
#at_3 ⇒ Object
Returns the value of attribute at_3.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_3 @at_3 end |
#at_4 ⇒ Object
Returns the value of attribute at_4.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_4 @at_4 end |
#at_5 ⇒ Object
Returns the value of attribute at_5.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_5 @at_5 end |
#at_6 ⇒ Object
Returns the value of attribute at_6.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_6 @at_6 end |
#at_7 ⇒ Object
Returns the value of attribute at_7.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_7 @at_7 end |
#at_8 ⇒ Object
Returns the value of attribute at_8.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_8 @at_8 end |
#at_9 ⇒ Object
Returns the value of attribute at_9.
5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 5 def at_9 @at_9 end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lib/nydp/lexical_context.rb', line 4 def parent @parent end |
Instance Method Details
#at_index(index) ⇒ Object
22 23 24 |
# File 'lib/nydp/lexical_context.rb', line 22 def at_index index instance_variable_get :"@at_#{index}" end |
#nth(n) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nydp/lexical_context.rb', line 11 def nth n case n when 0 self when -1 raise "wrong nesting level" else parent.nth(n - 1) end end |
#pretty ⇒ Object
47 48 49 |
# File 'lib/nydp/lexical_context.rb', line 47 def pretty to_s_with_indent '' end |
#set_index(index, value) ⇒ Object
26 27 28 |
# File 'lib/nydp/lexical_context.rb', line 26 def set_index index, value instance_variable_set :"@at_#{index}", value end |
#to_s ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nydp/lexical_context.rb', line 51 def to_s # values = [] # n = 0 # while at_index n # values << at_index(n)._nydp_inspect # n += 1 # end # parent_s = parent ? " parent #{parent.to_s}" : "" # "(context (#{values.join ' '})#{parent_s})" "(NEW context)" end |
#to_s_with_indent(str) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/nydp/lexical_context.rb', line 40 def to_s_with_indent str me = (@values || { }).map { |k, v| [str, k, "=>", v].join ' ' }.join "\n" me + (parent ? parent.to_s_with_indent(" #{str}") : '') end |