Class: Antlr4ruby::CodePointCharStream Abstract
- Inherits:
-
Object
- Object
- Antlr4ruby::CodePointCharStream
- Defined in:
- lib/antlr4ruby/code_point_char_stream.rb
Overview
This class is abstract.
Class Method Summary collapse
- .from_buffer(code_point_buffer, name = UNKNOWN_SOURCE_NAME) ⇒ Object
- .from_string(input, name = UNKNOWN_SOURCE_NAME) ⇒ Object
Instance Method Summary collapse
- #consume ⇒ Object
- #get_source_name ⇒ Object
- #get_text(interval) ⇒ Object
- #index ⇒ Object
-
#initialize(data, name = UNKNOWN_SOURCE_NAME) ⇒ CodePointCharStream
constructor
A new instance of CodePointCharStream.
- #la(i) ⇒ Object
- #mark ⇒ Object
- #release(marker) ⇒ Object
- #seek(index) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data, name = UNKNOWN_SOURCE_NAME) ⇒ CodePointCharStream
Returns a new instance of CodePointCharStream.
7 8 9 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 7 def initialize(data, name = UNKNOWN_SOURCE_NAME) @data, @name, @position = data, name, 0 end |
Class Method Details
.from_buffer(code_point_buffer, name = UNKNOWN_SOURCE_NAME) ⇒ Object
24 25 26 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 24 def self.from_buffer(code_point_buffer, name = UNKNOWN_SOURCE_NAME) # todo end |
.from_string(input, name = UNKNOWN_SOURCE_NAME) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 28 def self.from_string(input, name = UNKNOWN_SOURCE_NAME) buffer = input.unpack('U*') # input.each_char do |c| # buffer.push(c.ord) # end # 这里会有一个警告,但是不好处理 CodePointCharStream.new(buffer, name) end |
Instance Method Details
#consume ⇒ Object
37 38 39 40 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 37 def consume raise "can not consume eof." if @position == @data.length @position += 1 end |
#get_source_name ⇒ Object
78 79 80 81 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 78 def get_source_name UNKNOWN_SOURCE_NAME if !@name || name.empty? @name end |
#get_text(interval) ⇒ Object
72 73 74 75 76 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 72 def get_text(interval) hold = data[interval] return hold.pack('U*') if hold 'error in method get_text' end |
#index ⇒ Object
42 43 44 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 42 def index @position end |
#la(i) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 60 def la(i) if i < 0 offset = position + i offset < 0 ? IntStream.EOF : data[offset] elsif i > 0 offset = position + i - 1 offset > data.length ? IntStream.EOF : data[offset] else 0 end end |
#mark ⇒ Object
50 51 52 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 50 def mark -1 end |
#release(marker) ⇒ Object
54 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 54 def release(marker) end |
#seek(index) ⇒ Object
56 57 58 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 56 def seek(index) @position = index end |
#size ⇒ Object
46 47 48 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 46 def size @data.length end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/antlr4ruby/code_point_char_stream.rb', line 83 def to_s data.pack('U*') end |