class RewriteValuesToAst

FIXME: NOT NEEDED

Public Class Methods

rewrite(input,output) click to toggle source
# File src/rewrite/rewrite_values_to_ast.rb, line 7
def self.rewrite(input,output)
  self.new.rewrite(input,output)
end

Public Instance Methods

rewrite(input,output) click to toggle source

input should be in the form: 'thingtthingtformulan' where the last field is always a forumla output will be in the form 'thingtthingtastn' FIXME: Removes newlines and other unprintables from str types. Should actually process them.

# File src/rewrite/rewrite_values_to_ast.rb, line 14
def rewrite(input,output)
  input.each_line do |line|
    line =~ /^(.*?)\t(.*?)\t(.*)\n/
    ref, type, value = $1, $2, $3
    ast = case type
    when 'b'; value == "1" ? [:boolean_true] : [:boolean_false]
    when 's'; [:shared_string,value]
    when 'n'; [:number,value]
    when 'e'; [:error,value]
    when 'str'; [:string,value.gsub(/_x[0-9A-F]{4}_/,'')]
    else
      $stderr.puts "Type #{type} not known in #{line}"
      [:parse_error,line.inspect]
    end
    output.puts "#{ref}\t#{ast}"
  end
end