From: Logan Capaldo Date: 2005-06-10T10:28:03+09:00 Subject: Re: [SUMMARY] Whiteout (#34) On 6/9/05, Ara.T.Howard@noaa.gov wrote: [snip] > a hack but: > > harp:~ > cat fix_my_broken_syntax.rb > src = open($0).read > src.gsub! %r/([_a-z][_a-zA-Z]*)\+\+/, '((\1+=1;\1 - 1))' > eval src > exit > > > harp:~ > cat a.rb > #!/usr/local/bin/ruby -r./fix_my_broken_syntax.rb > n = 41 > p n++ > p n > > > harp:~ > ./a.rb > 41 > 42 > > > cheers. [snip] I have some suggestions for alternate methods. I haven't actually tried any of these yet, so take this with a grain of salt. The more interesting one I think would be to use ParseTree, assuming it allows (or eventually will) allow you to insert a modified parsetree back into the interpreter. You could then traverse the tree and look for items semantically instead of by regexps. There are disadvantages to this of course. You couldn't add new operators and such for instance, although I would imagine it would be good for things like AOP (It also probably would be impossible to implement whiteout using this method). A related option is to write a parser in ruby for ruby that emits ParseTree sexps that can once again be inserted into the interpreter. You could then modify this parser to add whatever syntax constructs you like (new operators etc.) as long as they could be mapped onto existing ruby syntax (since this is the point of source filters usually, I see no problem with that limitation, any more complicated and its just another language written in ruby). The other option to consider is a filter using pipes. Have two files, one with the filterable source (ie written in latin or whitespace or whatever) and another with the regexp based transformer, and wrap it up in a script. eg: $ cat illegible.rb #@#@#@# -- ? : 2 dfsdasdasd $ cat filter.rb #!/usr/bin/env ruby class LineNoise def transform .... end end x = LineNoise.new IO.popen("ruby") do |rb| File.open("illegible.rb") do |ill| ill.each do |line| rb.print x.transform(line) end end end $ This gets rid of the eval nastiness but adds its own nastiness (like, where do I find illegible.rb? etc.). Just some ideas. Of course we could all write our own languages that are just ruby with some syntax differences ;)