Permalink
Browse files

Seriously. stop with all the clever. The ruby parser is fast enough

  • Loading branch information...
1 parent 5137739 commit ea143708e8d3563bc5f4aa532fcbe60a717948fc @zenspider zenspider committed Jan 11, 2011
Showing with 2 additions and 51 deletions.
  1. +2 −51 lib/racc/parserfilegenerator.rb
@@ -325,57 +325,8 @@ def state_transition_table
end
def integer_list(name, table)
- if table.size > 2000
- serialize_integer_list_compressed name, table
- else
- serialize_integer_list_std name, table
- end
- end
-
- def serialize_integer_list_compressed(name, table)
- # TODO: this can be made a LOT more clean with a simple split/map
- sep = "\n"
- nsep = ",\n"
- buf = ''
- com = ''
- ncom = ','
- co = com
- @f.print 'clist = ['
- table.each do |i|
- buf << co << i.to_s; co = ncom
- if buf.size > 66
- @f.print sep; sep = nsep
- @f.print "'", buf, "'"
- buf = ''
- co = com
- end
- end
- unless buf.empty?
- @f.print sep
- @f.print "'", buf, "'"
- end
- line ' ]'
-
- @f.print(<<-End)
- #{name} = arr = ::Array.new(#{table.size}, nil)
- idx = 0
- clist.each do |str|
- str.split(',', -1).each do |i|
- arr[idx] = i.to_i unless i.empty?
- idx += 1
- end
- end
- End
- end
-
- def serialize_integer_list_std(name, table)
- sep = ''
- line "#{name} = ["
- table.each_slice(10) do |ns|
- @f.print sep; sep = ",\n"
- @f.print ns.map {|n| sprintf('%6s', n ? n.to_s : 'nil') }.join(',')
- end
- line ' ]'
+ lines = table.inspect.split(/((?:\w+, ){15})/).reject { |s| s.empty? }
+ line "#{name} = #{lines.join("\n")}"
end
def i_i_sym_list(name, table)

0 comments on commit ea14370

Please sign in to comment.