Class: ANTLR3::CompileTask::GrammarFile

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/antlr3/task.rb

Direct Known Subclasses

Imported

Defined Under Namespace

Classes: FormatError, Imported

Constant Summary collapse

LANGUAGES =
{ 
  "ActionScript" => [ ".as" ],
  "CSharp2" => [ ".cs" ],
  "C" => [ ".c", ".h" ],
  "ObjC" => [ ".m", ".h" ],
  "CSharp3" => [ ".cs" ],
  "Cpp" => [ ".cpp", ".h" ],
  "Ruby" => [ ".rb" ],
  "Java" => [ ".java" ],
  "JavaScript" => [ ".js" ],
  "Python" => [ ".py" ],
  "Delphi" => [ ".pas" ],
  "Perl5" => [ ".pm" ]
}.freeze
GRAMMAR_TYPES =
%w(lexer parser tree combined)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, path, options = {}) {|_self| ... } ⇒ GrammarFile

CONSTRUCTOR #############################################

Yields:

  • (_self)

Yield Parameters:


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/antlr3/task.rb', line 259

def initialize( group, path, options = {} )
  @group = group
  @path = path.to_s
  @imports = []
  @language = 'Java'
  @token_vocab = nil
  @tasks_defined = false
  @extra_dependencies = []
  if extra = options[ :extra_dependencies ]
    extra = [ extra ].flatten
    @extra_dependencies.concat( extra )
  end
  
  study
  yield( self ) if block_given?
  fetch_imports
end

Instance Attribute Details

#groupObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def group
  @group
end

#imported_grammarsObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def imported_grammars
  @imported_grammars
end

#importsObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def imports
  @imports
end

#languageObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def language
  @language
end

#nameObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def name
  @name
end

#pathObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def path
  @path
end

#sourceObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def source
  @source
end

#token_vocabObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def token_vocab
  @token_vocab
end

#typeObject (readonly)

ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################


280
281
282
# File 'lib/antlr3/task.rb', line 280

def type
  @type
end

Instance Method Details

#all_imported_filesObject


356
357
358
359
360
361
362
# File 'lib/antlr3/task.rb', line 356

def all_imported_files
  imported_files = []
  for grammar in @imported_grammars
    imported_files.push( grammar.path, *grammar.all_imported_files )
  end
  return imported_files
end

#cleanObject


364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/antlr3/task.rb', line 364

def clean
  deleted = []
  for target in target_files
    if test( ?f, target )
      rm( target )
      deleted << target
    end
  end
  
  for grammar in @imported_grammars
    deleted.concat( grammar.clean )
  end
  
  return deleted
end

#define_tasks(shared_depends) ⇒ Object


380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/antlr3/task.rb', line 380

def define_tasks( shared_depends )
  unless @tasks_defined
    depends = [ @path, *all_imported_files ]
    for f in depends
      file( f )
    end
    depends = shared_depends + depends
    
    target_files.each do | target |
      file( target => ( depends - [ target ] ) ) do   # prevents recursive .tokens file dependencies
        @group.compile( self )
      end
    end
    
    @tasks_defined = true
  end
end

#delegate_files(delegate_suffix) ⇒ Object


326
327
328
# File 'lib/antlr3/task.rb', line 326

def delegate_files( delegate_suffix )
  file_names( "#{ name }_#{ delegate_suffix }" )
end

#file_names(base) ⇒ Object


312
313
314
315
316
# File 'lib/antlr3/task.rb', line 312

def file_names( base )
  LANGUAGES.fetch( @language ).map do | ext |
    File.join( output_directory, base + ext )
  end
end

#lexer_filesObject


292
293
294
295
296
297
298
# File 'lib/antlr3/task.rb', line 292

def lexer_files
  if lexer? then base = @name
  elsif combined? then base = @name + 'Lexer'
  else return( [] )
  end
  return( file_names( base ) )
end

#parser_filesObject


300
301
302
303
304
305
306
# File 'lib/antlr3/task.rb', line 300

def parser_files
  if parser? then base = @name
  elsif combined? then base = @name + 'Parser'
  else return( [] )
  end
  return( file_names( base ) )
end

#target_files(all = true) ⇒ Object


334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/antlr3/task.rb', line 334

def target_files( all = true )
  targets = [ tokens_file ]
  
  for target_type in %w( lexer parser tree_parser )
    for file in self.send( :"#{ target_type }_files" )
      targets << file
    end
  end
  
  if all
    for grammar in @imported_grammars
      targets.concat( grammar.target_files )
    end
  end
  
  return targets
end

#tokens_fileObject


330
331
332
# File 'lib/antlr3/task.rb', line 330

def tokens_file
  File.join( output_directory, name + '.tokens' )
end

#tree_parser_filesObject


308
309
310
# File 'lib/antlr3/task.rb', line 308

def tree_parser_files
  return( tree? ? file_names( @name ) : [] )
end

#updateObject


352
353
354
# File 'lib/antlr3/task.rb', line 352

def update
  touch( @path )
end