Sha256: 560974411f53d3dc95a24c9b7fb3b178cb316b0a24152ff513f8bf1b32eda465

Contents?: true

Size: 732 Bytes

Versions: 3

Compression:

Stored size: 732 Bytes

Contents

class Parslet::Atoms::Base
  
  # 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
  #
  def parse_with_debug str, opts={}
    parse str, opts
  rescue Parslet::UnconsumedInput => error
    puts error
  rescue Parslet::ParseFailed => error
    puts error.cause.ascii_tree
  end

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
ghazel-parslet-1.4.0.2 lib/parslet/convenience.rb
ghazel-parslet-1.4.0.1 lib/parslet/convenience.rb
parslet-1.4.0 lib/parslet/convenience.rb