rley 0.5.03 → 0.5.04

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf5a9c73feeebf98f1714d89796bc073b406734e
4
- data.tar.gz: 33aad5b8b337bb617bda98c55adfd94d9ebfba03
3
+ metadata.gz: b5c84e4d5e47e769c76da705abef632e4748311c
4
+ data.tar.gz: 876569a22741aa76f5d9b7bec8404c0a518e02b3
5
5
  SHA512:
6
- metadata.gz: b1bb0f88617f3ce5c6b7f964c7849e70a016d7889a9568a3d2ba310d4f42f094cc76167f9ca64cb7cae7f71ca00af672f791afb4ba3460199e383dfbeece78c2
7
- data.tar.gz: db471ad23ae2a0bdf4f1408ed8371635cfe808808b5daa4454fa3b1189cc107a4ac99514e50f805cdfb58e1ff3ff61cfba8840a5dbeadad9f5766118e7424075
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-text[0]' # rule 'JSON-text' => 'value'
55
+ when 'JSON-text_0' # rule 'JSON-text' => 'value'
56
56
  return_first_child(aRange, theTokens, theChildren)
57
57
 
58
- when /value\[\d\]/
58
+ when /value_\d/
59
59
  return_first_child(aRange, theTokens, theChildren)
60
60
 
61
- when 'object[0]'
61
+ when 'object_0'
62
62
  reduce_object_0(aProduction, aRange, theTokens, theChildren)
63
63
 
64
- when 'object[1]'
64
+ when 'object_1'
65
65
  reduce_object_1(aRange, theTokens, theChildren)
66
66
 
67
- when 'member-list[0]'
67
+ when 'member-list_0'
68
68
  reduce_member_list_0(aRange, theTokens, theChildren)
69
69
 
70
- when 'member-list[1]'
70
+ when 'member-list_1'
71
71
  reduce_member_list_1(aProduction, aRange, theTokens, theChildren)
72
72
 
73
- when 'member[0]'
73
+ when 'member_0'
74
74
  reduce_member_0(aProduction, aRange, theTokens, theChildren)
75
75
 
76
- when 'array[0]'
76
+ when 'array_0'
77
77
  reduce_array_0(aProduction, aRange, theTokens, theChildren)
78
78
 
79
- when 'array[1]'
79
+ when 'array_1'
80
80
  reduce_array_1(aRange, theTokens, theChildren)
81
81
 
82
- when 'array-items[0]'
82
+ when 'array-items_0'
83
83
  reduce_array_items_0(aRange, theTokens, theChildren)
84
84
 
85
- when 'array-items[1]'
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 'expression[0]' # rule 'expression' => 'simple_expression'
61
+ when 'expression_0' # rule 'expression' => 'simple_expression'
62
62
  return_first_child(aRange, theTokens, theChildren)
63
63
 
64
- when 'simple_expression[0]' # rule 'simple_expression' => 'term'
64
+ when 'simple_expression_0' # rule 'simple_expression' => 'term'
65
65
  return_first_child(aRange, theTokens, theChildren)
66
66
 
67
- when 'simple_expression[1]'
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 'term[0]' # rule 'term' => 'factor'
71
+ when 'term_0' # rule 'term' => 'factor'
72
72
  return_first_child(aRange, theTokens, theChildren)
73
73
 
74
- when 'term[1]' # rule 'term' => %w[term mul_operator factor]
74
+ when 'term_1' # rule 'term' => %w[term mul_operator factor]
75
75
  reduce_term_1(aProduction, aRange, theTokens, theChildren)
76
76
 
77
- when 'factor[0]' # rule 'factor' => 'NUMBER'
77
+ when 'factor_0' # rule 'factor' => 'NUMBER'
78
78
  return_first_child(aRange, theTokens, theChildren)
79
79
 
80
- when 'factor[1]' # rule 'factor' => %w[LPAREN expression RPAREN]
80
+ when 'factor_1' # rule 'factor' => %w[LPAREN expression RPAREN]
81
81
  return_second_child(aRange, theTokens, theChildren)
82
82
 
83
- when 'add_operator[0]' # rule 'add_operator' => 'PLUS'
83
+ when 'add_operator_0' # rule 'add_operator' => 'PLUS'
84
84
  reduce_add_operator_0(aProduction, aRange, theTokens, theChildren)
85
85
 
86
- when 'add_operator[1]' # rule 'add_operator' => 'MINUS'
86
+ when 'add_operator_1' # rule 'add_operator' => 'MINUS'
87
87
  reduce_add_operator_1(aProduction, aRange, theTokens, theChildren)
88
88
 
89
- when 'mul_operator[0]' # rule 'mul_operator' => 'STAR'
89
+ when 'mul_operator_0' # rule 'mul_operator' => 'STAR'
90
90
  reduce_mul_operator_0(aProduction, aRange, theTokens, theChildren)
91
91
 
92
- when 'mul_operator[1]' # rule 'mul_operator' => 'DIVIDE'
92
+ when 'mul_operator_1' # rule 'mul_operator' => 'DIVIDE'
93
93
  reduce_mul_operator_1(aProduction, aRange, theTokens, theChildren)
94
94
 
95
95
  else
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.5.03'.freeze
6
+ Version = '0.5.04'.freeze
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm".freeze
@@ -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
- stack.pop if stack.last.done?
98
- break if stack.empty?
99
- curr_edge = stack.last.next_edge
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
- yield(end_vertex_for[aStartVertex.non_terminal])
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 make all visited non-terminals as reachable
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
- next unless a_vertex.kind_of?(StartVertex)
295
- a_vertex.non_terminal.unreachable = false
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
@@ -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 = '[0]'
81
+ suffix = '_0'
82
82
  else
83
- prev_serial = previous.name.match(/\[(\d+)\]$/)
84
- suffix = "[#{prev_serial[1].to_i + 1}]"
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
@@ -191,6 +191,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
191
191
  'A.',
192
192
  'A => . b',
193
193
  'A => b .',
194
+ 'S => A .',
194
195
  'S.'
195
196
  ]
196
197
  expect(result).to eq(expected)
@@ -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 'P[0]'
77
+ when 'P_0'
78
78
  reduce_P_0(aRange, theTokens, theChildren)
79
79
 
80
- when 'arr[0]'
80
+ when 'arr_0'
81
81
  reduce_arr_0(aRange, theTokens, theChildren)
82
82
 
83
- when 'sequence[0]'
83
+ when 'sequence_0'
84
84
  reduce_sequence_0(aRange, theTokens, theChildren)
85
85
 
86
- when 'sequence[1]'
86
+ when 'sequence_1'
87
87
  reduce_sequence_1(aRange, theTokens, theChildren)
88
88
 
89
- when 'list[0]'
89
+ when 'list_0'
90
90
  reduce_list_0(aRange, theTokens, theChildren)
91
91
 
92
- when 'list[1]'
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}\\[\\d\\]"))
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.03
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-09 00:00:00.000000000 Z
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls