Class: Trenni::StringScanner

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/trenni/scanner.rb

Direct Known Subclasses

Parser, Template::Scanner

Constant Summary collapse

STUCK_MESSAGE =
"Parser is stuck!".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ StringScanner

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

#bufferObject (readonly)

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

Raises:


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

#pathObject


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

Returns:

  • (Boolean)

122
123
124
# File 'lib/trenni/scanner.rb', line 122

def stuck?(position)
	self.pos == position
end