rley 0.5.03 → 0.5.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 +4 -0
- data/examples/data_formats/JSON/json_ast_builder.rb +11 -11
- data/examples/general/calc_iter1/calc_ast_builder.rb +11 -11
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/gfg/grm_flow_graph.rb +36 -14
- data/lib/rley/syntax/grammar.rb +3 -3
- data/spec/rley/gfg/grm_flow_graph_spec.rb +1 -0
- data/spec/rley/parser/ast_builder_spec.rb +6 -6
- data/spec/rley/syntax/grammar_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5c84e4d5e47e769c76da705abef632e4748311c
|
4
|
+
data.tar.gz: 876569a22741aa76f5d9b7bec8404c0a518e02b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da13f9f5924752adc98be8822f079e078ff4e5345a1cbf63dcd3f6d0c28c695397abf4f80db6fa38e549615cb1db264baadcb4b3fdc1428ef45ac3aa490459cf
|
7
|
+
data.tar.gz: 84b73e987ffb98f5ce5cf1a57f62a743507bff497c8c8c3294e887310036ba9893796ec5f3b9d1d8f2335b7c33bb47cda3e6455e7f66ce0dfcb3c85b90e629a4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.5.04 / 2017-10-26
|
2
|
+
* [Fix] Method GrmFlowGraph#traverse_df code terminated prematurely with nested call edges.
|
3
|
+
* [CHANGE] Method Grammar#name_production: suffix in default production name is changed (e.g. 'expression[3]' changed to expression_3)
|
4
|
+
|
1
5
|
### 0.5.03 / 2017-10-09
|
2
6
|
* [CHANGE] Refactoring code style to please Rubocop 0.50.0
|
3
7
|
* [CHANGE] File `.rubocop.yml`: Disabling heredoc cop because it produces false negatives
|
@@ -52,37 +52,37 @@ class JSONASTBuilder < Rley::Parser::ParseTreeBuilder
|
|
52
52
|
# @param theChildren [Array] Children nodes (one per rhs symbol)
|
53
53
|
def new_parent_node(aProduction, aRange, theTokens, theChildren)
|
54
54
|
node = case aProduction.name
|
55
|
-
when 'JSON-
|
55
|
+
when 'JSON-text_0' # rule 'JSON-text' => 'value'
|
56
56
|
return_first_child(aRange, theTokens, theChildren)
|
57
57
|
|
58
|
-
when /
|
58
|
+
when /value_\d/
|
59
59
|
return_first_child(aRange, theTokens, theChildren)
|
60
60
|
|
61
|
-
when '
|
61
|
+
when 'object_0'
|
62
62
|
reduce_object_0(aProduction, aRange, theTokens, theChildren)
|
63
63
|
|
64
|
-
when '
|
64
|
+
when 'object_1'
|
65
65
|
reduce_object_1(aRange, theTokens, theChildren)
|
66
66
|
|
67
|
-
when 'member-
|
67
|
+
when 'member-list_0'
|
68
68
|
reduce_member_list_0(aRange, theTokens, theChildren)
|
69
69
|
|
70
|
-
when 'member-
|
70
|
+
when 'member-list_1'
|
71
71
|
reduce_member_list_1(aProduction, aRange, theTokens, theChildren)
|
72
72
|
|
73
|
-
when '
|
73
|
+
when 'member_0'
|
74
74
|
reduce_member_0(aProduction, aRange, theTokens, theChildren)
|
75
75
|
|
76
|
-
when '
|
76
|
+
when 'array_0'
|
77
77
|
reduce_array_0(aProduction, aRange, theTokens, theChildren)
|
78
78
|
|
79
|
-
when '
|
79
|
+
when 'array_1'
|
80
80
|
reduce_array_1(aRange, theTokens, theChildren)
|
81
81
|
|
82
|
-
when 'array-
|
82
|
+
when 'array-items_0'
|
83
83
|
reduce_array_items_0(aRange, theTokens, theChildren)
|
84
84
|
|
85
|
-
when 'array-
|
85
|
+
when 'array-items_1'
|
86
86
|
reduce_array_items_1(aProduction, aRange, theTokens, theChildren)
|
87
87
|
else
|
88
88
|
raise StandardError, "Don't know production #{aProduction.name}"
|
@@ -58,38 +58,38 @@ class CalcASTBuilder < Rley::Parser::ParseTreeBuilder
|
|
58
58
|
# @param theChildren [Array] Children nodes (one per rhs symbol)
|
59
59
|
def new_parent_node(aProduction, aRange, theTokens, theChildren)
|
60
60
|
node = case aProduction.name
|
61
|
-
when '
|
61
|
+
when 'expression_0' # rule 'expression' => 'simple_expression'
|
62
62
|
return_first_child(aRange, theTokens, theChildren)
|
63
63
|
|
64
|
-
when '
|
64
|
+
when 'simple_expression_0' # rule 'simple_expression' => 'term'
|
65
65
|
return_first_child(aRange, theTokens, theChildren)
|
66
66
|
|
67
|
-
when '
|
67
|
+
when 'simple_expression_1'
|
68
68
|
# rule 'simple_expression' => %w[simple_expression add_operator term]
|
69
69
|
reduce_simple_expression_1(aProduction, aRange, theTokens, theChildren)
|
70
70
|
|
71
|
-
when '
|
71
|
+
when 'term_0' # rule 'term' => 'factor'
|
72
72
|
return_first_child(aRange, theTokens, theChildren)
|
73
73
|
|
74
|
-
when '
|
74
|
+
when 'term_1' # rule 'term' => %w[term mul_operator factor]
|
75
75
|
reduce_term_1(aProduction, aRange, theTokens, theChildren)
|
76
76
|
|
77
|
-
when '
|
77
|
+
when 'factor_0' # rule 'factor' => 'NUMBER'
|
78
78
|
return_first_child(aRange, theTokens, theChildren)
|
79
79
|
|
80
|
-
when '
|
80
|
+
when 'factor_1' # rule 'factor' => %w[LPAREN expression RPAREN]
|
81
81
|
return_second_child(aRange, theTokens, theChildren)
|
82
82
|
|
83
|
-
when '
|
83
|
+
when 'add_operator_0' # rule 'add_operator' => 'PLUS'
|
84
84
|
reduce_add_operator_0(aProduction, aRange, theTokens, theChildren)
|
85
85
|
|
86
|
-
when '
|
86
|
+
when 'add_operator_1' # rule 'add_operator' => 'MINUS'
|
87
87
|
reduce_add_operator_1(aProduction, aRange, theTokens, theChildren)
|
88
88
|
|
89
|
-
when '
|
89
|
+
when 'mul_operator_0' # rule 'mul_operator' => 'STAR'
|
90
90
|
reduce_mul_operator_0(aProduction, aRange, theTokens, theChildren)
|
91
91
|
|
92
|
-
when '
|
92
|
+
when 'mul_operator_1' # rule 'mul_operator' => 'DIVIDE'
|
93
93
|
reduce_mul_operator_1(aProduction, aRange, theTokens, theChildren)
|
94
94
|
|
95
95
|
else
|
data/lib/rley/constants.rb
CHANGED
@@ -46,9 +46,10 @@ module Rley # This module is used as a namespace
|
|
46
46
|
mark_unreachable_symbols
|
47
47
|
end
|
48
48
|
|
49
|
-
Branching = Struct.new(:vertex, :to_visit, :visited) do
|
50
|
-
def initialize(aVertex)
|
49
|
+
Branching = Struct.new(:vertex, :in_edge, :to_visit, :visited) do
|
50
|
+
def initialize(aVertex, aCallEdge)
|
51
51
|
super(aVertex)
|
52
|
+
self.in_edge = aCallEdge
|
52
53
|
self.to_visit = aVertex.edges.dup
|
53
54
|
self.visited = []
|
54
55
|
end
|
@@ -64,6 +65,15 @@ module Rley # This module is used as a namespace
|
|
64
65
|
return next_one
|
65
66
|
end
|
66
67
|
end
|
68
|
+
|
69
|
+
def print_vertex(aText, aVertex)
|
70
|
+
print aText + ' '
|
71
|
+
if aVertex.kind_of?(NonTerminalVertex)
|
72
|
+
puts "#{aVertex.class} #{aVertex.non_terminal.name}"
|
73
|
+
else
|
74
|
+
p(aVertex.label)
|
75
|
+
end
|
76
|
+
end
|
67
77
|
|
68
78
|
# Walk over all the vertices of the graph that are reachable from a given
|
69
79
|
# start vertex. This is a depth-first graph traversal.
|
@@ -74,29 +84,38 @@ module Rley # This module is used as a namespace
|
|
74
84
|
visited = Set.new
|
75
85
|
stack = []
|
76
86
|
visitee = aStartVertex
|
87
|
+
curr_edge = nil
|
77
88
|
|
78
89
|
begin
|
90
|
+
# print_vertex( 'Traversing', visitee)
|
91
|
+
|
79
92
|
first_time = !visited.include?(visitee)
|
80
93
|
if first_time
|
81
94
|
yield(visitee)
|
82
95
|
visited << visitee
|
83
|
-
end
|
84
|
-
|
96
|
+
end
|
97
|
+
|
85
98
|
case visitee
|
86
99
|
when Rley::GFG::StartVertex
|
87
100
|
if first_time
|
88
|
-
stack.push(Branching.new(visitee))
|
101
|
+
stack.push(Branching.new(visitee, curr_edge))
|
89
102
|
curr_edge = stack.last.next_edge
|
90
103
|
else
|
91
|
-
# Skip start and end vertices
|
104
|
+
# Skip both start and end vertices
|
92
105
|
# Retrieve the corresponding return edge
|
93
106
|
curr_edge = get_matching_return(curr_edge)
|
94
107
|
end
|
95
108
|
|
96
109
|
when Rley::GFG::EndVertex
|
97
|
-
|
98
|
-
|
99
|
-
|
110
|
+
if stack.last.done?
|
111
|
+
popped = stack.pop
|
112
|
+
break if stack.empty?
|
113
|
+
# puts "Popped!"
|
114
|
+
return_key = popped.in_edge.key.sub(/^CALL/, 'RET')
|
115
|
+
curr_edge = visitee.edges.find { |e| e.key == return_key }
|
116
|
+
else
|
117
|
+
curr_edge = stack.last.next_edge
|
118
|
+
end
|
100
119
|
|
101
120
|
else
|
102
121
|
# All other vertex types have only one successor
|
@@ -105,7 +124,8 @@ module Rley # This module is used as a namespace
|
|
105
124
|
visitee = curr_edge.successor unless curr_edge.nil?
|
106
125
|
end until stack.empty?
|
107
126
|
# Now process the end vertex matching the initial start vertex
|
108
|
-
|
127
|
+
last_one = end_vertex_for[aStartVertex.non_terminal]
|
128
|
+
yield(last_one) unless visited.include?(last_one)
|
109
129
|
end
|
110
130
|
|
111
131
|
private
|
@@ -288,11 +308,13 @@ module Rley # This module is used as a namespace
|
|
288
308
|
a_vertex.non_terminal.unreachable = true
|
289
309
|
end
|
290
310
|
|
291
|
-
# Now traverse graph from start vertex
|
292
|
-
# and
|
311
|
+
# Now traverse graph from start vertex of graph
|
312
|
+
# and mark all visited non-terminals as reachable
|
293
313
|
traverse_df(start_vertex) do |a_vertex|
|
294
|
-
|
295
|
-
a_vertex.
|
314
|
+
# print_vertex(' Visiting', a_vertex)
|
315
|
+
if a_vertex.kind_of?(StartVertex)
|
316
|
+
a_vertex.non_terminal.unreachable = false
|
317
|
+
end
|
296
318
|
end
|
297
319
|
end
|
298
320
|
end # class
|
data/lib/rley/syntax/grammar.rb
CHANGED
@@ -78,10 +78,10 @@ module Rley # This module is used as a namespace
|
|
78
78
|
prefix = aProduction.lhs.name.dup
|
79
79
|
previous = index.zero? ? nil : rules[index - 1]
|
80
80
|
if previous.nil? || previous.lhs != aProduction.lhs
|
81
|
-
suffix = '
|
81
|
+
suffix = '_0'
|
82
82
|
else
|
83
|
-
prev_serial = previous.name.match(
|
84
|
-
suffix = "
|
83
|
+
prev_serial = previous.name.match(/_(\d+)$/)
|
84
|
+
suffix = "_#{prev_serial[1].to_i + 1}"
|
85
85
|
end
|
86
86
|
|
87
87
|
aProduction.name = prefix + suffix
|
@@ -74,22 +74,22 @@ module Rley # This module is used as a namespace
|
|
74
74
|
# @param theChildren [Array] Children nodes (one per rhs symbol)
|
75
75
|
def new_parent_node(aProduction, aRange, theTokens, theChildren)
|
76
76
|
node = case aProduction.name
|
77
|
-
when '
|
77
|
+
when 'P_0'
|
78
78
|
reduce_P_0(aRange, theTokens, theChildren)
|
79
79
|
|
80
|
-
when '
|
80
|
+
when 'arr_0'
|
81
81
|
reduce_arr_0(aRange, theTokens, theChildren)
|
82
82
|
|
83
|
-
when '
|
83
|
+
when 'sequence_0'
|
84
84
|
reduce_sequence_0(aRange, theTokens, theChildren)
|
85
85
|
|
86
|
-
when '
|
86
|
+
when 'sequence_1'
|
87
87
|
reduce_sequence_1(aRange, theTokens, theChildren)
|
88
88
|
|
89
|
-
when '
|
89
|
+
when 'list_0'
|
90
90
|
reduce_list_0(aRange, theTokens, theChildren)
|
91
91
|
|
92
|
-
when '
|
92
|
+
when 'list_1'
|
93
93
|
reduce_list_1(aRange, theTokens, theChildren)
|
94
94
|
else
|
95
95
|
err_msg = "Don't know production #{aProduction.name}"
|
@@ -162,7 +162,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
162
162
|
|
163
163
|
it 'should ensure that each production has a name' do
|
164
164
|
subject.rules.each do |prod|
|
165
|
-
expect(prod.name).to match(Regexp.new("#{prod.lhs.name}\\
|
165
|
+
expect(prod.name).to match(Regexp.new("#{prod.lhs.name}_\\d$"))
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end # context
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.04
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|