Class: ANTLR3::CompileTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- ANTLR3::CompileTask
show all
- Defined in:
- lib/antlr3/task.rb
Overview
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
Defined Under Namespace
Classes: GrammarFile, GrammarSet
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Constructor Details
- (CompileTask) initialize(*grammar_files)
A new instance of CompileTask
48
49
50
51
52
53
54
55
56
|
# File 'lib/antlr3/task.rb', line 48
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
|
Instance Attribute Details
- (Object) grammar_sets
Returns the value of attribute grammar_sets
38
39
40
|
# File 'lib/antlr3/task.rb', line 38
def grammar_sets
@grammar_sets
end
|
- (Object) name
Returns the value of attribute name
39
40
41
|
# File 'lib/antlr3/task.rb', line 39
def name
@name
end
|
- (Object) options
Returns the value of attribute options
38
39
40
|
# File 'lib/antlr3/task.rb', line 38
def options
@options
end
|
Class Method Details
+ (Object) define(*grammar_files)
41
42
43
44
45
46
|
# File 'lib/antlr3/task.rb', line 41
def self.define( *grammar_files )
lib = new( *grammar_files )
block_given? and yield( lib )
lib.define
return( lib )
end
|
Instance Method Details
- (Object) clobber!
89
90
91
|
# File 'lib/antlr3/task.rb', line 89
def clobber!
clobber_task.invoke
end
|
- (Object) clobber_task
84
85
86
87
|
# File 'lib/antlr3/task.rb', line 84
def clobber_task
full_name = ( @namespace + [ @name, 'clobber' ] ).join( ':' )
Rake::Task[ full_name ]
end
|
- (Object) compile!
80
81
82
|
# File 'lib/antlr3/task.rb', line 80
def compile!
compile_task.invoke
end
|
- (Object) compile_task
75
76
77
78
|
# File 'lib/antlr3/task.rb', line 75
def compile_task
full_name = ( @namespace + [ @name, 'compile' ] ).join( ':' )
Rake::Task[ full_name ]
end
|
- (Object) define
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/antlr3/task.rb', line 93
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
|
- (Object) grammar_set(*grammar_files)
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/antlr3/task.rb', line 64
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
|
- (Object) target_files
58
59
60
61
62
|
# File 'lib/antlr3/task.rb', line 58
def target_files
@grammar_sets.inject( [] ) do | list, set |
list.concat( set.target_files )
end
end
|