From a6b423787b9d9df618d89468e2573b4d598f011e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 23 Jan 2012 16:11:11 +0100 Subject: tools/genruby: take care of enum backward references --- tools/genruby.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/genruby.rb b/tools/genruby.rb index 5508981..baca539 100755 --- a/tools/genruby.rb +++ b/tools/genruby.rb @@ -151,7 +151,28 @@ def gen_enums path, indent values = $2.strip typename = $3.strip tsym = set_type typename, typename - args = values.split(',').collect { |cst| ':'+cst.strip.downcase }.join(', ').gsub(/=/,',').gsub(/ ,/,',') + syms, vals = [], [] + values.split(',').each do |define| + s,v = define.gsub(/ /,'').split(/=/) + syms << s + vals << v + end + if vals.count(nil) == vals.length + args = syms.collect{ |sym| ':'+sym.strip.downcase }.join(', ') + else + i=0 + h={} + syms.zip(vals) do |s,v| + sym=':'+s.downcase + if h.has_key? v + h[s]=h[v] + else + h[s]=i + i+=1 + end + end + args = syms.inject(''){|r,s| r+=":#{s.strip.downcase}, #{h[s]}, " } + end r << indent+"# #{typedef} {...} #{typename};" r << wrap_text( indent+"enum #{tsym}, [ #{args} ]", indent+' '*4 ) end -- cgit v1.1-2-g2b99