rley 0.6.04 → 0.6.05
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/engine.rb +4 -1
- data/lib/rley/parse_rep/parse_tree_builder.rb +11 -4
- data/lib/rley/parser/gfg_parsing.rb +45 -2
- data/lib/rley/parser/parse_entry.rb +1 -1
- data/spec/rley/parser/gfg_parsing_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: 3083af262074f545ce6cdb9afed83c0d8a5cd255
|
4
|
+
data.tar.gz: d99c85423dde12c232681524dc9f8692bbd1d0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b474bb46b84aad4cfa74f72cdadc4d7da99bb0a80e5d6f8e4176716a6297a5be9495adac0202f2c5791ddbeb728ef7a35a5f0dd0e22504cb3d934c2d4446c9
|
7
|
+
data.tar.gz: 296215d53be774b54bff3b1b4ee316afab8ea86282d507cb72fac36f55b810c694e45554b2758a4b18c9008cb75030147129b20b730ce1b8cd1077ff582438df
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.6.05 / 2018-04-02
|
2
|
+
* [CHANGE] Method `ParseTreeBuilder#process_end_entry`: added an explicit message in case of ambiguous parse.
|
3
|
+
* [CHANGE] Method `ParseTreeBuilder#process_item_entry`: added an explicit message in case of ambiguous parse.
|
4
|
+
* [FIX] Method `ParseEntry#add_antecedent` now checks for the unicity of antecedent entries.
|
5
|
+
|
1
6
|
### 0.6.04 / 2018-03-30
|
2
7
|
* [CHANGE] Method `GrammarBuilder#add_production` Simplified rule entry syntax
|
3
8
|
* [CHANGE] File `examples/NML/pico_en_demo.rb` updated to reflect the simplified rule syntax.
|
data/lib/rley/constants.rb
CHANGED
data/lib/rley/engine.rb
CHANGED
@@ -61,7 +61,10 @@ module Rley # This module is used as a namespace
|
|
61
61
|
end
|
62
62
|
parser = build_parser(grammar)
|
63
63
|
parser.gf_graph.diagnose if configuration.diagnose
|
64
|
-
|
64
|
+
result = parser.parse(tokens)
|
65
|
+
result.tidy_up!
|
66
|
+
|
67
|
+
return result
|
65
68
|
end
|
66
69
|
|
67
70
|
# Convert raw parse result into a more convenient representation
|
@@ -101,8 +101,11 @@ module Rley # This module is used as a namespace
|
|
101
101
|
non_terminal = entry2nonterm(anEntry)
|
102
102
|
# Create raw node and push onto stack
|
103
103
|
push_raw_node(range, non_terminal)
|
104
|
-
|
105
|
-
|
104
|
+
|
105
|
+
when :backtrack
|
106
|
+
msg_prefix = 'Ambiguous parse detected at '
|
107
|
+
msg_suffix = "entry: #{anEntry}, index: #{anIndex}"
|
108
|
+
raise StandardError, msg_prefix + msg_suffix
|
106
109
|
else
|
107
110
|
raise NotImplementedError, "Cannot handle event #{anEvent}"
|
108
111
|
end
|
@@ -135,10 +138,14 @@ module Rley # This module is used as a namespace
|
|
135
138
|
# (pattern: N => alpha+ . beta+)
|
136
139
|
process_middle_entry(anEntry, anIndex)
|
137
140
|
end
|
141
|
+
when :backtrack
|
142
|
+
msg_prefix = 'Ambiguous parse detected at '
|
143
|
+
msg_suffix = "entry: #{anEntry}, index: #{anIndex}"
|
144
|
+
raise StandardError, msg_prefix + msg_suffix
|
138
145
|
else
|
139
146
|
msg_prefix = "Internal Error '#{anEvent}', "
|
140
|
-
|
141
|
-
raise NotImplementedError
|
147
|
+
msg_suffix = "entry: #{anEntry}, index: #{anIndex}"
|
148
|
+
raise NotImplementedError, msg_prefix + msg_suffix
|
142
149
|
end
|
143
150
|
end
|
144
151
|
|
@@ -78,7 +78,6 @@ module Rley # This module is used as a namespace
|
|
78
78
|
start_entry = apply_rule(anEntry, start, pos, pos, :nullable_rule)
|
79
79
|
|
80
80
|
end_vertex = gf_graph.end_vertex_for[next_symbol]
|
81
|
-
end_entry = push_entry(end_vertex, pos, pos, :nullable_rule)
|
82
81
|
|
83
82
|
start.edges.each do |edge|
|
84
83
|
succ = edge.successor # succ always an ItemVertex
|
@@ -89,6 +88,7 @@ module Rley # This module is used as a namespace
|
|
89
88
|
|
90
89
|
curr_vertex = anEntry.vertex
|
91
90
|
next_vertex = curr_vertex.shortcut.successor
|
91
|
+
end_entry = push_entry(end_vertex, pos, pos, :nullable_rule)
|
92
92
|
apply_rule(end_entry, next_vertex, anEntry.origin, pos, :nullable_rule)
|
93
93
|
end
|
94
94
|
|
@@ -190,7 +190,7 @@ module Rley # This module is used as a namespace
|
|
190
190
|
def parse_forest()
|
191
191
|
msg = <<-END_MSG
|
192
192
|
Method Rley::Parser::GFGParsing.parse_forest is deprecated, call
|
193
|
-
Rley::Engine::to_pforest. It will be removed
|
193
|
+
Rley::Engine::to_pforest. It will be removed June 1st
|
194
194
|
or version 0.6.1 (whichever is first)
|
195
195
|
END_MSG
|
196
196
|
# warn(msg)
|
@@ -240,6 +240,15 @@ END_MSG
|
|
240
240
|
premature_end unless success? || failure_reason
|
241
241
|
end
|
242
242
|
|
243
|
+
# Clean and normalize the object.
|
244
|
+
# Call this method when the parsing is complete.
|
245
|
+
def tidy_up!()
|
246
|
+
antecedence.each_key do |entry|
|
247
|
+
antecedence[entry].uniq!
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
|
243
252
|
private
|
244
253
|
|
245
254
|
# Parse error detected: all input tokens were consumed and
|
@@ -266,8 +275,42 @@ END_MSG
|
|
266
275
|
|
267
276
|
def apply_rule(antecedentEntry, aVertex, anOrigin, aPosition, aRuleId)
|
268
277
|
consequent = push_entry(aVertex, anOrigin, aPosition, aRuleId)
|
278
|
+
|
269
279
|
antecedence[consequent] << antecedentEntry
|
280
|
+
|
281
|
+
# Invariant checks
|
282
|
+
antecedents = antecedence[consequent]
|
283
|
+
case aVertex
|
284
|
+
when Rley::GFG::EndVertex
|
285
|
+
# Rule: has 1..* antecedents, all of them are exit items
|
286
|
+
antecedents.each do |antec|
|
287
|
+
next if antec.exit_entry?
|
288
|
+
msg_prefix = "Parse entry #{consequent}"
|
289
|
+
msg_suffix = " has for antecedent #{antec}"
|
290
|
+
raise StandardError, msg_prefix + msg_suffix
|
291
|
+
end
|
292
|
+
|
293
|
+
when Rley::GFG::ItemVertex
|
294
|
+
# Rule: has exactly one antecedent
|
295
|
+
# if antecedents.size > 1
|
296
|
+
# msg_prefix = "Parse entry #{consequent} | #{aPosition}"
|
297
|
+
# msg = " has more than one antecedent:\n"
|
298
|
+
# msg_suffix = antecedents.map(&:to_s).join("\n")
|
299
|
+
# raise(StandardError, msg_prefix + msg + msg_suffix)
|
300
|
+
# end
|
301
|
+
|
302
|
+
when Rley::GFG::StartVertex
|
303
|
+
# Rule: has 0..* antecedents, all of them are item vertices but not exit items
|
304
|
+
antecedents.each do |antec|
|
305
|
+
next if antec.dotted_entry? && !antec.end_entry?
|
306
|
+
msg_prefix = "Parse entry #{consequent}"
|
307
|
+
msg_suffix = " has for antecedent #{antec}"
|
308
|
+
raise StandardError, msg_prefix + msg_suffix
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
270
312
|
consequent.add_antecedent(antecedentEntry)
|
313
|
+
return consequent
|
271
314
|
end
|
272
315
|
|
273
316
|
# Push a parse entry (vertex + origin) to the
|
@@ -43,7 +43,7 @@ module Rley # This module is used as a namespace
|
|
43
43
|
|
44
44
|
# Add a link to an antecedent parse entry
|
45
45
|
def add_antecedent(anAntecedent)
|
46
|
-
antecedents << anAntecedent
|
46
|
+
antecedents << anAntecedent unless antecedents.include?(anAntecedent)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Equality comparison. A parse entry behaves as a value object.
|
@@ -254,7 +254,7 @@ SNIPPET
|
|
254
254
|
end_entry = subject.chart[1].last
|
255
255
|
expect(end_entry.vertex.label).to eq('S => A .')
|
256
256
|
expect(end_entry.origin).to eq(0)
|
257
|
-
expect(subject.antecedence.fetch(end_entry)).to eq([exit_entry])
|
257
|
+
expect(subject.antecedence.fetch(end_entry)).to eq([exit_entry])
|
258
258
|
end
|
259
259
|
=begin
|
260
260
|
|
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.6.
|
4
|
+
version: 0.6.05
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|