Method: ANTLR3::FileStream#initialize
- Defined in:
- lib/antlr3/streams.rb
#initialize(file, options = {}) ⇒ FileStream
creates a new FileStream object using the given file object. If file is a path string, the file will be read and the contents will be used and the name attribute will be set to the path. If file is an IO-like object (that responds to :read), the content of the object will be used and the stream will attempt to set its name object first trying the method #name on the object, then trying the method #path on the object.
see StringStream.new for a list of additional options the constructer accepts
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/antlr3/streams.rb', line 689 def initialize( file, = {} ) case file when $stdin then data = $stdin.read @name = '(stdin)' when ARGF data = file.read @name = file.path when ::File then file = file.clone file.reopen( file.path, 'r' ) @name = file.path data = file.read file.close else if file.respond_to?( :read ) data = file.read if file.respond_to?( :name ) then @name = file.name elsif file.respond_to?( :path ) then @name = file.path end else @name = file.to_s if test( ?f, @name ) then data = File.read( @name ) else raise ArgumentError, "could not find an existing file at %p" % @name end end end super( data, ) end |