rley 0.3.07 → 0.3.08

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: b9b70296885dc161ee4fdedf19ff1c2e04256086
4
- data.tar.gz: 993b5b46f0edf140140d4713161c88b3cc846ca6
3
+ metadata.gz: 38c77acd3a3831519aa9511c02ab2aaa7f99c962
4
+ data.tar.gz: bd84fe47221a72d195a92e40e8c5a62fafed562b
5
5
  SHA512:
6
- metadata.gz: c390b234b9412d2b48d92ad725bfad8860dea3c1b9d21ef75ffb6191f05cc23a3bccfa8975c6a79e9651b29fba345298e1c053454523390d118eeab9f8b6ad24
7
- data.tar.gz: 5358fb0d0201b821be251d47f804dd9362ea970e4765462346658106ecf8e452e6088d239b0ce63073bc7bc9db9299018f523ac9024de6cac3b85e664ba36fe8
6
+ metadata.gz: 7a36a172143025e47b03022dc2db7be6bcb990b21834ea51288afe9158c3fe97eaafce70cbcd36ea64841da03036a0e98e446454b4e6f8e2170e60e9fa2c0697
7
+ data.tar.gz: 716aa238f7f40e07118b11eb3d7c38c5a3f2cc8583c516818d1d5bcb11267a7c52b7849e049de4ecf93729f23746b1569adfbdd1d297947e787f9c82a5a0b94e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.08 / 2016-11-17
2
+ * [FIX] Method `ParseWalkerFactory#select_antecedent` did not support alternative nodes creation when visiting an item entry for highly ambiguous parse.
3
+ * [FIX] Method `ParseWalkerFactory#select_antecedent` did not manage properly call/return stack for alternative nodes created when visiting an item entry for highly ambiguous parse.
4
+
5
+
1
6
  ### 0.3.07 / 2016-11-08
2
7
  * [FIX] The sharing a of forest node could be repeated in a production in a revisit event.
3
8
  * [CHANGE] Method `ParseWalkerFactory#process_end_entry`. Added a guard condition to avoid repeated node sharing
@@ -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.3.07'.freeze
6
+ Version = '0.3.08'.freeze
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm".freeze
@@ -82,7 +82,7 @@ module Rley # This module is used as a namespace
82
82
  when :backtrack
83
83
  # Restore path
84
84
  @curr_path = entry2path_to_alt[anEntry].dup
85
- # puts "Restore path #{curr_path.join(', ')}]"
85
+ # puts "Restore path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
86
86
  antecedent_index = curr_parent.subnodes.size
87
87
  # puts "Current parent #{curr_parent.to_string(0)}"
88
88
  # puts "Antecedent index #{antecedent_index}"
@@ -103,35 +103,76 @@ module Rley # This module is used as a namespace
103
103
  end
104
104
 
105
105
 
106
- def process_item_entry(_anEvent, anEntry, anIndex)
107
- if anEntry.exit_entry?
108
- # Previous entry was an end entry (X. pattern)
109
- # Does the previous entry have multiple antecedent?
110
- if last_visitee.end_entry? && last_visitee.antecedents.size > 1
111
- # Store current path for later backtracking
112
- # puts "Store backtrack context #{last_visitee}"
113
- # puts "path [#{curr_path.join(', ')}]"
114
- entry2path_to_alt[last_visitee] = curr_path.dup
115
- curr_parent.refinement = :or
116
-
117
- create_alternative_node(anEntry)
118
- end
119
- end
120
-
121
- # Retrieve the grammar symbol before the dot (if any)
122
- prev_symbol = anEntry.prev_symbol
123
- case prev_symbol
124
- when Syntax::Terminal
125
- # Add node without changing current path
126
- create_token_node(anEntry, anIndex)
127
-
128
- when NilClass # Dot at the beginning of production
129
- if anEntry.vertex.dotted_item.production.empty?
130
- # Empty rhs => create an epsilon node ...
131
- # ... without changing current path
132
- create_epsilon_node(anEntry, anIndex)
106
+ def process_item_entry(anEvent, anEntry, anIndex)
107
+ case anEvent
108
+ when :visit
109
+ if anEntry.exit_entry?
110
+ # Previous entry was an end entry (X. pattern)
111
+ # Does the previous entry have multiple antecedent?
112
+ if last_visitee.end_entry? && last_visitee.antecedents.size > 1
113
+ # Store current path for later backtracking
114
+ # puts "Store backtrack context #{last_visitee}"
115
+ # puts "path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
116
+ entry2path_to_alt[last_visitee] = curr_path.dup
117
+ curr_parent.refinement = :or
118
+
119
+ create_alternative_node(anEntry)
120
+ end
133
121
  end
134
- curr_path.pop if curr_parent.kind_of?(SPPF::AlternativeNode)
122
+
123
+ # Does this entry have multiple antecedent?
124
+ if anEntry.antecedents.size > 1
125
+ # Store current path for later backtracking
126
+ # puts "Store backtrack context #{anEntry}"
127
+ # puts "path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
128
+ entry2path_to_alt[anEntry] = curr_path.dup
129
+ # curr_parent.refinement = :or
130
+
131
+ create_alternative_node(anEntry)
132
+ end
133
+
134
+ # Retrieve the grammar symbol before the dot (if any)
135
+ prev_symbol = anEntry.prev_symbol
136
+ case prev_symbol
137
+ when Syntax::Terminal
138
+ # Add node without changing current path
139
+ create_token_node(anEntry, anIndex)
140
+
141
+ when NilClass # Dot at the beginning of production
142
+ if anEntry.vertex.dotted_item.production.empty?
143
+ # Empty rhs => create an epsilon node ...
144
+ # ... without changing current path
145
+ create_epsilon_node(anEntry, anIndex)
146
+ end
147
+ curr_path.pop if curr_parent.kind_of?(SPPF::AlternativeNode)
148
+ end
149
+
150
+ when :backtrack
151
+ # Restore path
152
+ @curr_path = entry2path_to_alt[anEntry].dup
153
+ # puts "Special restore path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
154
+ antecedent_index = curr_parent.subnodes.size
155
+ # puts "Current parent #{curr_parent.to_string(0)}"
156
+ # puts "Antecedent index #{antecedent_index}"
157
+
158
+ create_alternative_node(anEntry)
159
+
160
+ when :revisit
161
+ # Retrieve the grammar symbol before the dot (if any)
162
+ prev_symbol = anEntry.prev_symbol
163
+ case prev_symbol
164
+ when Syntax::Terminal
165
+ # Add node without changing current path
166
+ create_token_node(anEntry, anIndex)
167
+
168
+ when NilClass # Dot at the beginning of production
169
+ if anEntry.vertex.dotted_item.production.empty?
170
+ # Empty rhs => create an epsilon node ...
171
+ # ... without changing current path
172
+ create_epsilon_node(anEntry, anIndex)
173
+ end
174
+ curr_path.pop if curr_parent.kind_of?(SPPF::AlternativeNode)
175
+ end
135
176
  end
136
177
  end
137
178
 
@@ -168,6 +168,7 @@ module Rley # This module is used as a namespace
168
168
  aContext.return_stack << aContext.curr_entry
169
169
  elsif traversed_edge.kind_of?(GFG::CallEdge)
170
170
  # Pop top of stack
171
+ fail ScriptError, "Return stack empty!" if aContext.return_stack.empty?
171
172
  aContext.return_stack.pop
172
173
  # puts "Pop from return stack matching entry #{new_entry}"
173
174
  elsif traversed_edge.kind_of?(GFG::ScanEdge)
@@ -187,13 +188,19 @@ module Rley # This module is used as a namespace
187
188
  case aContext.curr_entry.vertex
188
189
  when GFG::EndVertex
189
190
  # puts "Add backtrack point stack #{aContext.curr_entry}"
190
- # An end vertex with multiple antecedents requires
191
- # a backtrack point for a correct graph traversal
192
191
  bp = add_backtrack_point(aContext)
193
192
  new_entry = bp.visitee.antecedents[bp.antecedent_index]
194
193
 
195
194
  when GFG::StartVertex
196
195
  new_entry = select_calling_entry(aContext)
196
+
197
+ when GFG::ItemVertex
198
+ # Push current entry onto stack
199
+ # puts "Special push on return stack #{aContext.curr_entry}"
200
+ aContext.return_stack << aContext.curr_entry
201
+ # puts "Add special backtrack point stack #{aContext.curr_entry}"
202
+ bp = add_backtrack_point(aContext)
203
+ new_entry = bp.visitee.antecedents[bp.antecedent_index]
197
204
  else
198
205
  raise StandardError, 'Internal error'
199
206
  end
@@ -239,6 +246,7 @@ module Rley # This module is used as a namespace
239
246
  # Observation: calling parse entry is an parse entry linked
240
247
  # to a item vertex
241
248
  def select_calling_entry(aContext)
249
+ fail ScriptError, "Empty return stack" if aContext.return_stack.empty?
242
250
  # Retrieve top of stack
243
251
  tos = aContext.return_stack.pop
244
252
  tos_dotted_item = tos.vertex.dotted_item
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.3.07
4
+ version: 0.3.08
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-08 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake