Class: ANTLR3::Template::Context

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

Constant Summary collapse

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

#initialize(variable_map = nil) ⇒ Context


281
282
283
284
# File 'lib/antlr3/template.rb', line 281

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

#method_missing(method, *args) ⇒ Object


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

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

.groupObject

Returns the value of attribute group


232
233
234
# File 'lib/antlr3/template.rb', line 232

def group
  @group
end

.nameObject

Returns the value of attribute name


232
233
234
# File 'lib/antlr3/template.rb', line 232

def name
  @name
end

.parametersObject

Returns the value of attribute parameters


232
233
234
# File 'lib/antlr3/template.rb', line 232

def parameters
  @parameters
end

Class Method Details

.define(group, name, parameters) ⇒ Object


243
244
245
246
247
248
249
250
251
252
253
# File 'lib/antlr3/template.rb', line 243

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

.define_alias(name) ⇒ Object


235
236
237
238
239
240
241
# File 'lib/antlr3/template.rb', line 235

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

Instance Method Details

#<<(variable_map) ⇒ Object


274
275
276
277
278
279
# File 'lib/antlr3/template.rb', line 274

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

#[](name) ⇒ Object


269
270
271
272
# File 'lib/antlr3/template.rb', line 269

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

#[]=(name, value) ⇒ Object


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

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