Subject: bug#22241: 25.0.50; etags Ruby parser problems

From: Eli Zaretskii <[email-masked]>
Date: Sat, 23 Jan 2016 20:59:00 +0200

> Cc: [email-masked]
> From: Dmitry Gutov <[email-masked]>
> Date: Sat, 23 Jan 2016 21:23:57 +0300
> 
> On 01/23/2016 07:38 PM, Eli Zaretskii wrote:
> 
> > I don't speak Ruby.  So please give a more detailed spec for the
> > features you want added.  I wrote some questions below, but I'm quite
> > sure there are more questions I should ask, but don't know about.  So
> > please provide as complete specification for each feature as you
> > possibly can, TIA.
> 
> There's no actual up-to-date language spec, and when in doubt, I fire up 
> the REPL and try things out (and forget many of the results afterwards). 
> So there's no "detailed spec" in my head. Let me just try my best 
> answering your questions, for now.

Thanks.  I have a couple of follow-ups.

> >> - Constants are not indexed.
> >
> > What is the full syntax of a "constant"?  Is it just
> >
> >    IDENTIFIER "=" INTEGER-NUMBER
> 
> Pretty much. IDENTIFIER should be ALL_CAPS, or CamelCase, with 
> underscores allowed.
> 
> INTEGER-NUMBER should be just EXPRESSION, because it can be any 
> expression, possibly a multiline one.

So I guess I will leave constants out for now: etags has no notion of
expressions.

> >> - "class << self" blocks are given a separate entry.
> >
> > What should be done instead?  Can't a class be named "<<"?
> 
> A class cannot be named "<<". You should not add that line to the index, 
> but record that the method definitions inside the following scope are 
> defined on the current class or module.

Is the telltale part "<<" or "self" (or both)?  If it's "<<", then are
there other such tokens that "invalidate" a class?

> > How to know when a module's or a class's scope ends?  Is it enough to
> > count "end" lines?
> 
> Hmm, maybe? I'm guessing etags doesn't really handle heredoc syntax, or 
> multiline strings defined with percent literals (examples here: 
> https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#.22Here_document.22_notation)
> 
> The result shouldn't be too bad if you do that, anyway. Except:
> 
> > Can I assume that "end" will always appear by
> > itself on a line?
> 
> Unfortunately, no. It can also be on the same line, after a semicolon 
> (or on any other line, I suppose, but nobody writes Ruby like that). 
> Examples:
> 
> class SpecialError < StandardError; end
> 
> or
> 
> class MyStruct < Struct.new(:a, :b, :c); end

Looks complicated, but I will look into this.  I hope no identifier
can be named "end", as in

  def foo
    bar = end
  end

?

> >> A
> >> A::B
> >> A::B::ABC
> >> A::B#foo!
> >> A::B.bar?
> >> A::B.qux=
> >
> > Why did 'foo!' get a '#' instead of a '.', as for '_bar'?
> 
> It's common to use '#' in the qualified names of instance methods

What part of the source makes 'foo!' an instance method?

> > Why did 'bar' and 'tee' git a '=' appended?
> 
> Because 'attr_writer :bar' effectively expands to
> 
> def bar=(val)
>    @bar = val
> end
> 
> and 'attr_accessor :tee' expands into
> 
> def tee
>    @tee
> end
> 
> def tee=(val)
>    @tee = val
> end

So you are saying that attr_writer and attr_accessor cause the '=' to
be appended?

Thanks.