Class: RPrec::Stream Abstract
- Inherits:
-
Object
- Object
- RPrec::Stream
- Defined in:
- lib/rprec/stream.rb
Overview
This class is abstract.
current
, next
and eof?
must be implemented.
Stream
is a token stream.
Direct Known Subclasses
Instance Method Summary collapse
- #current ⇒ RPrec::Token
- #eof? ⇒ Boolean
- #expected(tokens) ⇒ void
-
#initialize ⇒ Stream
constructor
A new instance of Stream.
- #next ⇒ void
- #unexpected ⇒ void
Constructor Details
#initialize ⇒ Stream
Returns a new instance of Stream.
8 9 10 |
# File 'lib/rprec/stream.rb', line 8 def initialize @expected = [] end |
Instance Method Details
#current ⇒ RPrec::Token
13 14 15 |
# File 'lib/rprec/stream.rb', line 13 def current raise ScriptError, 'Not implemented' end |
#eof? ⇒ Boolean
23 24 25 |
# File 'lib/rprec/stream.rb', line 23 def eof? raise ScriptError, 'Not implemented' end |
#expected(tokens) ⇒ void
This method returns an undefined value.
29 30 31 |
# File 'lib/rprec/stream.rb', line 29 def expected(tokens) @expected += tokens end |
#next ⇒ void
This method returns an undefined value.
18 19 20 |
# File 'lib/rprec/stream.rb', line 18 def next @expected = [] end |
#unexpected ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 40 |
# File 'lib/rprec/stream.rb', line 34 def unexpected token = current raise ParseError.new("Unexpected token '#{token.type}'", loc: token.loc) if @expected.empty? expected = @expected.sort.map { |tok| "'#{tok}'" }.join(', ') raise ParseError.new("Expected token(s) #{expected}, but the unexpected token '#{token.type}' comes", loc: token.loc) end |