parslet 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/HISTORY.txt +38 -1
  2. data/README +33 -21
  3. data/example/deepest_errors.rb +131 -0
  4. data/example/email_parser.rb +2 -6
  5. data/example/ignore.rb +2 -2
  6. data/example/json.rb +0 -3
  7. data/example/modularity.rb +47 -0
  8. data/example/nested_errors.rb +132 -0
  9. data/example/output/deepest_errors.out +54 -0
  10. data/example/output/modularity.out +0 -0
  11. data/example/output/nested_errors.out +54 -0
  12. data/lib/parslet.rb +65 -51
  13. data/lib/parslet/atoms.rb +1 -1
  14. data/lib/parslet/atoms/alternative.rb +11 -12
  15. data/lib/parslet/atoms/base.rb +57 -99
  16. data/lib/parslet/atoms/can_flatten.rb +9 -4
  17. data/lib/parslet/atoms/context.rb +26 -4
  18. data/lib/parslet/atoms/entity.rb +5 -10
  19. data/lib/parslet/atoms/lookahead.rb +11 -7
  20. data/lib/parslet/atoms/named.rb +8 -12
  21. data/lib/parslet/atoms/re.rb +10 -9
  22. data/lib/parslet/atoms/repetition.rb +23 -24
  23. data/lib/parslet/atoms/sequence.rb +10 -16
  24. data/lib/parslet/atoms/str.rb +11 -13
  25. data/lib/parslet/cause.rb +45 -13
  26. data/lib/parslet/convenience.rb +6 -6
  27. data/lib/parslet/error_reporter.rb +7 -0
  28. data/lib/parslet/error_reporter/deepest.rb +95 -0
  29. data/lib/parslet/error_reporter/tree.rb +57 -0
  30. data/lib/parslet/export.rb +4 -4
  31. data/lib/parslet/expression.rb +0 -2
  32. data/lib/parslet/expression/treetop.rb +2 -2
  33. data/lib/parslet/parser.rb +2 -6
  34. data/lib/parslet/pattern.rb +15 -4
  35. data/lib/parslet/pattern/binding.rb +3 -3
  36. data/lib/parslet/rig/rspec.rb +2 -2
  37. data/lib/parslet/slice.rb +0 -6
  38. data/lib/parslet/source.rb +40 -59
  39. data/lib/parslet/source/line_cache.rb +2 -2
  40. data/lib/parslet/transform.rb +13 -7
  41. data/lib/parslet/transform/context.rb +1 -1
  42. metadata +69 -26
  43. data/example/ignore_whitespace.rb +0 -66
  44. data/lib/parslet/bytecode.rb +0 -6
  45. data/lib/parslet/bytecode/compiler.rb +0 -138
  46. data/lib/parslet/bytecode/instructions.rb +0 -358
  47. data/lib/parslet/bytecode/vm.rb +0 -209
  48. data/lib/parslet/error_tree.rb +0 -50
@@ -1,50 +0,0 @@
1
-
2
- # A tree structure that contains parse error messages. This can be used to
3
- # give the user a detailed report on what went wrong during a parse.
4
- #
5
- class Parslet::ErrorTree
6
- # The parslet that caused the error stored here.
7
- attr_reader :parslet
8
- # All errors that were encountered when parsing part of this +parslet+.
9
- attr_reader :children
10
-
11
- def initialize(parslet, *children) # :nodoc:
12
- @parslet = parslet
13
- @children = children.compact
14
- end
15
-
16
- def nodes
17
- 1 + children.inject(0) { |sum, node| sum + node.nodes }
18
- end
19
-
20
- def cause
21
- parslet.cause || "Unknown error in #{parslet.inspect}"
22
- end
23
-
24
- # Returns an ascii tree representation of the causes of this node and its
25
- # children.
26
- #
27
- def ascii_tree
28
- StringIO.new.tap { |io|
29
- recursive_ascii_tree(self, io, [true]) }.
30
- string
31
- end
32
- alias to_s ascii_tree
33
- private
34
- def recursive_ascii_tree(node, stream, curved) # :nodoc:
35
- append_prefix(stream, curved)
36
- stream.puts node.cause
37
-
38
- node.children.each do |child|
39
- last_child = (node.children.last == child)
40
-
41
- recursive_ascii_tree(child, stream, curved + [last_child])
42
- end
43
- end
44
- def append_prefix(stream, curved) # :nodoc:
45
- curved[0..-2].each do |c|
46
- stream.print c ? " " : "| "
47
- end
48
- stream.print curved.last ? "`- " : "|- "
49
- end
50
- end