Class: ANTLR3::InteractiveStringStream
- Inherits:
-
StringStream
- Object
- StringStream
- ANTLR3::InteractiveStringStream
- Defined in:
- lib/antlr3/streams/interactive.rb
Overview
A special stream used in the interactive mode of the Main scripts. It uses Readline (if available) or standard IO#gets to fetch data on demand.
Constant Summary
Constant Summary
Constants inherited from StringStream
Constants included from Constants
Constants::BUILT_IN_TOKEN_NAMES, Constants::DEFAULT, Constants::DOWN, Constants::EOF, Constants::EOF_TOKEN, Constants::EOR_TOKEN_TYPE, Constants::HIDDEN, Constants::INVALID_TOKEN, Constants::INVALID_TOKEN_TYPE, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP
Instance Attribute Summary
Attributes inherited from StringStream
#column, #data, #line, #name, #position, #string
Attributes included from CharacterStream
Attributes included from Stream
Instance Method Summary (collapse)
- - (Object) consume
-
- (InteractiveStringStream) initialize(options = {}, &block)
constructor
creates a new StringStream object where data is the string data to stream.
- - (Object) look(i = 1)
- - (Object) peek(i = 1)
- - (Object) substring(start, stop)
Methods inherited from StringStream
#<<, #[], #beginning_of_line?, #beginning_of_string?, #end_of_line?, #end_of_string?, #inspect, #last_marker, #mark, #mark_depth, #release, #reset, #rewind, #seek, #size, #through
Constructor Details
- (InteractiveStringStream) initialize(options = {}, &block)
creates a new StringStream object where data is the string data to stream. accepts the following options in a symbol-to-value hash:
- :file or :name
-
the (file) name to associate with the stream; default: '(string)'
- :line
-
the initial line number; default: 1
- :column
-
the initial column number; default: 0
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/antlr3/streams/interactive.rb', line 24 def initialize( = {}, &block ) @string = @data = '' @position = .fetch :position, 0 @line = .fetch :line, 1 @column = .fetch :column, 0 @markers = [] mark @initialized = @eof = false @readline = block or raise( ArgumentError, "no line-reading block was provided" ) @name ||= [ :file ] || [ :name ] || '(interactive)' end |
Instance Method Details
- (Object) consume
90 91 92 93 94 95 96 |
# File 'lib/antlr3/streams/interactive.rb', line 90 def consume @position < @data.size and return( super ) unless @eof readline consume end end |
- (Object) look(i = 1)
112 113 114 |
# File 'lib/antlr3/streams/interactive.rb', line 112 def look( i = 1 ) peek( i ).chr rescue EOF end |
- (Object) peek(i = 1)
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/antlr3/streams/interactive.rb', line 98 def peek( i = 1 ) i.zero? and return 0 i += 1 if i < 0 index = @position + i - 1 index < 0 and return 0 if index < @data.size char = @data[ index ] elsif readline peek( i ) else EOF end end |
- (Object) substring(start, stop)
116 117 118 119 |
# File 'lib/antlr3/streams/interactive.rb', line 116 def substring( start, stop ) fill_through( stop ) @string[ start .. stop ] end |