Skip to content

Commit

Permalink
Seriously. stop with all the clever. The ruby parser is fast enough
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Jan 11, 2011
1 parent 5137739 commit ea14370
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions lib/racc/parserfilegenerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ea14370

Please sign in to comment.