Class: ANTLR3::Template::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr3/template.rb

Constant Summary

VARIABLE_FORM =
/^(@)?[a-z_\x80-\xff][\w\x80-\xff]*$/
SETTER_FORM =
/^([a-z_\x80-\xff][\w\x80-\xff]*)=$/
ATTR_FORM =
/^[a-z_\x80-\xff][\w\x80-\xff]*$/

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Context) initialize(variable_map = nil)

A new instance of Context



266
267
268
269
# File 'lib/antlr3/template.rb', line 266

def initialize( variable_map = nil )
  variable_map and self << variable_map
  block_given? and yield( self )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)



241
242
243
244
245
246
247
248
# File 'lib/antlr3/template.rb', line 241

def method_missing( method, *args )
  case name = method.to_s
  when SETTER_FORM then return( self[ $1 ] = args.first )
  when ATTR_FORM
    args.empty? and has_ivar?( name ) and return( self[ name ] )
  end
  super
end

Class Attribute Details

+ (Object) group

Returns the value of attribute group



217
218
219
# File 'lib/antlr3/template.rb', line 217

def group
  @group
end

+ (Object) name

Returns the value of attribute name



217
218
219
# File 'lib/antlr3/template.rb', line 217

def name
  @name
end

+ (Object) parameters

Returns the value of attribute parameters



217
218
219
# File 'lib/antlr3/template.rb', line 217

def parameters
  @parameters
end

Class Method Details

+ (Object) define(group, name, parameters)



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/antlr3/template.rb', line 228

def define( group, name, parameters )
  Class.new( self ) do
    include( group )
    
    @group = group
    @name  = name
    @parameters = parameters
    
    block_given? and yield( self )
  end
end

+ (Object) define_alias(name)



220
221
222
223
224
225
226
# File 'lib/antlr3/template.rb', line 220

def define_alias( name )
  new = clone
  new.name = name
  new.group = @group
  block_given? and yield( new )
  return( new )
end

Instance Method Details

- (Object) <<(variable_map)



259
260
261
262
263
264
# File 'lib/antlr3/template.rb', line 259

def <<( variable_map )
  variable_map.each_pair do | name, value |
    self[ name ] = value
  end
  return( self )
end

- (Object) [](name)



254
255
256
257
# File 'lib/antlr3/template.rb', line 254

def []( name )
  name = make_ivar( name )
  instance_variable_defined?( name ) ? instance_variable_get( name ) : nil
end

- (Object) []=(name, value)



250
251
252
# File 'lib/antlr3/template.rb', line 250

def []=( name, value )
  instance_variable_set( make_ivar( name ), value )
end