Class: ANTLR3::UnicodeStream
- Inherits:
-
StringStream
- Object
- StringStream
- ANTLR3::UnicodeStream
- Defined in:
- lib/antlr3/streams/unicode.rb
Constant Summary
- PACK_MASK =
'U*'.freeze
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) [](start, *args)
identical to String#[].
-
- (UnicodeStream) initialize(data, options = {})
constructor
creates a new StringStream object where data is the string data to stream.
-
- (Object) look(k = 1)
identical to #peek, except it returns the character value as a String.
-
- (Object) substring(start, stop)
return the string slice between position start and stop.
-
- (Object) through(k)
return a substring around the stream cursor at a distance k if k >= 0, return the next k characters if k < 0, return the previous |k| characters.
Methods inherited from StringStream
#<<, #beginning_of_line?, #beginning_of_string?, #consume, #end_of_line?, #end_of_string?, #inspect, #last_marker, #mark, #mark_depth, #peek, #release, #reset, #rewind, #seek, #size
Constructor Details
- (UnicodeStream) initialize(data, options = {})
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
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/antlr3/streams/unicode.rb', line 25 def initialize( data, = {} ) # for 1.8 @string = data.to_s @string.equal?( data ) and @string = @string.clone @string.freeze @data = @string.unpack( PACK_MASK ) @position = .fetch :position, 0 @line = .fetch :line, 1 @column = .fetch :column, 0 @markers = [] @name ||= [ :file ] || [ :name ] # || '(string)' mark end |
Instance Method Details
- (Object) [](start, *args)
identical to String#[]
74 75 76 |
# File 'lib/antlr3/streams/unicode.rb', line 74 def []( start, *args ) @data[ start, *args ].pack( PACK_MASK ) end |
- (Object) look(k = 1)
identical to #peek, except it returns the character value as a String
41 42 43 44 45 46 47 48 49 |
# File 'lib/antlr3/streams/unicode.rb', line 41 def look( k = 1 ) # for 1.8 k == 0 and return nil k += 1 if k < 0 index = @position + k - 1 index.between?( 0, @data.length - 1) or return nil @data[ index, 1 ].pack( PACK_MASK ) end |
- (Object) substring(start, stop)
return the string slice between position start and stop
66 67 68 |
# File 'lib/antlr3/streams/unicode.rb', line 66 def substring( start, stop ) @data[ start, stop - start + 1 ].pack( PACK_MASK ) end |
- (Object) through(k)
return a substring around the stream cursor at a distance k if k >= 0, return the next k characters if k < 0, return the previous |k| characters
56 57 58 59 60 61 |
# File 'lib/antlr3/streams/unicode.rb', line 56 def through( k ) if k >= 0 then @data[ @position, k ].pack( PACK_MASK ) else start = ( @position + k ).at_least( 0 ) # start cannot be negative or index will wrap around @data[ start ... @position ].pack( PACK_MASK ) end end |