class ANTLR3::Test::Grammar::InlineGrammar
Attributes
host_file[RW]
host_line[RW]
Public Class Methods
new( source, options = {} ) { |self| ... }
click to toggle source
# 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
Public Instance Methods
inspect()
click to toggle source
# File lib/antlr3/test/grammar.rb, line 299 def inspect sprintf( 'inline grammar %s (%s:%s)', name, @host_file, @host_line ) end
output_directory()
click to toggle source
# File lib/antlr3/test/grammar.rb, line 289 def output_directory @output_directory and return @output_directory File.basename( @host_file ) end
path=( v )
click to toggle source
# File lib/antlr3/test/grammar.rb, line 294 def path=( v ) previous, @path = @path, v.to_s previous == @path or write_to_disk end
Private Instance Methods
write_to_disk()
click to toggle source
# File lib/antlr3/test/grammar.rb, line 305 def write_to_disk @path ||= output_directory / @name + '.g' test( ?d, output_directory ) or Dir.mkdir( output_directory ) unless test( ?f, @path ) and MD5.digest( @source ) == MD5.digest( File.read( @path ) ) open( @path, 'w' ) { |f| f.write( @source ) } end end