Class: Trenni::StringScanner
- Inherits:
-
StringScanner
- Object
- StringScanner
- Trenni::StringScanner
show all
- Defined in:
- lib/trenni/scanner.rb
Constant Summary
collapse
- STUCK_MESSAGE =
"Parser is stuck!".freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StringScanner.
108
109
110
111
112
|
# File 'lib/trenni/scanner.rb', line 108
def initialize(buffer)
@buffer = buffer
super(buffer.read)
end
|
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
114
115
116
|
# File 'lib/trenni/scanner.rb', line 114
def buffer
@buffer
end
|
Instance Method Details
#parse_error!(message, positions = nil) ⇒ Object
132
133
134
135
136
|
# File 'lib/trenni/scanner.rb', line 132
def parse_error!(message, positions = nil)
positions ||= [self.pos]
raise ParseError.new(message, self, positions)
end
|
#path ⇒ Object
116
117
118
|
# File 'lib/trenni/scanner.rb', line 116
def path
@buffer.path
end
|
#raise_if_stuck(position, message = STUCK_MESSAGE) ⇒ Object
126
127
128
129
130
|
# File 'lib/trenni/scanner.rb', line 126
def raise_if_stuck(position, message = STUCK_MESSAGE)
if stuck?(position)
parse_error!(message)
end
end
|
#stuck?(position) ⇒ Boolean
122
123
124
|
# File 'lib/trenni/scanner.rb', line 122
def stuck?(position)
self.pos == position
end
|