class ANTLR3::UnicodeStream
Constants
- PACK_MASK
Public Class Methods
new( data, options = {} )
click to toggle source
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
# File lib/antlr3/streams/unicode.rb, line 25 def initialize( data, options = {} ) # for 1.8 @string = data.to_s @string.equal?( data ) and @string = @string.clone @string.freeze @data = @string.unpack( PACK_MASK ) @position = options.fetch :position, 0 @line = options.fetch :line, 1 @column = options.fetch :column, 0 @markers = [] @name ||= options[ :file ] || options[ :name ] # || '(string)' mark end
Public Instance Methods
[]( start, *args )
click to toggle source
identical to String#[]
# File lib/antlr3/streams/unicode.rb, line 74 def []( start, *args ) @data[ start, *args ].pack( PACK_MASK ) end
look( k = 1 )
click to toggle source
substring( start, stop )
click to toggle source
return the string slice between position start
and stop
# File lib/antlr3/streams/unicode.rb, line 66 def substring( start, stop ) @data[ start, stop - start + 1 ].pack( PACK_MASK ) end
through( k )
click to toggle source
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
# 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