Parent

Files

Parslet::Source

Wraps the input string for parslet.

Attributes

pos[RW]

Position of the parse as a character offset into the original string. @note: Encodings...

Public Class Methods

new(str) click to toggle source
# File lib/parslet/source.rb, line 10
def initialize(str)
  raise ArgumentError unless str.respond_to?(:to_str)

  @pos = 0
  @str = str
  
  @line_cache = LineCache.new
  @line_cache.scan_for_line_endings(0, @str)
end

Public Instance Methods

chars_left() click to toggle source

Returns how many chars remain in the input.

# File lib/parslet/source.rb, line 46
def chars_left
  @str.size - @pos
end
consume(n) click to toggle source

Consumes n characters from the input, returning them as a slice of the input.

# File lib/parslet/source.rb, line 33
def consume(n)
  slice_str = @str.slice(@pos, n)
  slice = Parslet::Slice.new(
    slice_str, 
    pos,
    @line_cache)
  
  @pos += slice_str.size
  return slice
end
eof?() click to toggle source
# File lib/parslet/source.rb, line 50
def eof?
  @pos >= @str.size
end
line_and_column(position=nil) click to toggle source

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.

# File lib/parslet/source.rb, line 62
def line_and_column(position=nil)
  @line_cache.line_and_column(position || self.pos)
end
match(pattern) click to toggle source
Alias for: matches?
matches?(pattern) click to toggle source

Checks if the given pattern matches at the current input position.

@param pattern [Regexp, String] pattern to check for @return [Boolean] true if the pattern matches at pos

# File lib/parslet/source.rb, line 25
def matches?(pattern)
  @str.index(pattern, @pos) == @pos
end
Also aliased as: match

[Validate]

Generated with the Darkfish Rdoc Generator 2.