From: Michael Edgar Date: 2011-09-01T12:41:05+09:00 Subject: Re: ripper on array access operation --Apple-Mail=_689A4C49-BC80-4FC8-9904-8188E90DA21B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Aug 31, 2011, at 7:00 PM, justincollins@ucla.edu wrote: > Quoting "Surya G." : >=20 >> unknown wrote in post #1019486: >>> Quoting "Surya G." : >>>=20 >>> I am pretty sure it's the :aref part. Ripper is making [] a special >>> case. >>>=20 >>> -Justin >>=20 >> Thats what it looks like but why not treat aref as any-other method >> call. >>=20 >> -- >> Posted via http://www.ruby-forum.com/. Aref is parsed differently from other method calls. Ripper delivers a = parse tree, and by providing aref as a different AST node, a program = consuming the parse tree can distinguish between a.[](1, 2) and a[1,2]. = There are plenty of reasons (such as pretty-printing) that these two = should not be conflated. >=20 > I don't know. Ripper's output looks like a mess to me when compared to = RubyParser: >=20 > s(:call, s(:call, nil, :a, s(:arglist)), :[], s(:arglist, s(:lit, 1))) >=20 > -Justin >=20 That's because RubyParser doesn't provide an abstract syntax tree, it = provides a tree interpretation of Ruby programs. While Ripper comes = close to a concrete syntax tree at times, at least it sticks to syntax. = t discuss my choice of Ripper over RubyParser in my undergraduate thesis = [0]; while it is perhaps suitable for an interpreter, its output = discards so much of the syntax. It even inserts nodes which have nothing = to do with syntax and everything to do with semantics. In this example, = if I want my static analyzer to find examples of a.[](1), I can't using = RubyParser (at least with the default settings). It adds :scope nodes which don't have anything to do with the syntax, it = evaluates constant literals, from integers to regular expressions, which = is not the job of a general-purpose AST. It even inserts a local = assignment node when it parses "rescue Foo =3D> x" (x =3D $!). RubyParser is a good library, and its value as a pure-ruby parser cannot = be understated. It's not suitable for many uses because of the shortcuts = it takes, the over-interpretation it does (this aref example is a clear = one), and the overall focus on semantics and not on just *parsing*. [0] PDF: = http://www.cs.dartmouth.edu/cms_file/SYS_techReport/532/TR2011-686.pdf= --Apple-Mail=_689A4C49-BC80-4FC8-9904-8188E90DA21B--