Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble flattening lists #16

Open
dbarowy opened this issue Feb 5, 2011 · 1 comment
Open

Trouble flattening lists #16

dbarowy opened this issue Feb 5, 2011 · 1 comment

Comments

@dbarowy
Copy link

dbarowy commented Feb 5, 2011

Hi Michael,

Any idea how to do list flattening in a straightforward way with nested rules? If I use the construct below with the input "foo1 foo2 foo3" and then call the value method on my tree, I get "Stack level too deep". Seems that Things will call the morethings method on itself instead of on the matched substring. This appears to be a bug, but maybe I've missed something here...

I can make it work if I add a second rule so that the two rules alternate, but it sure does make the grammar file ugly!

Many thanks,
Dan

grammar SampleGrammar
rule ROOT
(things:Things WS* EOF)
{
def value
list = []
list += things.value
return list
end
}
end

rule Things
    (thing:THING WS* (morethings:Things)?)
    {
        def value
            list = []
            list << thing.value
            list += morethings.value unless morethings.nil?
            return list
        end
    }
end

rule THING
    [a-zA-Z0-9]+
end

rule EOF
    !.
end

rule WS
    [\s\t\r\n\f] 
end

end

@rogerbraun
Copy link

It works if you do it like this:

list += morethings.matches.first.value unless morethings.matches.first.nil?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants