Class: EDN::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/edn/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse_prefix(str, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/edn/parser.rb', line 7

def parse_prefix(str, options={})
  source = Parslet::Source.new(str.to_s)
  success, value = setup_and_apply(source, nil)

  unless success
    reporter = options[:reporter] || Parslet::ErrorReporter::Tree.new
    success, value = setup_and_apply(source, reporter)

    fail "Assertion failed: success was true when parsing with reporter" if success
    value.raise
  end

  rest = nil
  if !source.eof?
    rest = source.consume(source.chars_left).to_s
  end

  return [flatten(value), rest]
end