class ANTLR3::CompileTask
A rake task-generating utility concerning ANTLR grammar file compilation. This is a general utility – the grammars do not have to be targetted for Ruby output; it handles all known ANTLR language targets.
require 'antlr3/task' ANTLR3::CompileTask.define( :name => 'grammars', :output_directory => 'lib/parsers' ) do | t | t.grammar_set( 'antlr/MainParser.g', 'antlr/MainTree.g' ) t.grammar_set( 'antlr/Template.g' ) do | gram | gram.output_directory = 'lib/parsers/template' gram.debug = true end end
TODO: finish documentation
Attributes
grammar_sets[R]
name[RW]
options[R]
Public Class Methods
define( *grammar_files ) { |lib| ... }
click to toggle source
# File lib/antlr3/task.rb, line 42 def self.define( *grammar_files ) lib = new( *grammar_files ) block_given? and yield( lib ) lib.define return( lib ) end
new( *grammar_files )
click to toggle source
# File lib/antlr3/task.rb, line 49 def initialize( *grammar_files ) grammar_files = [ grammar_files ].flatten! options = Hash === grammar_files.last ? grammar_files.pop : {} @grammar_sets = [] @name = options.fetch( :name, 'antlr-grammars' ) @options = options @namespace = Rake.application.current_scope grammar_files.empty? or grammar_set( grammar_files ) end
Public Instance Methods
clobber!()
click to toggle source
# File lib/antlr3/task.rb, line 90 def clobber! clobber_task.invoke end
clobber_task()
click to toggle source
# File lib/antlr3/task.rb, line 85 def clobber_task full_name = ( @namespace + [ @name, 'clobber' ] ).join( ':' ) Rake::Task[ full_name ] end
compile!()
click to toggle source
# File lib/antlr3/task.rb, line 81 def compile! compile_task.invoke end
compile_task()
click to toggle source
# File lib/antlr3/task.rb, line 76 def compile_task full_name = ( @namespace + [ @name, 'compile' ] ).join( ':' ) Rake::Task[ full_name ] end
define()
click to toggle source
# File lib/antlr3/task.rb, line 94 def define namespace( @name ) do desc( "trash all ANTLR-generated source code" ) task( 'clobber' ) do for set in @grammar_sets set.clean end end for set in @grammar_sets set.define_tasks end desc( "compile ANTLR grammars" ) task( 'compile' => target_files ) end end
grammar_set( *grammar_files ) { |set| ... }
click to toggle source
# File lib/antlr3/task.rb, line 65 def grammar_set( *grammar_files ) grammar_files = [ grammar_files ].flatten! options = @options.merge( Hash === grammar_files.last ? grammar_files.pop : {} ) set = GrammarSet.new( grammar_files, options ) block_given? and yield( set ) @grammar_sets << set return( set ) end
target_files()
click to toggle source
# File lib/antlr3/task.rb, line 59 def target_files @grammar_sets.inject( [] ) do | list, set | list.concat( set.target_files ) end end