Feature #4985

Add %S[] support for making a list of symbols

Added by Aaron Patterson almost 4 years ago. Updated almost 3 years ago.

[ruby-core:37840]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada

Description

I would like to add %S, which would create a list of symbols.

For example:

%S[foo bar] # => [:foo, :bar]

I've attached a patch which implements this along with ripper events and tests. Thanks to Josh Susser for thinking of this. :-)

qsymbols.patch Magnifier - symbol patch (5.82 KB) Aaron Patterson, 07/07/2011 01:00 PM

qsymbols.patch Magnifier - correctly indented patch (5.76 KB) Aaron Patterson, 07/07/2011 01:02 PM

percent_i.patch Magnifier - percent i and percent I (7.2 KB) Aaron Patterson, 08/04/2011 09:26 AM

feature4985.pdf (261 KB) Aaron Patterson, 07/01/2012 04:27 AM

noname (500 Bytes) Anonymous, 07/02/2012 11:29 PM

noname (500 Bytes) Anonymous, 07/02/2012 11:29 PM

4985.patch Magnifier - updated patch to fix conflicts and tests (7.69 KB) Aaron Patterson, 07/24/2012 08:44 AM

Associated revisions

Revision 36524
Added by tenderlove almost 3 years ago

  • parse.y: added symbols and qsymbols productions for %i and %I
    support. %i{ .. } returns a list of symbols without interpolation,
    %I{ .. } returns a list of symbols with interpolation. Thanks to
    Josh Susser for inspiration of this feature. [Feature #4985]

  • ext/ripper/eventids2.c: added ripper events for %i and %I.

  • test/ripper/test_parser_events.rb: ripper tests

  • test/ripper/test_scanner_events.rb: ditto

  • test/ruby/test_array.rb: test for %i and %I behavior

Revision 36524
Added by tenderlove almost 3 years ago

  • parse.y: added symbols and qsymbols productions for %i and %I
    support. %i{ .. } returns a list of symbols without interpolation,
    %I{ .. } returns a list of symbols with interpolation. Thanks to
    Josh Susser for inspiration of this feature. [Feature #4985]

  • ext/ripper/eventids2.c: added ripper events for %i and %I.

  • test/ripper/test_parser_events.rb: ripper tests

  • test/ripper/test_scanner_events.rb: ditto

  • test/ruby/test_array.rb: test for %i and %I behavior

History

#1 Updated by Aaron Patterson almost 4 years ago

Adding a new patch with correct indentation for parse.y

#2 Updated by Joel VanderWerf almost 4 years ago

Wondering idly if the following could be parsed...

:[foo bar]

Eh, maybe it's too inconsistent with % notation anyway.

#3 Updated by Yukihiro Matsumoto almost 4 years ago

Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.

matz.

#4 Updated by Nobuyoshi Nakada almost 4 years ago

Hi,

At Thu, 7 Jul 2011 16:15:36 +0900,
Joel VanderWerf wrote in :

Wondering idly if the following could be parsed...

:[foo bar]

It would be possible, but conflicts with :.

--
Nobu Nakada

#5 Updated by Aaron Patterson almost 4 years ago

On Thu, Jul 07, 2011 at 04:48:51PM +0900, Yukihiro Matsumoto wrote:

Issue #4985 has been updated by Yukihiro Matsumoto.

Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.

Ya. We already have %s, so %S might be confusing (especially when
compared to %w and %W). I don't care about the prefix so much as I care
about having the feature. :-)

--
Aaron Patterson
http://tenderlovemaking.com/

#6 Updated by Aaron Patterson almost 4 years ago

On Thu, Jul 07, 2011 at 04:48:51PM +0900, Yukihiro Matsumoto wrote:

Issue #4985 has been updated by Yukihiro Matsumoto.

Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.

How about %i and %I? (i stands for "intern").

--
Aaron Patterson
http://tenderlovemaking.com/

#7 Updated by Aaron Patterson almost 4 years ago

  • File deleted (noname)

#8 Updated by Aaron Patterson almost 4 years ago

  • File deleted (noname)

#9 Updated by Rodrigo Rosenfeld Rosas almost 4 years ago

How about "%:(symbol1 symbol2)"?

#10 Updated by Nobuyoshi Nakada almost 4 years ago

Hi,

At Fri, 8 Jul 2011 02:36:50 +0900,
Rodrigo Rosenfeld Rosas wrote in :

How about "%:(symbol1 symbol2)"?

$ ruby -e 'p %:(:'
"("

Already ":" manages hard works. Don't overload anymore.

--
Nobu Nakada

#11 Updated by Aaron Patterson almost 4 years ago

I've updated my patch to implement %i and %I. They have the same semantics as %w and %W (one with interpolation, one without).

What do you think of this matz?

#12 Updated by Aaron Patterson almost 4 years ago

Bump

#13 Updated by Shyouhei Urabe over 3 years ago

  • Status changed from Open to Assigned

#14 Updated by Aaron Patterson about 3 years ago

adding a slide

#15 Updated by Rodrigo Rosenfeld Rosas about 3 years ago

I don't understand why your pdfs have a second weird slide :)

#16 Updated by Yusuke Endoh about 3 years ago

Received. Thank you!

The second page is mysterious... A cat or something walked a straight line of your keyboard? :-)

Yusuke Endoh mame@tsg.ne.jp

#17 Updated by Koichi Sasada about 3 years ago

I guessed that %S(...) is S-expr syntax.

example:
%S((foo bar (baz boo)) #=> [:foo, :bar, [:baz, :boo]]

(I have no idea about use-case of this S-expr literal, except Lisp like DSL)

--
// SASADA Koichi at atdot dot net

#18 Updated by Anonymous about 3 years ago

On Mon, Jul 02, 2012 at 02:17:12AM +0900, mame (Yusuke Endoh) wrote:

Issue #4985 has been updated by mame (Yusuke Endoh).

Received. Thank you!

The second page is mysterious... A cat or something walked a straight line of your keyboard? :-)

Quit likely. Sorry about the second page. ;-)

--
Aaron Patterson
http://tenderlovemaking.com/

#19 Updated by Anonymous about 3 years ago

On Mon, Jul 02, 2012 at 06:45:38AM +0900, SASADA Koichi wrote:

I guessed that %S(...) is S-expr syntax.

example:
%S((foo bar (baz boo)) #=> [:foo, :bar, [:baz, :boo]]

(I have no idea about use-case of this S-expr literal, except Lisp like DSL)

My patch (and slide) actually uses %i and %I ("i" stands for "intern")
and mirrors %w and %W. %s is already taken :-)

--
Aaron Patterson
http://tenderlovemaking.com/

#20 Updated by Clay Trump about 3 years ago

+1, I'd use that a lot.

Do we need two versions? Why not always interpolate? Can't see who's going
to need a symbol with a litteral #{ or \whatever in it.

This way we could have only %S and it always interpolates.
--

#21 Updated by Nobuyoshi Nakada almost 3 years ago

=begin
The latest ((%percent_i.patch%)) seems almost fine, except for a conflict in ((%parse.y%)).
=end

#22 Updated by Nobuyoshi Nakada almost 3 years ago

=begin
Seems like ((%ext/ripper/eventids2.c%)) misses (({tSYMBOLS_BEG})).
=end

#23 Updated by Yusuke Endoh almost 3 years ago

  • Assignee changed from Yukihiro Matsumoto to Nobuyoshi Nakada

Aaron Patterson,

I'm happy to inform you that matz has accepted your proposal.

Matz was worried about the letter `i' and searching other ones,
but finally accepted.

Nakada-san,

Could you review the patch attached?

Yusuke Endoh mame@tsg.ne.jp

#24 Updated by Aaron Patterson almost 3 years ago

I've attached an updated patch that includes the correct symbols, fixes the ripper tests, and fixes the conflicts.

Nakada-san: if you're happy with this patch, I can apply. :)

#25 Updated by Nobuyoshi Nakada almost 3 years ago

Seems fine to me.

#26 Updated by Aaron Patterson almost 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r36524.
Aaron, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • parse.y: added symbols and qsymbols productions for %i and %I
    support. %i{ .. } returns a list of symbols without interpolation,
    %I{ .. } returns a list of symbols with interpolation. Thanks to
    Josh Susser for inspiration of this feature. [Feature #4985]

  • ext/ripper/eventids2.c: added ripper events for %i and %I.

  • test/ripper/test_parser_events.rb: ripper tests

  • test/ripper/test_scanner_events.rb: ditto

  • test/ruby/test_array.rb: test for %i and %I behavior

Also available in: Atom PDF