Backport #1183

Adding support for the new hash literal syntax

Added by knu (Akinori MUSHA) over 3 years ago. Updated about 1 year ago.

[ruby-core:22286]
Status:Closed Start date:02/20/2009
Priority:Normal Due date:
Assignee:knu (Akinori MUSHA) % Done:

100%

Category:core
Target version:Ruby 1.8.8

Description

Attached is a patch for ruby_1_8 which adds support for the new literal syntax for hash and hash style arguments.

However, there needs some more work to retain the use of colon in place of then/do, in order to keep backward compatibility, although it has been deprecated and dropped in 1.9.

knu@daemon[1]% ruby-1.8.7 -ve 'if true: p(1); end'
ruby 1.8.7 (2008-11-11 patchlevel 73) [x86_64-freebsd7]
1
knu@daemon[1]% ruby-1.8 -ve 'if true: p(1); end'
ruby 1.8.7p5000 (2009-02-19 revision 22433) [x86_64-freebsd7]
-e:1: syntax error, unexpected tLABEL
if true: p(1); end
        ^
-e:1: syntax error, unexpected kEND, expecting $end

label_hash.patch (4.1 kB) knu (Akinori MUSHA), 02/20/2009 07:17 pm

tLABEL.patch - a patch to implement "label: value" style hash, for 1.8 (4.3 kB) shyouhei (Shyouhei Urabe), 07/23/2009 03:49 am

Associated revisions

Revision 24338
Added by shyouhei almost 3 years ago

* parse.y: Support for { key: value } -style hash immediates. [ruby-core:21946][ruby-core:22286] * keywords: ditto.

History

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

Hi,

At Fri, 20 Feb 2009 19:17:10 +0900,
Akinori MUSHA wrote in [ruby-core:22286]:
> However, there needs some more work to retain the use of
> colon in place of then/do, in order to keep backward
> compatibility, although it has been deprecated and dropped in
> 1.9.

No such syntax has been defined officially.
No backward compatibility issue.

-- 
Nobu Nakada

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

Nobuyoshi Nakada wrote:
> Hi,
> 
> At Fri, 20 Feb 2009 19:17:10 +0900,
> Akinori MUSHA wrote in [ruby-core:22286]:
>> However, there needs some more work to retain the use of
>> colon in place of then/do, in order to keep backward
>> compatibility, although it has been deprecated and dropped in
>> 1.9.
> 
> No such syntax has been defined officially.
> No backward compatibility issue.

What do you mean here in "official"? because AFAIK there has been no single
line of official syntax definitions so far.

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

Hi,

At Fri, 20 Feb 2009 20:49:35 +0900,
Urabe Shyouhei wrote in [ruby-core:22289]:
> What do you mean here in "official"? because AFAIK there has been no single
> line of official syntax definitions so far.

Matz's book and official tutorial[1] mention about "then" but
not ":".  Is there any description about such colons?

[1] http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html

-- 
Nobu Nakada

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

Nobuyoshi Nakada wrote:
> Hi,
> 
> At Fri, 20 Feb 2009 20:49:35 +0900,
> Urabe Shyouhei wrote in [ruby-core:22289]:
>> What do you mean here in "official"? because AFAIK there has been no single
>> line of official syntax definitions so far.
> 
> Matz's book and official tutorial[1] mention about "then" but
> not ":".  Is there any description about such colons?

At least O'Reilly's "Programming Language Ruby" has a detailed description
about it.  One of a Matz's book no wonder.

Updated by shyouhei (Shyouhei Urabe) almost 3 years ago

太古のメールに返信する上に-devに振るのですが、これできた気がします。test-allと
かが一応通っていそうです。どんなもんでしょうか。

patchはredmineに貼ってあります。

Akinori MUSHA さんは書きました:
> Backport #1183: Adding support for the new hash literal syntax
> http://redmine.ruby-lang.org/issues/show/1183
> 
> Author: Akinori MUSHA
> Status: Open, Priority: Normal
> Assigned to: Akinori MUSHA, Category: core, Target version: Ruby 1.8.8
> 
> Attached is a patch for ruby_1_8 which adds support for the new literal syntax for hash and hash style arguments.
> 
> However, there needs some more work to retain the use of colon in place of then/do, in order to keep backward compatibility, although it has been deprecated and dropped in 1.9.
> 
> knu@daemon[1]% ruby-1.8.7 -ve 'if true: p(1); end'
> ruby 1.8.7 (2008-11-11 patchlevel 73) [x86_64-freebsd7]
> 1
> knu@daemon[1]% ruby-1.8 -ve 'if true: p(1); end'
> ruby 1.8.7p5000 (2009-02-19 revision 22433) [x86_64-freebsd7]
> -e:1: syntax error, unexpected tLABEL
> if true: p(1); end
>         ^
> -e:1: syntax error, unexpected kEND, expecting $end
> 
> 
> ----------------------------------------
> http://redmine.ruby-lang.org
> 
> 
> 

Updated by shyouhei (Shyouhei Urabe) almost 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r24338.

Updated by shyouhei (Shyouhei Urabe) almost 3 years ago

Shyouhei Urabe さんは書きました:
> Applied in changeset r24338.

とりあえずNEWSは書きましたが、テストはどこに突っ込めばいいんでしょうか...


Attachment: signature.asc

Also available in: Atom PDF