# Re: Subclassing Struct.new

**URL:** <https://www.ruby-forum.com/t/re-subclassing-struct-new/75354>\
**Category:** Ruby\
**Created:** [March 1, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/re-subclassing-struct-new/75354 "2006-03-01T19:40:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 1, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/re-subclassing-struct-new/75354/1 "2006-03-01T19:40:59Z")

</div>

Quoting Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> |Will the Ruby2.0 grammar no longer have variable/method  
> ambiguities?
> 
> I’m not sure what you meant by “ambiguities”. The identifiers  
> not assigned in the scope will be treated as method calls, as  
> well as in current behavior.

When speaking of grammar, “ambiguity” refers to situations where the  
same text can parse to more than one tree – for example:

foo[1] # (call (lvar foo) [] (array 1))  
foo [1] # (call (lvar foo) [] (array 1))

versus:

foo[1] # (call (fcall foo (array)) [] (array 1))  
foo [1] # (fcall foo (array (array 1)))

There may be disambiguating factors (e.g. whether ‘foo’ is known a  
priori to be an lvar or a method), but those are external to the  
grammar.

Rather than making the grammar itself ambiguous, it would be better  
to introduce a new ‘lvar-or-fcall’ production parse the above  
expressions unconditionally as:

foo[1] # (call (lvar-or-fcall foo) [] (array 1))  
foo [1] # (fcall foo (array (array 1)))

This way, it would be possible to write an unambiguous context-free  
grammar for Ruby (heredocs and so forth aside).

Also, it would help users confused about whether “foo [1]” parses as  
a method call or a variable access, since “foo 1” always parses as a  
method call.

You’d still be free to backpatch the lvar-or-fcall node to an lvar  
or fcall if you wanted to do so, but it wouldn’t complicate the  
grammar any longer.

Please don’t make Ruby even harder to parse…

-mental
