# Ragel and ruby

**URL:** <https://www.ruby-forum.com/t/ragel-and-ruby/128560>\
**Category:** Ruby\
**Created:** [February 8, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/ragel-and-ruby/128560 "2008-02-08T21:49:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [February 8, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/ragel-and-ruby/128560/1 "2008-02-08T21:49:45Z")

</div>

Hi,

I’ve been trying to generate ruby with ragel. But the generated code  
is complaing about undefined local variables

Here an excerpt of the generated code:

class MyParser

```
# more generated code here ...

class << self
  attr_accessor :mymachine_start
end

# and here ...

def parse(input)

  # ...

  begin
    cs = mymachine_start
  end

  # ...

end

```

end

If I prepend ‘type.’, which is deprecated, I know, it works for this  
case. But there are other accessor that are being set private, e. g.

attr\_accessor :\_mymachine\_trans\_actions\_wi  
private :\_mymachine\_trans\_actions\_wi, :\_mymachine\_trans\_actions\_wi=

How is this mean to work?

And why isn’t an accessor set at class level not accessible from within  
an instance of this class in the first place?

g phil

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [February 8, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/ragel-and-ruby/128560/2 "2008-02-08T22:41:00Z")

</div>

This is sort of unconsidered, but it might help. In order to get  
Ragel to work for me, I needed to add the following to the code  
definition template:

```
  %%{
    write init;
  }%%
  mark = nil
  data = io.read
  p = 0
  pe = data.length
  stack = []
  top = 0
  %%write exec;

```

If I recall correctly, there’s a way to go the other way: to have  
Ragel generate different code for getting the next character, but it’s  
been a little while and I don’t remember what it is.

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [February 8, 2008, 11:52pm UTC](https://www.ruby-forum.com/t/ragel-and-ruby/128560/3 "2008-02-08T23:52:50Z")

</div>

thanks for your answer, but i had that already. but for reference i  
figured it out: maybe i overread that somewhere, but the generated  
ruby class isn’t meant to be instanciated. calling MyParser.parse  
without instanciation works.

nevertheless the question remains why an accessor set at class level  
isn’t accessible from an instance of the same class.

g phil

---

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [February 9, 2008, 1:50am UTC](https://www.ruby-forum.com/t/ragel-and-ruby/128560/4 "2008-02-09T01:50:44Z")

</div>

On Feb 8, 2008 2:51 PM, Philipp H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nevertheless the question remains why an accessor set at class level  
> isn’t accessible from an instance of the same class.

Well, that’s because it’s a class method. You can reach it as  
“self.class.accessor.”

Judson
