Class: ANTLR3::Test::Grammar::InlineGrammar

Inherits:
ANTLR3::Test::Grammar show all
Defined in:
lib/antlr3/test/grammar.rb

Overview

class Grammar

Constant Summary

Constants inherited from ANTLR3::Test::Grammar

CLASS_TO_TYPE, GRAMMAR_TYPES, TYPE_TO_CLASS

Constants included from DependantFile

DependantFile::GLOBAL_DEPENDENCIES

Instance Attribute Summary collapse

Attributes inherited from ANTLR3::Test::Grammar

#name, #source, #type, #verbose

Attributes included from DependantFile

#force, #path

Instance Method Summary collapse

Methods inherited from ANTLR3::Test::Grammar

#clean!, #combined?, #compile, #compile!, global_dependency, #has_lexer?, #has_parser?, #imported_target_files, #imports, inline, #lexer?, #lexer_class_name, #lexer_file_name, #parser?, #parser_class_name, #parser_file_name, #target_files, #tree?, #tree_parser_class_name, #tree_parser_file_name

Methods included from DependantFile

#dependencies, #depends_on, #stale?

Constructor Details

#initialize(source, options = {}) {|_self| ... } ⇒ InlineGrammar

Returns a new instance of InlineGrammar.

Yields:

  • (_self)

Yield Parameters:


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/antlr3/test/grammar.rb', line 271

def initialize( source, options = {} )
  host = call_stack.find { |call| call.file != __FILE__ }
  
  @host_file = File.expand_path( options[ :file ] || host.file )
  @host_line = ( options[ :line ] || host.line )
  @output_directory = options.fetch( :output_directory, File.dirname( @host_file ) )
  @verbose = options.fetch( :verbose, $VERBOSE )
  
  @source = source.to_s.fixed_indent( 0 )
  @source.strip!
  
  study
  write_to_disk
  build_dependencies
  
  yield( self ) if block_given?
end

Instance Attribute Details

#host_fileObject

Returns the value of attribute host_file


269
270
271
# File 'lib/antlr3/test/grammar.rb', line 269

def host_file
  @host_file
end

#host_lineObject

Returns the value of attribute host_line


269
270
271
# File 'lib/antlr3/test/grammar.rb', line 269

def host_line
  @host_line
end

Instance Method Details

#inspectObject


299
300
301
# File 'lib/antlr3/test/grammar.rb', line 299

def inspect
  sprintf( 'inline grammar %s (%s:%s)', name, @host_file, @host_line )
end

#output_directoryObject


289
290
291
292
# File 'lib/antlr3/test/grammar.rb', line 289

def output_directory
  @output_directory and return @output_directory
  File.basename( @host_file )
end

#path=(v) ⇒ Object


294
295
296
297
# File 'lib/antlr3/test/grammar.rb', line 294

def path=( v )
  previous, @path = @path, v.to_s
  previous == @path or write_to_disk
end