Class Parslet::Atoms::Base
In: lib/parslet/convenience.rb
lib/parslet/atoms/base.rb
lib/parslet/atoms/visitor.rb
Parent: Object

Base class for all parslets, handles orchestration of calls and implements a lot of the operator and chaining methods.

Also see Parslet::Atoms::DSL chaining parslet atoms together.

Methods

Included Modules

Parslet::Atoms::Precedence Parslet::Atoms::DSL Parslet::Atoms::CanFlatten

Public Class methods

Debug printing - in Treetop syntax.

Public Instance methods

 Calls the #try method of this parslet. Success consumes input, error will
 rewind the input.

 @param source [Parslet::Source] source to read input from

 @param context [Parslet::Atoms::Context] context to use for the parsing

 @param consume_all [Boolean] true if the current parse must consume
   all input by itself.

Returns true if this atom can be cached in the packrat cache. Most parslet atoms are cached, so this always returns true, unless overridden.

Given a string or an IO object, this will attempt a parse of its contents and return a result. If the parse fails, a Parslet::ParseFailed exception will be thrown.

@param io [String, Source] input for the parse process @option options [Parslet::ErrorReporter] :reporter error reporter to use,

  defaults to Parslet::ErrorReporter::Tree

@option options [Boolean] :prefix Should a prefix match be accepted?

  (default: false)

@return [Hash, Array, Parslet::Slice] PORO (Plain old Ruby object) result

  tree

Packages the common idiom

   begin
     tree = parser.parse('something')
   rescue Parslet::ParseFailed => error
     puts parser.cause.ascii_tree
   end

into a convenient method.

Usage:

  require 'parslet'
  require 'parslet/convenience'

  class FooParser < Parslet::Parser
    rule(:foo) { str('foo') }
    root(:foo)
  end

  FooParser.new.parse_with_debug('bar')

@see Parslet::Atoms::Base#parse

Creates a context for parsing and applies the current atom to the input. Returns the parse result.

@return [<Boolean, Object>] Result of the parse. If the first member is

  true, the parse has succeeded.

Override this in your Atoms::Base subclasses to implement parsing behaviour.

[Validate]