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
#initialize(*grammar_files) ⇒ CompileTask
Returns a new instance of CompileTask.
49
50
51
52
53
54
55
56
57
|
# 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
|
Instance Attribute Details
#grammar_sets ⇒ Object
Returns the value of attribute grammar_sets.
39
40
41
|
# File 'lib/antlr3/task.rb', line 39
def grammar_sets
@grammar_sets
end
|
#name ⇒ Object
Returns the value of attribute name.
40
41
42
|
# File 'lib/antlr3/task.rb', line 40
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
39
40
41
|
# File 'lib/antlr3/task.rb', line 39
def options
@options
end
|
Class Method Details
.define(*grammar_files) ⇒ Object
42
43
44
45
46
47
|
# 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
|
Instance Method Details
#clobber! ⇒ Object
90
91
92
|
# File 'lib/antlr3/task.rb', line 90
def clobber!
clobber_task.invoke
end
|
#clobber_task ⇒ Object
85
86
87
88
|
# File 'lib/antlr3/task.rb', line 85
def clobber_task
full_name = ( @namespace + [ @name, 'clobber' ] ).join( ':' )
Rake::Task[ full_name ]
end
|
#compile! ⇒ Object
81
82
83
|
# File 'lib/antlr3/task.rb', line 81
def compile!
compile_task.invoke
end
|
#compile_task ⇒ Object
76
77
78
79
|
# File 'lib/antlr3/task.rb', line 76
def compile_task
full_name = ( @namespace + [ @name, 'compile' ] ).join( ':' )
Rake::Task[ full_name ]
end
|
#define ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# 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) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# 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 ⇒ Object
59
60
61
62
63
|
# File 'lib/antlr3/task.rb', line 59
def target_files
@grammar_sets.inject( [] ) do | list, set |
list.concat( set.target_files )
end
end
|