Re: trying to understand irb: why does it have its own lexer, instead of forwarding input to ruby ?



As mentioned before, I want to extend the ruby language.
Specifically, I want to twist the interpreter so that it expands
for instance w8s6ny into w[8].s[6].y.size(). Do you experts
think this can be achieved by modifying IRB's ruby code,
without diving into Ruby's C code?

It depends on what rules should guide the translation. Here's a
simplistic example:

irb(main):003:0> "w8s6ny".scan(/../).map do |m|
irb(main):004:1* case m
irb(main):005:2> when /(\w)(\d)/
irb(main):006:2> then "#$1[#$2]"
irb(main):007:2> when /n(\w)/
irb(main):008:2> then "#$1.size()"
irb(main):009:2> else
irb(main):010:2* m
irb(main):011:2> end
irb(main):012:1> end.join "."
=> "w[8].s[6].y.size()"

This is a two-pass solution: first expand whatever I defined on top of
Ruby, then hand the result down to IRB. Worth thinking about. My
original intention was a one-pass solution: extended-IRB should
recognise w8 in the very same way as IRB recognises w[8].

Thanks again, Joachim

.