1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#!/usr/bin/ruby
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvermodule ANTLR3
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvermodule Template
5324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverParameter = Struct.new( :name, :default )
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverclass Parameter
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  def to_s
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    if block then "&#{ name }"
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    elsif splat then "*#{ name }"
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    elsif default then "#{ name } = #{ default }"
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    else name.dup
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    end
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  end
14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverend
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverclass ParameterList < ::Array
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  attr_accessor :splat, :block
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  def self.default
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    new.add( :values ) do | p |
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      p.default = '{}'
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    end
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  end
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  def names
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    names = map { | param | param.name.to_s }
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    @splat and names << @splat.to_s
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    @block and names << @block.to_s
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return( names )
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  end
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  def add( name, default = nil )
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    param =
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      case name
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      when Parameter then name
36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      else Parameter.new( name.to_s )
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      end
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    if options
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      default = options[ :default ] and param.default = default
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      param.splat = options.fetch( :splat, false )
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver      param.block = options.fetch( :block, false )
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    end
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    block_given? and yield( param )
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    push( param )
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return( self )
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  end
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  def to_s
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    signature = join( ', ' )
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    @splat and signature << ", *" << @splat.to_s
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    @block and signature << ", &" << @block.to_s
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return( signature )
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  end
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverend
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverend
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverend
57