Class: ANTLR3::CompileTask::GrammarFile
- Inherits:
-
Object
- Object
- ANTLR3::CompileTask::GrammarFile
- Includes:
- Rake::DSL
- Defined in:
- lib/antlr3/task.rb
Direct Known Subclasses
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
-
#group ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#imported_grammars ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#imports ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#language ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#name ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#path ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#source ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#token_vocab ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
-
#type ⇒ Object
readonly
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################.
Instance Method Summary collapse
- #all_imported_files ⇒ Object
- #clean ⇒ Object
- #define_tasks(shared_depends) ⇒ Object
- #delegate_files(delegate_suffix) ⇒ Object
- #file_names(base) ⇒ Object
-
#initialize(group, path, options = {}) {|_self| ... } ⇒ GrammarFile
constructor
CONSTRUCTOR #############################################.
- #lexer_files ⇒ Object
- #parser_files ⇒ Object
- #target_files(all = true) ⇒ Object
- #tokens_file ⇒ Object
- #tree_parser_files ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(group, path, options = {}) {|_self| ... } ⇒ GrammarFile
CONSTRUCTOR #############################################
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, = {} ) @group = group @path = path.to_s @imports = [] @language = 'Java' @token_vocab = nil @tasks_defined = false @extra_dependencies = [] if extra = [ :extra_dependencies ] extra = [ extra ].flatten @extra_dependencies.concat( extra ) end study yield( self ) if block_given? fetch_imports end |
Instance Attribute Details
#group ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def group @group end |
#imported_grammars ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def imported_grammars @imported_grammars end |
#imports ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def imports @imports end |
#language ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def language @language end |
#name ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def name @name end |
#path ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def path @path end |
#source ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def source @source end |
#token_vocab ⇒ Object (readonly)
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
280 281 282 |
# File 'lib/antlr3/task.rb', line 280 def token_vocab @token_vocab end |
#type ⇒ Object (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_files ⇒ Object
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 |
#clean ⇒ Object
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_files ⇒ Object
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_files ⇒ Object
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_file ⇒ Object
330 331 332 |
# File 'lib/antlr3/task.rb', line 330 def tokens_file File.join( output_directory, name + '.tokens' ) end |
#tree_parser_files ⇒ Object
308 309 310 |
# File 'lib/antlr3/task.rb', line 308 def tree_parser_files return( tree? ? file_names( @name ) : [] ) end |
#update ⇒ Object
352 353 354 |
# File 'lib/antlr3/task.rb', line 352 def update touch( @path ) end |