Class: YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader Private
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/yard/parser/ruby/legacy/ruby_lex.rb |
Overview
Read an input stream character by character. We allow for unlimited ungetting of characters just read.
We simplify the implementation greatly by reading the entire input into a buffer initially, and then simply traversing it using pointers.
We also have to allow for the here document diversion. This little gem comes about when the lexer encounters a here document. At this point we effectively need to split the input stream into two parts: one to read the body of the here document, the other to read the rest of the input line where the here document was initially encountered. For example, we might have
do_something(<<-A, <<-B) stuff for A stuff for B
When the lexer encounters the <<A, it reads until the end of the line, and keeps it around for later. It then reads the body of the here document. Once complete, it needs to read the rest of the original line, but then skip the here document body.
Class Method Summary
- .new(content) ⇒ BufferedReader constructor Internal use only
Instance Attribute Summary
- #line_num readonly Internal use only
Instance Method Summary
- #column Internal use only
- #divert_read_from(reserve) Internal use only
- #get_read Internal use only
- #getc Internal use only
- #getc_already_read Internal use only
- #peek(at) Internal use only
- #peek_equal(str) Internal use only
- #ungetc(_ch) Internal use only
Instance Attribute Details
#line_num (readonly)
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 344
attr_reader :line_num
Instance Method Details
#column
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 365
def column @offset - @last_newline end
#divert_read_from(reserve)
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 419
def divert_read_from(reserve) @content[@offset, 0] = reserve @size = @content.size end
#get_read
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 400
def get_read res = @content[@read_back_offset...@offset] @read_back_offset = @offset res end
#getc
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 369
def getc return nil if @offset >= @size ch = @content[@offset, 1] @offset += 1 @hwm = @offset if @hwm < @offset if @newline_pending @line_num += 1 @last_newline = @offset - 1 @newline_pending = false end if ch == "\n" @newline_pending = true end ch end
#getc_already_read
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 388
def getc_already_read getc end
#peek(at)
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 406
def peek(at) pos = @offset + at if pos >= @size nil else @content[pos, 1] end end
#peek_equal(str)
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 415
def peek_equal(str) @content[@offset, str.length] == str end
#ungetc(_ch)
[ GitHub ]# File 'lib/yard/parser/ruby/legacy/ruby_lex.rb', line 392
def ungetc(_ch) raise "unget past beginning of file" if @offset <= 0 @offset -= 1 if @content[@offset] == ?\n @newline_pending = false end end