class Antlr4::Runtime::CodePointCharStream

Attributes

size[R]

Public Class Methods

new(position, remaining, name, byte_array) click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 6
def initialize(position, remaining, name, byte_array)
  @size = remaining
  @name = name
  @position = position
  @byte_array = byte_array
end

Public Instance Methods

consume() click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 53
def consume
  raise IllegalStateException, 'cannot consume EOF' if (@size - @position).zero?

  @position += 1
end
index() click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 59
def index
  @position
end
internal_storage() click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 49
def internal_storage
  @byte_array
end
la(i) click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 28
def la(i)
  case Integer.signum(i)
  when -1
    offset = @position + i
    return IntStream::EOF if offset < 0

    return @byte_array[offset] & 0xFF
  when 0
    # Undefined
    return 0
  when 1
    offset = @position + i - 1
    return IntStream::EOF if offset >= @size

    return @byte_array[offset] & 0xFF
  else
    # type code here
  end
  raise UnsupportedOperationException, 'Not reached'
end
mark() click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 65
def mark
  -1
end
release(marker) click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 69
def release(marker)
  ;
end
seek(index) click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 73
def seek(index)
  @position = index
end
source_name() click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 77
def source_name
  return UNKNOWN_SOURCE_NAME if @name.nil? || @name.empty?

  @name
end
text(interval) click to toggle source
# File lib/antlr4/runtime/code_point_char_stream.rb, line 13
def text(interval)
  start_idx = [interval.a, @size].min
  len = [interval.b - interval.a + 1, @size - start_idx].min

  # We know the maximum code point in byte_array is U+00FF,
  # so we can treat this as if it were ISO-8859-1, aka Latin-1,
  # which shares the same code points up to 0xFF.
  chars = @byte_array.slice(start_idx, len)
  result = ''
  chars.each do |c|
    result << c
  end
  result
end