Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Specifying extension has odd precedence #20

Closed
glenjamin opened this Issue · 3 comments

2 participants

@glenjamin

After digging around for a while, I discovered that this is actually documented, but I don't see why it would be implemented this way; the following rule:

rule a
  b c d { ruby_code}
end
rule d
  'd'
end

attaches the extension to the instance of d used in the a rule, rather than to the a rule as I would have expected.

@mjackson
Owner

I'm not sure why the order of precedence is so strange in this case. If you were writing Ruby code, the block would bind tighter to the d than it would to any preceding symbols, unless you also used parentheses to change the order of precedence. My thinking in making the binding of extensions higher than that of sequences was to make it as similar to Ruby as possible.

@glenjamin

While that does make sense, I can't see any case where it's useful (or neat) to bind a callback to one specific expression of a rule.

In the above fragment, it's far neater to put the block in the definition of d.

@mjackson
Owner

I agree that it's a bit messy to put the block on the end of a line with multiple nested method calls, but that's how Ruby works. I'd prefer to keep it that way to conform to the principle of least surprise.

@mjackson mjackson closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.