Class: RPrec::RegexpStream Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
RegexpStream
is a stream generated by a RegexpLexer
.
Instance Attribute Summary collapse
- #current ⇒ RPrec::Token readonly private
Instance Method Summary collapse
- #eof? ⇒ Boolean private
-
#initialize(lexer, source) ⇒ RegexpStream
constructor
private
A new instance of RegexpStream.
- #next ⇒ void private
Methods inherited from Stream
Constructor Details
#initialize(lexer, source) ⇒ RegexpStream
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RegexpStream.
39 40 41 42 43 44 45 |
# File 'lib/rprec/regexp_lexer.rb', line 39 def initialize(lexer, source) super() @lexer = lexer @source = source @offset = 0 self.next end |
Instance Attribute Details
#current ⇒ RPrec::Token (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/rprec/regexp_lexer.rb', line 48 def current @current end |
Instance Method Details
#eof? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/rprec/regexp_lexer.rb', line 78 def eof? @source.size <= @offset end |
#next ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rprec/regexp_lexer.rb', line 51 def next super skip = @source.match(@lexer.skip, @offset) @offset += skip.to_s.size if skip if eof? @current = Token.new('EOF', loc: @offset...@offset) return end match = @source.match(@lexer.pattern, @offset) raise ParseError.new("Unexpected character: #{@source[@offset].inspect}", loc: @offset...@offset + 1) unless match type_and_value = @lexer.block.call(match) type, value = if type_and_value.is_a?(Array) [type_and_value[0], type_and_value[1]] else [type_and_value, nil] end loc = @offset...@offset + match.to_s.size @offset += match.to_s.size @current = Token.new(type, value, loc:) end |