Class Parslet::Source
In: lib/parslet/source.rb
lib/parslet/source/line_cache.rb
Parent: Object

Wraps the input IO to parslet. The interface defined by this class is smaller than what IO offers, but enhances it with a column and line method for the current position.

Methods

eof?   error   line_and_column   new   pos   pos=   read  

Public Class methods

Public Instance methods

Formats an error cause at the current position or at the position given by pos. If pos is nil, the current source position will be the error position.

Returns a <line, column> tuple for the given position. If no position is given, line/column information is returned for the current position given by pos.

Reads n bytes from the input and returns a Range instance. If the n bytes end in the middle of a multibyte representation of a char, that char is returned fully.

Example:

  source.read(1)  # always returns at least one valid char
  source.read(7)  # reads 7 bytes, then to the next char boundary.

[Validate]