Class: RedParse::StackMonkey

Inherits:
Object
  • Object
show all
Defined in:
lib/redparse.rb

Overview

include Nodes

Direct Known Subclasses

DeleteMonkey

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, first_changed_index, and_expect_node, options = {}, &monkey_code) ⇒ StackMonkey



46
47
48
49
50
# File 'lib/redparse.rb', line 46

def initialize(name,first_changed_index,and_expect_node,options={},&monkey_code)
  first_changed_index=-first_changed_index if first_changed_index>0
  @name,@first_changed_index,@and_expect_node,@monkey_code=
    name,first_changed_index,and_expect_node,monkey_code
end

Instance Attribute Details

#and_expect_nodeObject (readonly) Also known as: hint

Returns the value of attribute and_expect_node.



52
53
54
# File 'lib/redparse.rb', line 52

def and_expect_node
  @and_expect_node
end

#exemplarsObject

Returns the value of attribute exemplars.



54
55
56
# File 'lib/redparse.rb', line 54

def exemplars
  @exemplars
end

#first_changed_indexObject (readonly)

Returns the value of attribute first_changed_index.



52
53
54
# File 'lib/redparse.rb', line 52

def first_changed_index
  @first_changed_index
end

#monkey_codeObject (readonly)

Returns the value of attribute monkey_code.



52
53
54
# File 'lib/redparse.rb', line 52

def monkey_code
  @monkey_code
end

#nameObject (readonly)

Returns the value of attribute name.



52
53
54
# File 'lib/redparse.rb', line 52

def name
  @name
end

Class Method Details

._load(str) ⇒ Object



65
66
67
# File 'lib/redparse.rb', line 65

def self._load str
  Thread.current[:$RedParse_parser].undumpables[@name]
end

Instance Method Details

#[](stack) ⇒ Object



56
57
58
59
# File 'lib/redparse.rb', line 56

def [](stack)
  result=@monkey_code[stack]
  return result
end

#_dump(depth) ⇒ Object



61
62
63
# File 'lib/redparse.rb', line 61

def _dump depth
  @name
end

#action2cObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/redparse.rb', line 69

def action2c
  #"return the whole thing on first call, just a goto stmt after that"
  return "    goto #@goto_label;\n" if defined? @goto_label

=begin
  <<-E
  #{@[email protected](/[^a-z0-9_]/,'_')}:
    monkey=rb_hash_get(undumpables,rb_cstr2str("#@name"));
    rb_funcall(monkey,rb_intern("[]"),huh_stack);

    /*recover from stackmonkey fiddling*/
    for(i=0;i<#{-@first_changed_index};++i) {
      rb_ary_unshift(lexer_moretokens,
        rb_ary_pop(huh_semantic_stack));
      rb_ary_pop(huh_syntax_stack);
    }

    goto #{Node===@and_expect_node ? 
             postreduceaction4this_state(@and_expect_node) : 
             shiftaction4this_state
    };
  E
=end
end