Class: RedParse::StackMonkey

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

Overview

generic stuff for parsing any(?) language

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

Returns a new instance of StackMonkey.



73
74
75
76
77
# File 'lib/redparse.rb', line 73

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.



79
80
81
# File 'lib/redparse.rb', line 79

def and_expect_node
  @and_expect_node
end

#exemplarsObject

Returns the value of attribute exemplars.



81
82
83
# File 'lib/redparse.rb', line 81

def exemplars
  @exemplars
end

#first_changed_indexObject (readonly)

Returns the value of attribute first_changed_index.



79
80
81
# File 'lib/redparse.rb', line 79

def first_changed_index
  @first_changed_index
end

#monkey_codeObject (readonly)

Returns the value of attribute monkey_code.



79
80
81
# File 'lib/redparse.rb', line 79

def monkey_code
  @monkey_code
end

#nameObject (readonly)

Returns the value of attribute name.



79
80
81
# File 'lib/redparse.rb', line 79

def name
  @name
end

Class Method Details

._load(str) ⇒ Object



92
93
94
# File 'lib/redparse.rb', line 92

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

Instance Method Details

#[](stack) ⇒ Object



83
84
85
86
# File 'lib/redparse.rb', line 83

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

#_dump(depth) ⇒ Object



88
89
90
# File 'lib/redparse.rb', line 88

def _dump depth
  @name
end

#action2cObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/redparse.rb', line 96

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