Class: Antlr4::Runtime::CodePointCharStream

Inherits:
CharStream show all
Defined in:
lib/antlr4/runtime/code_point_char_stream.rb

Constant Summary

Constants inherited from IntStream

IntStream::EOF, IntStream::UNKNOWN_SOURCE_NAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, remaining, name, byte_array) ⇒ CodePointCharStream

Returns a new instance of CodePointCharStream



6
7
8
9
10
11
# 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

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size



63
64
65
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 63

def size
  @size
end

Instance Method Details

#consumeObject



53
54
55
56
57
# 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

#indexObject



59
60
61
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 59

def index
  @position
end

#internal_storageObject



49
50
51
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 49

def internal_storage
  @byte_array
end

#la(i) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

#markObject



65
66
67
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 65

def mark
  -1
end

#release(marker) ⇒ Object



69
70
71
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 69

def release(marker)
  ;
end

#seek(index) ⇒ Object



73
74
75
# File 'lib/antlr4/runtime/code_point_char_stream.rb', line 73

def seek(index)
  @position = index
end

#source_nameObject



77
78
79
80
81
# 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) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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