rley 0.3.01 → 0.3.04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -3
- data/Gemfile +1 -1
- data/examples/parsers/parsing_groucho.rb +1 -3
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/parser/gfg_parsing.rb +5 -179
- data/lib/rley/parser/parse_forest_builder.rb +62 -77
- data/lib/rley/parser/parse_walker_factory.rb +26 -17
- data/lib/rley.rb +1 -0
- data/spec/rley/gfg/end_vertex_spec.rb +1 -1
- data/spec/rley/gfg/shortcut_edge_spec.rb +6 -6
- data/spec/rley/gfg/start_vertex_spec.rb +1 -1
- data/spec/rley/parse_forest_visitor_spec.rb +1 -1
- data/spec/rley/parse_tree_visitor_spec.rb +1 -1
- data/spec/rley/parser/gfg_parsing_spec.rb +3 -6
- data/spec/rley/parser/parse_entry_set_spec.rb +19 -19
- data/spec/rley/parser/parse_entry_spec.rb +6 -6
- data/spec/rley/parser/parse_forest_builder_spec.rb +374 -79
- data/spec/rley/parser/parse_forest_factory_spec.rb +1 -1
- data/spec/rley/parser/parse_walker_factory_spec.rb +60 -40
- data/spec/rley/parser/state_set_spec.rb +8 -8
- data/spec/rley/support/grammar_L0_helper.rb +81 -0
- metadata +11 -13
- data/spec/rley/sppf/antecedence_graph.rb +0 -87
- data/spec/rley/sppf/forest_representation.rb +0 -136
- data/spec/rley/sppf/gfg_representation.rb +0 -111
@@ -1,111 +0,0 @@
|
|
1
|
-
# Mix-in module that generates a Graphviz's DOT file
|
2
|
-
# that represents the precedence graph of parse entries.
|
3
|
-
class GFGRepresentation
|
4
|
-
|
5
|
-
def generate_graph(aParsing, aFile)
|
6
|
-
heading = build_heading()
|
7
|
-
aFile.puts(heading)
|
8
|
-
|
9
|
-
fill_graph(aParsing.gf_graph, aFile)
|
10
|
-
|
11
|
-
trailing = build_trailing()
|
12
|
-
aFile.puts(trailing)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def build_heading()
|
18
|
-
text = <<-END_STRING
|
19
|
-
digraph gfg {
|
20
|
-
size="7,9.5";
|
21
|
-
page="8.5,11";
|
22
|
-
ratio = fill;
|
23
|
-
END_STRING
|
24
|
-
|
25
|
-
return text
|
26
|
-
end
|
27
|
-
|
28
|
-
def build_trailing()
|
29
|
-
return '}'
|
30
|
-
end
|
31
|
-
|
32
|
-
def fill_graph(aGFGraph, aFile)
|
33
|
-
all_vertices = aGFGraph.vertices.dup
|
34
|
-
(itemized, endpoints) = all_vertices.partition do |vertex|
|
35
|
-
vertex.is_a?(Rley::GFG::ItemVertex)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Group start/end nodes by non-terminal symbol
|
39
|
-
group_endings = endpoints.group_by { |endpoint| endpoint.non_terminal }
|
40
|
-
|
41
|
-
# Group item vertices by lhs non-terminal symbol
|
42
|
-
group_items = itemized.group_by { |vertex| vertex.lhs }
|
43
|
-
|
44
|
-
aFile.puts ''
|
45
|
-
group_endings.each_pair do |nonterm, nodes|
|
46
|
-
text = <<-END_STRING
|
47
|
-
subgraph cluster_#{nonterm} {
|
48
|
-
color = transparent;
|
49
|
-
END_STRING
|
50
|
-
aFile.puts text
|
51
|
-
aFile.puts ' // Define the start and end nodes'
|
52
|
-
nodes.each do |vertex|
|
53
|
-
# Emit the start/end nodes
|
54
|
-
aFile.puts %Q( node_#{vertex.object_id}[shape=box, fontsize=18.0, label="#{vertex.label}"];)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Create sub-clusters by production
|
58
|
-
subnodes = group_items[nonterm]
|
59
|
-
subclusters = subnodes.group_by { |vertex| vertex.dotted_item.production }
|
60
|
-
subclusters.each_pair do |prod, vertices|
|
61
|
-
aFile.puts ''
|
62
|
-
aFile.puts cluster_heading(prod)
|
63
|
-
vertices.each do |vertex|
|
64
|
-
aFile.puts %Q( node_#{vertex.object_id}[label="#{vertex.label}"];)
|
65
|
-
end
|
66
|
-
aFile.puts cluster_trailing(prod)
|
67
|
-
end
|
68
|
-
aFile.puts ' }'
|
69
|
-
end
|
70
|
-
|
71
|
-
aFile.puts ''
|
72
|
-
aFile.puts ' // Draw the edges'
|
73
|
-
aGFGraph.vertices.each do |from_vertex|
|
74
|
-
from_vertex.edges.each do |anEdge|
|
75
|
-
if from_vertex.is_a?(Rley::GFG::EndVertex)
|
76
|
-
to_dotted_item = anEdge.successor.dotted_item
|
77
|
-
label = "RET_#{to_dotted_item.production.object_id}_#{to_dotted_item.prev_position}"
|
78
|
-
aFile.puts " node_#{from_vertex.object_id}->node_#{anEdge.successor.object_id}[color=red, style=dashed, arrowhead=onormal,label=#{label}];"
|
79
|
-
else
|
80
|
-
if anEdge.is_a?(Rley::GFG::ScanEdge)
|
81
|
-
aFile.puts %Q( node_#{from_vertex.object_id}->node_#{anEdge.successor.object_id}[fontsize=18.0, label="#{anEdge.terminal}"];)
|
82
|
-
else
|
83
|
-
if anEdge.successor.is_a?(Rley::GFG::StartVertex)
|
84
|
-
from_dotted_item = from_vertex.dotted_item
|
85
|
-
label = "CALL_#{from_dotted_item.production.object_id}_#{from_dotted_item.position}"
|
86
|
-
aFile.puts " node_#{from_vertex.object_id}->node_#{anEdge.successor.object_id}[color=green, label=#{label}];"
|
87
|
-
else
|
88
|
-
aFile.puts " node_#{from_vertex.object_id}->node_#{anEdge.successor.object_id};"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
def cluster_heading(anObject)
|
98
|
-
text = <<-END_STRING
|
99
|
-
subgraph cluster_#{anObject.object_id} {
|
100
|
-
style = rounded;
|
101
|
-
color = blue;
|
102
|
-
END_STRING
|
103
|
-
|
104
|
-
return text
|
105
|
-
end
|
106
|
-
|
107
|
-
def cluster_trailing(anObject)
|
108
|
-
return ' }'
|
109
|
-
end
|
110
|
-
|
111
|
-
end # module
|