The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
String interpolation in ruby2c

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Hodel

Posts: 660
Nickname: drbrain
Registered: Mar, 2006

Eric Hodel is a long-time Rubyist and co-founder of Seattle.rb.
String interpolation in ruby2c Posted: Mar 6, 2006 8:27 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eric Hodel.
Original Post: String interpolation in ruby2c
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eric Hodel
Latest Posts From Segment7

Advertisement

The toolset zenspider and I built into ParseTree for rewriting Ruby’s AST allows us to make features work that otherwise would be very difficult by rewriting them into easier to implement features.

One feature that makes Ruby so clean is string interpolation but currently ruby2c doesn’t support it. In Ruby there are two types of String nodes, a plain :str node ([:str, "mystring"]) for regular strings and a :dstr node that contains all the parts of the dynamic string which the interpreter concatenates ([:dstr, "val: ", [:vcall, :val]]).

Implementing :dstr in a runtime would be too hard to be worthwhile so I used SexpProcessor to rewrite a :dstr into a series of calls to #<< and #to_s that append to the leading :str node.

Now a dynamic string like:

[:dstr,
 "a",
 [:vcall, :x],
 [:str, "b"],
 [:vcall, :y],
 [:str, "c"]]

Gets transformed into this ugly sexp:

s(:call,
  s(:call,
    s(:call,
      s(:call,
        s(:str, "a"),
          :<<,
          s(:arglist,
            s(:call, s(:call, nil, :x, nil), :to_s, nil))),
        :<<,
        s(:arglist,
          s(:call, s(:str, "b"), :to_s, nil))),
      :<<,
      s(:arglist,
        s(:call, s(:call, nil, :y, nil), :to_s, nil))),
    :<<,
    s(:arglist,
      s(:call, s(:str, "c"), :to_s, nil)))

I don’t know about the inside-outness of it though, I may have to fix that.

Read: String interpolation in ruby2c

Topic: Como hacer público un subdirectorio dentro de un directorio protegido en Apache Previous Topic   Next Topic Topic: Happy Birthday Jason!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use