parslet 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +38 -1
- data/README +33 -21
- data/example/deepest_errors.rb +131 -0
- data/example/email_parser.rb +2 -6
- data/example/ignore.rb +2 -2
- data/example/json.rb +0 -3
- data/example/modularity.rb +47 -0
- data/example/nested_errors.rb +132 -0
- data/example/output/deepest_errors.out +54 -0
- data/example/output/modularity.out +0 -0
- data/example/output/nested_errors.out +54 -0
- data/lib/parslet.rb +65 -51
- data/lib/parslet/atoms.rb +1 -1
- data/lib/parslet/atoms/alternative.rb +11 -12
- data/lib/parslet/atoms/base.rb +57 -99
- data/lib/parslet/atoms/can_flatten.rb +9 -4
- data/lib/parslet/atoms/context.rb +26 -4
- data/lib/parslet/atoms/entity.rb +5 -10
- data/lib/parslet/atoms/lookahead.rb +11 -7
- data/lib/parslet/atoms/named.rb +8 -12
- data/lib/parslet/atoms/re.rb +10 -9
- data/lib/parslet/atoms/repetition.rb +23 -24
- data/lib/parslet/atoms/sequence.rb +10 -16
- data/lib/parslet/atoms/str.rb +11 -13
- data/lib/parslet/cause.rb +45 -13
- data/lib/parslet/convenience.rb +6 -6
- data/lib/parslet/error_reporter.rb +7 -0
- data/lib/parslet/error_reporter/deepest.rb +95 -0
- data/lib/parslet/error_reporter/tree.rb +57 -0
- data/lib/parslet/export.rb +4 -4
- data/lib/parslet/expression.rb +0 -2
- data/lib/parslet/expression/treetop.rb +2 -2
- data/lib/parslet/parser.rb +2 -6
- data/lib/parslet/pattern.rb +15 -4
- data/lib/parslet/pattern/binding.rb +3 -3
- data/lib/parslet/rig/rspec.rb +2 -2
- data/lib/parslet/slice.rb +0 -6
- data/lib/parslet/source.rb +40 -59
- data/lib/parslet/source/line_cache.rb +2 -2
- data/lib/parslet/transform.rb +13 -7
- data/lib/parslet/transform/context.rb +1 -1
- metadata +69 -26
- data/example/ignore_whitespace.rb +0 -66
- data/lib/parslet/bytecode.rb +0 -6
- data/lib/parslet/bytecode/compiler.rb +0 -138
- data/lib/parslet/bytecode/instructions.rb +0 -358
- data/lib/parslet/bytecode/vm.rb +0 -209
- data/lib/parslet/error_tree.rb +0 -50
data/lib/parslet/error_tree.rb
DELETED
@@ -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
|