rley 0.7.00 → 0.7.01
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/.rubocop.yml +51 -34
- data/.travis.yml +10 -9
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +0 -1
- data/appveyor.yml +10 -8
- data/examples/NLP/benchmark_pico_en.rb +3 -2
- data/examples/NLP/engtagger.rb +23 -12
- data/examples/NLP/nano_eng/nano_en_demo.rb +4 -3
- data/examples/NLP/pico_en_demo.rb +3 -2
- data/examples/data_formats/JSON/json_ast_nodes.rb +3 -0
- data/examples/data_formats/JSON/json_demo.rb +1 -0
- data/examples/data_formats/JSON/json_lexer.rb +2 -1
- data/lib/rley/base/dotted_item.rb +2 -0
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/engine.rb +8 -7
- data/lib/rley/gfg/grm_flow_graph.rb +2 -0
- data/lib/rley/gfg/item_vertex.rb +2 -0
- data/lib/rley/gfg/vertex.rb +2 -1
- data/lib/rley/lexical/token.rb +5 -4
- data/lib/rley/parse_forest_visitor.rb +7 -5
- data/lib/rley/parse_rep/ast_base_builder.rb +1 -1
- data/lib/rley/parse_rep/parse_rep_creator.rb +2 -2
- data/lib/rley/parse_rep/parse_tree_builder.rb +1 -0
- data/lib/rley/parse_tree_visitor.rb +2 -0
- data/lib/rley/parser/error_reason.rb +8 -6
- data/lib/rley/parser/gfg_chart.rb +5 -5
- data/lib/rley/parser/gfg_parsing.rb +10 -5
- data/lib/rley/parser/parse_entry_tracker.rb +1 -0
- data/lib/rley/parser/parse_state.rb +2 -1
- data/lib/rley/parser/parse_state_tracker.rb +1 -0
- data/lib/rley/parser/parse_walker_factory.rb +7 -1
- data/lib/rley/ptree/parse_tree_node.rb +1 -0
- data/lib/rley/sppf/parse_forest.rb +9 -7
- data/lib/rley/syntax/grammar.rb +10 -6
- data/lib/rley/syntax/grammar_builder.rb +2 -2
- data/lib/rley/syntax/grm_symbol.rb +1 -0
- data/lib/support/base_tokenizer.rb +10 -96
- data/spec/rley/engine_spec.rb +3 -3
- data/spec/rley/gfg/grm_flow_graph_spec.rb +1 -0
- data/spec/rley/parse_forest_visitor_spec.rb +63 -38
- data/spec/rley/parse_rep/groucho_spec.rb +9 -8
- data/spec/rley/parse_tree_visitor_spec.rb +1 -1
- data/spec/rley/parser/gfg_earley_parser_spec.rb +7 -7
- data/spec/rley/parser/gfg_parsing_spec.rb +1 -3
- data/spec/rley/parser/parse_entry_spec.rb +1 -1
- data/spec/rley/support/expectation_helper.rb +2 -1
- data/spec/rley/support/grammar_ambig01_helper.rb +4 -3
- data/spec/rley/support/grammar_arr_int_helper.rb +5 -4
- data/spec/rley/support/grammar_b_expr_helper.rb +5 -4
- data/spec/rley/support/grammar_helper.rb +2 -2
- data/spec/rley/support/grammar_l0_helper.rb +3 -2
- data/spec/rley/support/grammar_pb_helper.rb +5 -28
- data/spec/support/base_tokenizer_spec.rb +7 -9
- metadata +2 -2
|
@@ -31,6 +31,7 @@ module Rley # This module is used as a namespace
|
|
|
31
31
|
|
|
32
32
|
# Notification that the SPPF construction is over
|
|
33
33
|
def done!
|
|
34
|
+
# Do nothing
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
# Returns true if the given node is present in the forest.
|
|
@@ -44,15 +45,16 @@ module Rley # This module is used as a namespace
|
|
|
44
45
|
return @is_ambiguous
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
# Create an Enumerator that helps to iterate over the possible
|
|
48
|
-
# That enumerator will generate a parse tree when
|
|
48
|
+
# Create an Enumerator that helps to iterate over the possible
|
|
49
|
+
# parse trees. That enumerator will generate a parse tree when
|
|
50
|
+
# called with `next` method.
|
|
49
51
|
# @return [Enumerator]
|
|
50
52
|
def to_ptree_enum()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
# How to implement?
|
|
54
|
+
# One visits the forest => beware of dependency
|
|
55
|
+
# At each visited item create a corresponding tree node.
|
|
56
|
+
# At end of visit & stack not empty
|
|
57
|
+
# Re-generate another ptree
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
# Part of the 'visitee' role in the Visitor design pattern.
|
data/lib/rley/syntax/grammar.rb
CHANGED
|
@@ -26,7 +26,7 @@ module Rley # This module is used as a namespace
|
|
|
26
26
|
attr_reader(:symbols)
|
|
27
27
|
|
|
28
28
|
# A Hash that maps symbol names to their grammar symbols
|
|
29
|
-
# @return [Hash{String => GrmSymbol}]
|
|
29
|
+
# @return [Hash{String => GrmSymbol}]
|
|
30
30
|
attr_reader(:name2symbol)
|
|
31
31
|
|
|
32
32
|
# @param theProductions [Array<Production>] productions of the grammar.
|
|
@@ -62,6 +62,7 @@ module Rley # This module is used as a namespace
|
|
|
62
62
|
def validate_productions(theProductions)
|
|
63
63
|
msg = 'A grammar must have at least one production'
|
|
64
64
|
raise StandardError, msg if theProductions.nil? || theProductions.empty?
|
|
65
|
+
|
|
65
66
|
return theProductions
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -133,6 +134,7 @@ module Rley # This module is used as a namespace
|
|
|
133
134
|
|
|
134
135
|
rules.each do |a_rule|
|
|
135
136
|
next unless a_rule.generative?.nil?
|
|
137
|
+
|
|
136
138
|
if a_rule.empty?
|
|
137
139
|
a_rule.generative = false
|
|
138
140
|
curr_marked << a_rule
|
|
@@ -146,6 +148,7 @@ module Rley # This module is used as a namespace
|
|
|
146
148
|
break unless symbol.generative?
|
|
147
149
|
end
|
|
148
150
|
next if last_considered.generative?.nil?
|
|
151
|
+
|
|
149
152
|
a_rule.generative = last_considered.generative?
|
|
150
153
|
curr_marked << a_rule
|
|
151
154
|
could_mark_nterm_generative(a_rule)
|
|
@@ -211,30 +214,31 @@ module Rley # This module is used as a namespace
|
|
|
211
214
|
end
|
|
212
215
|
end
|
|
213
216
|
break if new_nullables.empty?
|
|
217
|
+
|
|
214
218
|
filtered_rules.reject! { |prod| prod.lhs.nullable? }
|
|
215
219
|
nullable_sets[i] = nullable_sets[i - 1].merge(new_nullables)
|
|
216
220
|
end
|
|
217
|
-
|
|
221
|
+
|
|
218
222
|
mark_nullable
|
|
219
223
|
end
|
|
220
224
|
|
|
221
225
|
# Return the set of nonterminals which have one of their
|
|
222
226
|
# production rules empty
|
|
223
|
-
def direct_nullable
|
|
227
|
+
def direct_nullable
|
|
224
228
|
nullables = Set.new
|
|
225
229
|
# Direct nullable nonterminals correspond to empty productions
|
|
226
230
|
rules.each do |prod|
|
|
227
231
|
next unless prod.empty?
|
|
232
|
+
|
|
228
233
|
prod.lhs.nullable = true
|
|
229
234
|
nullables << prod.lhs
|
|
230
235
|
end
|
|
231
236
|
|
|
232
237
|
return nullables
|
|
233
238
|
end
|
|
234
|
-
|
|
235
|
-
|
|
239
|
+
|
|
236
240
|
# For each prodction determine whether it is nullable or not.
|
|
237
|
-
# A nullable production is a production that can match an empty string.
|
|
241
|
+
# A nullable production is a production that can match an empty string.
|
|
238
242
|
def mark_nullable
|
|
239
243
|
rules.each do |prod|
|
|
240
244
|
if prod.empty?
|
|
@@ -75,8 +75,8 @@ module Rley # This module is used as a namespace
|
|
|
75
75
|
when Array
|
|
76
76
|
rhs_members = rhs_repr.map { |name| get_nonterminal(name) }
|
|
77
77
|
when String
|
|
78
|
-
|
|
79
|
-
rhs_members =
|
|
78
|
+
rhs_lexemes = rhs_repr.scan(/\S+/)
|
|
79
|
+
rhs_members = rhs_lexemes.map { |name| get_nonterminal(name) }
|
|
80
80
|
when Terminal
|
|
81
81
|
rhs_members = [rhs_repr]
|
|
82
82
|
end
|
|
@@ -37,13 +37,14 @@ class BaseTokenizer
|
|
|
37
37
|
|
|
38
38
|
# Patterns:
|
|
39
39
|
# Unambiguous single character
|
|
40
|
-
# Conditional single character
|
|
40
|
+
# Conditional single character:
|
|
41
|
+
# (e.g. '+' operator, '+' prefix for positive numbers)
|
|
41
42
|
def _next_token
|
|
42
43
|
skip_whitespaces
|
|
43
44
|
curr_ch = scanner.peek(1)
|
|
44
45
|
return nil if curr_ch.nil? || curr_ch.empty?
|
|
45
46
|
|
|
46
|
-
token = recognize_token
|
|
47
|
+
token = recognize_token
|
|
47
48
|
if token.nil? # Unknown token
|
|
48
49
|
curr_ch = scanner.peek(1)
|
|
49
50
|
erroneous = curr_ch.nil? ? '' : scanner.scan(/./)
|
|
@@ -55,40 +56,8 @@ class BaseTokenizer
|
|
|
55
56
|
return token
|
|
56
57
|
end
|
|
57
58
|
|
|
58
|
-
def recognize_token
|
|
59
|
-
|
|
60
|
-
if "()'`".include? curr_ch # Single characters
|
|
61
|
-
# Delimiters, separators => single character token
|
|
62
|
-
token = build_token(@@lexeme2name[curr_ch], scanner.getch)
|
|
63
|
-
elsif (lexeme = scanner.scan(/(?:\.)(?=\s)/)) # Single char occurring alone
|
|
64
|
-
token = build_token('PERIOD', lexeme)
|
|
65
|
-
elsif (lexeme = scanner.scan(/,@?/))
|
|
66
|
-
token = build_token(@@lexeme2name[lexeme], lexeme)
|
|
67
|
-
elsif (lexeme = scanner.scan(/#(?:(?:true)|(?:false)|(?:u8)|[\\\(tfeiodx]|(?:\d+[=#]))/))
|
|
68
|
-
token = cardinal_token(lexeme)
|
|
69
|
-
elsif (lexeme = scanner.scan(/[+-]?[0-9]+(?=\s|[|()";]|$)/))
|
|
70
|
-
token = build_token('INTEGER', lexeme) # Decimal radix
|
|
71
|
-
elsif (lexeme = scanner.scan(/[+-]?[0-9]+(?:\.[0-9]+)?(?:(?:e|E)[+-]?[0-9]+)?/))
|
|
72
|
-
# Order dependency: must be tested after INTEGER case
|
|
73
|
-
token = build_token('REAL', lexeme)
|
|
74
|
-
elsif (lexeme = scanner.scan(/"(?:\\"|[^"])*"/)) # Double quotes literal?
|
|
75
|
-
token = build_token('STRING_LIT', lexeme)
|
|
76
|
-
elsif (lexeme = scanner.scan(/[a-zA-Z!$%&*\/:<=>?@^_~][a-zA-Z0-9!$%&*+-.\/:<=>?@^_~+-]*/))
|
|
77
|
-
keyw = @@keywords[lexeme.upcase]
|
|
78
|
-
tok_type = keyw ? keyw : 'IDENTIFIER'
|
|
79
|
-
token = build_token(tok_type, lexeme)
|
|
80
|
-
elsif (lexeme = scanner.scan(/\|(?:[^|])*\|/)) # Vertical bar delimited
|
|
81
|
-
token = build_token('IDENTIFIER', lexeme)
|
|
82
|
-
elsif (lexeme = scanner.scan(/([\+\-])((?=\s|[|()";])|$)/))
|
|
83
|
-
# # R7RS peculiar identifiers case 1: isolated plus and minus as identifiers
|
|
84
|
-
token = build_token('IDENTIFIER', lexeme)
|
|
85
|
-
elsif (lexeme = scanner.scan(/[+-][a-zA-Z!$%&*\/:<=>?@^_~+-@][a-zA-Z0-9!$%&*+-.\/:<=>?@^_~+-]*/))
|
|
86
|
-
# R7RS peculiar identifiers case 2
|
|
87
|
-
token = build_token('IDENTIFIER', lexeme)
|
|
88
|
-
elsif (lexeme = scanner.scan(/\.[a-zA-Z!$%&*\/:<=>?@^_~+-@.][a-zA-Z0-9!$%&*+-.\/:<=>?@^_~+-]*/))
|
|
89
|
-
# R7RS peculiar identifiers case 4
|
|
90
|
-
token = build_token('IDENTIFIER', lexeme)
|
|
91
|
-
=end
|
|
59
|
+
def recognize_token
|
|
60
|
+
raise NotImplementedError
|
|
92
61
|
end
|
|
93
62
|
|
|
94
63
|
def build_token(aSymbolName, aLexeme, aFormat = :default)
|
|
@@ -105,7 +74,7 @@ class BaseTokenizer
|
|
|
105
74
|
return token
|
|
106
75
|
end
|
|
107
76
|
|
|
108
|
-
def convert_to(aLexeme,
|
|
77
|
+
def convert_to(aLexeme, _symbol_name, _format)
|
|
109
78
|
return aLexeme
|
|
110
79
|
end
|
|
111
80
|
|
|
@@ -124,11 +93,11 @@ class BaseTokenizer
|
|
|
124
93
|
end
|
|
125
94
|
# next_ch = scanner.peek(1)
|
|
126
95
|
# if next_ch == ';'
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
96
|
+
# cmt_found = true
|
|
97
|
+
# scanner.skip(/;[^\r\n]*(?:(?:\r\n)|\r|\n)?/)
|
|
98
|
+
# next_line
|
|
130
99
|
# end
|
|
131
|
-
break unless ws_found
|
|
100
|
+
break unless ws_found || cmt_found
|
|
132
101
|
end
|
|
133
102
|
|
|
134
103
|
curr_pos = scanner.pos
|
|
@@ -140,58 +109,3 @@ class BaseTokenizer
|
|
|
140
109
|
@line_start = scanner.pos
|
|
141
110
|
end
|
|
142
111
|
end # class
|
|
143
|
-
=begin
|
|
144
|
-
require 'base_tokenizer'
|
|
145
|
-
|
|
146
|
-
class PB_Tokenizer < BaseTokenizer
|
|
147
|
-
@@lexeme2name = {
|
|
148
|
-
'(' => 'LPAREN',
|
|
149
|
-
')' => 'RPAREN',
|
|
150
|
-
'+' => 'PLUS',
|
|
151
|
-
}.freeze
|
|
152
|
-
|
|
153
|
-
protected
|
|
154
|
-
|
|
155
|
-
def recognize_token()
|
|
156
|
-
token = nil
|
|
157
|
-
curr_ch = scanner.peek(1)
|
|
158
|
-
|
|
159
|
-
if '()'.include? curr_ch # Single characters
|
|
160
|
-
# Delimiters, separators => single character token
|
|
161
|
-
token = build_token(@@lexeme2name[curr_ch], scanner.getch)
|
|
162
|
-
elsif (lexeme = scanner.scan(/(?:\+)(?=\s)/)) # Single char occurring alone
|
|
163
|
-
token = build_token(@@lexeme2name[lexeme], lexeme)
|
|
164
|
-
elsif (lexeme = scanner.scan(/[+-]?[0-9]+/))
|
|
165
|
-
token = build_token('INTEGER', lexeme)
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
end # class
|
|
169
|
-
|
|
170
|
-
# Basic tokenizer
|
|
171
|
-
# @return [Array<Rley::Lexical::Token>]
|
|
172
|
-
def tokenize(aText)
|
|
173
|
-
tokenizer = PB_Tokenizer.new(aText)
|
|
174
|
-
tokenizer.token
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
=end
|
|
178
|
-
=begin
|
|
179
|
-
# Basic expression tokenizer
|
|
180
|
-
def tokenize(aText)
|
|
181
|
-
tokens = aText.scan(/\S+/).map do |lexeme|
|
|
182
|
-
case lexeme
|
|
183
|
-
when '+', '(', ')'
|
|
184
|
-
terminal = @grammar.name2symbol[lexeme]
|
|
185
|
-
when /^[-+]?\d+$/
|
|
186
|
-
terminal = @grammar.name2symbol['int']
|
|
187
|
-
else
|
|
188
|
-
msg = "Unknown input text '#{lexeme}'"
|
|
189
|
-
raise StandardError, msg
|
|
190
|
-
end
|
|
191
|
-
pos = Rley::Lexical::Position.new(1, 4) # Dummy position
|
|
192
|
-
Rley::Lexical::Token.new(lexeme, terminal, pos)
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
return tokens
|
|
196
|
-
end
|
|
197
|
-
=end
|
data/spec/rley/engine_spec.rb
CHANGED
|
@@ -17,10 +17,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it 'could be created with block argument' do
|
|
20
|
-
expect
|
|
20
|
+
expect do
|
|
21
|
+
Engine.new do |config|
|
|
21
22
|
config.parse_repr = :raw
|
|
22
23
|
end
|
|
23
|
-
|
|
24
|
+
end.not_to raise_error
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
it "shouldn't have a link to a grammar yet" do
|
|
@@ -145,7 +146,6 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
145
146
|
visitor = subject.pforest_visitor(ptree)
|
|
146
147
|
expect(visitor).to be_kind_of(ParseForestVisitor)
|
|
147
148
|
end
|
|
148
|
-
|
|
149
149
|
end # context
|
|
150
150
|
end # describe
|
|
151
151
|
end # module
|
|
@@ -138,6 +138,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
138
138
|
it 'should have shortcut edges' do
|
|
139
139
|
subject.vertices.each do |a_vertex|
|
|
140
140
|
next unless a_vertex.kind_of?(ItemVertex)
|
|
141
|
+
|
|
141
142
|
if a_vertex.next_symbol.kind_of?(Syntax::NonTerminal)
|
|
142
143
|
expect(a_vertex.shortcut).not_to be_nil
|
|
143
144
|
my_d_item = a_vertex.dotted_item
|
|
@@ -179,12 +179,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
179
179
|
expect(children.size).to eq(2)
|
|
180
180
|
},
|
|
181
181
|
->(event, item) {
|
|
182
|
-
|
|
182
|
+
prediction = 'Alt(S => a T .)[0, 4]'
|
|
183
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
183
184
|
check_legs(['Alt(S => a T .)[0, 4]', 6]) # 2 * 3
|
|
184
185
|
check_node_accesses(item, [6])
|
|
185
186
|
},
|
|
186
187
|
->(event, parent, children) {
|
|
187
|
-
|
|
188
|
+
prediction = 'Alt(S => a T .)[0, 4]'
|
|
189
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
188
190
|
expect(children.size).to eq(2)
|
|
189
191
|
},
|
|
190
192
|
->(event, item) {
|
|
@@ -220,27 +222,31 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
220
222
|
->(event, item) {
|
|
221
223
|
check_event(event, item, [:after_terminal, 'b[3, 4]'])
|
|
222
224
|
},
|
|
223
|
-
->(event, parent,
|
|
225
|
+
->(event, parent, _children) {
|
|
224
226
|
check_event(event, parent, [:after_subnodes, 'T[1, 4]'])
|
|
225
227
|
},
|
|
226
228
|
->(event, item) {
|
|
227
229
|
check_event(event, item, [:after_non_terminal, 'T[1, 4]'])
|
|
228
230
|
},
|
|
229
231
|
->(event, parent, children) {
|
|
230
|
-
|
|
232
|
+
prediction = 'Alt(S => a T .)[0, 4]'
|
|
233
|
+
check_event(event, parent, [:after_subnodes, prediction])
|
|
231
234
|
expect(children.size).to eq(2)
|
|
232
235
|
check_legs(['Alt(S => a T .)[0, 4]', 6]) # 2 * 3
|
|
233
236
|
},
|
|
234
237
|
->(event, item) {
|
|
235
|
-
|
|
238
|
+
prediction = 'Alt(S => a T .)[0, 4]'
|
|
239
|
+
check_event(event, item, [:after_alternative, prediction])
|
|
236
240
|
},
|
|
237
241
|
->(event, item) {
|
|
238
|
-
|
|
242
|
+
prediction = 'Alt(S => A T .)[0, 4]'
|
|
243
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
239
244
|
check_legs(['Alt(S => A T .)[0, 4]', 10]) # 2 * 5
|
|
240
245
|
check_node_accesses(item, [10])
|
|
241
246
|
},
|
|
242
247
|
->(event, parent, children) {
|
|
243
|
-
|
|
248
|
+
prediction = 'Alt(S => A T .)[0, 4]'
|
|
249
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
244
250
|
expect(children.size).to eq(2)
|
|
245
251
|
},
|
|
246
252
|
->(event, item) {
|
|
@@ -253,13 +259,15 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
253
259
|
expect(children.size).to eq(2)
|
|
254
260
|
},
|
|
255
261
|
->(event, item) {
|
|
256
|
-
|
|
262
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
263
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
257
264
|
check_legs(['Alt(A => a .)[0, 1]', 7130]) # 2 * 5 * 23 * 31
|
|
258
265
|
check_node_accesses(item, [7130])
|
|
259
266
|
# p(subject.legs)
|
|
260
267
|
},
|
|
261
268
|
->(event, parent, children) {
|
|
262
|
-
|
|
269
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
270
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
263
271
|
expect(children.size).to eq(1)
|
|
264
272
|
},
|
|
265
273
|
->(event, item) {
|
|
@@ -268,20 +276,24 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
268
276
|
->(event, item) {
|
|
269
277
|
check_event(event, item, [:after_terminal, 'a[0, 1]'])
|
|
270
278
|
},
|
|
271
|
-
->(event, parent,
|
|
272
|
-
|
|
279
|
+
->(event, parent, _children) {
|
|
280
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
281
|
+
check_event(event, parent, [:after_subnodes, prediction])
|
|
273
282
|
check_legs(['Alt(A => a .)[0, 1]', 7130]) # 2 * 5 * 23 * 31
|
|
274
283
|
},
|
|
275
284
|
->(event, item) {
|
|
276
|
-
|
|
285
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
286
|
+
check_event(event, item, [:after_alternative, prediction])
|
|
277
287
|
},
|
|
278
288
|
->(event, item) {
|
|
279
|
-
|
|
289
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
290
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
280
291
|
check_legs(['Alt(A => B A .)[0, 1]', 8510]) # 2 * 5 * 23 * 37
|
|
281
292
|
check_node_accesses(item, [8510])
|
|
282
293
|
},
|
|
283
294
|
->(event, parent, children) {
|
|
284
|
-
|
|
295
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
296
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
285
297
|
expect(children.size).to eq(2)
|
|
286
298
|
},
|
|
287
299
|
->(event, item) {
|
|
@@ -299,7 +311,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
299
311
|
->(event, item) {
|
|
300
312
|
check_event(event, item, [:after_epsilon, '_[0, 0]'])
|
|
301
313
|
},
|
|
302
|
-
->(event, parent,
|
|
314
|
+
->(event, parent, _children) {
|
|
303
315
|
check_event(event, parent, [:after_subnodes, 'B[0, 0]'])
|
|
304
316
|
check_legs(['B[0, 0]', 365930]) # 2 * 5 * 23 * 37 * 43
|
|
305
317
|
},
|
|
@@ -316,12 +328,15 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
316
328
|
expect(children.size).to eq(2)
|
|
317
329
|
},
|
|
318
330
|
->(event, item) {
|
|
319
|
-
|
|
320
|
-
|
|
331
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
332
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
333
|
+
# 12399070 = 2 * 5 * 23 * 37 * 47 * 31
|
|
334
|
+
check_legs(['Alt(A => a .)[0, 1]', 12399070])
|
|
321
335
|
check_node_accesses(item, [7130, 12399070])
|
|
322
336
|
},
|
|
323
337
|
->(event, parent, children) {
|
|
324
|
-
|
|
338
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
339
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
325
340
|
expect(children.size).to eq(1)
|
|
326
341
|
},
|
|
327
342
|
->(event, item) {
|
|
@@ -330,21 +345,26 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
330
345
|
->(event, item) {
|
|
331
346
|
check_event(event, item, [:after_terminal, 'a[0, 1]'])
|
|
332
347
|
},
|
|
333
|
-
->(event, parent,
|
|
348
|
+
->(event, parent, _children) {
|
|
334
349
|
check_event(event, parent, [:after_subnodes, 'Alt(A => a .)[0, 1]'])
|
|
335
|
-
|
|
350
|
+
# 12399070 = 2 * 5 * 23 * 37 * 47 * 31
|
|
351
|
+
check_legs(['Alt(A => a .)[0, 1]', 12399070])
|
|
336
352
|
},
|
|
337
353
|
->(event, item) {
|
|
338
|
-
|
|
354
|
+
prediction = 'Alt(A => a .)[0, 1]'
|
|
355
|
+
check_event(event, item, [:after_alternative, prediction])
|
|
339
356
|
},
|
|
340
357
|
->(event, item) {
|
|
341
|
-
|
|
342
|
-
|
|
358
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
359
|
+
check_event(event, item, [:before_alternative, prediction])
|
|
360
|
+
# For prime factoring:
|
|
361
|
+
# https://www.calculatorsoup.com/calculators/math/prime-factors.php
|
|
343
362
|
check_legs(['Alt(A => B A .)[0, 1]', 399970]) # 2 * 5 * 23 * 37 * 47
|
|
344
363
|
check_node_accesses(item, [8510, 399970])
|
|
345
364
|
},
|
|
346
365
|
->(event, parent, children) {
|
|
347
|
-
|
|
366
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
367
|
+
check_event(event, parent, [:before_subnodes, prediction])
|
|
348
368
|
expect(children.size).to eq(2)
|
|
349
369
|
},
|
|
350
370
|
->(event, item) {
|
|
@@ -362,36 +382,40 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
362
382
|
->(event, item) {
|
|
363
383
|
check_event(event, item, [:after_epsilon, '_[0, 0]'])
|
|
364
384
|
},
|
|
365
|
-
|
|
385
|
+
->(event, parent, _children) {
|
|
366
386
|
check_event(event, parent, [:after_subnodes, 'B[0, 0]'])
|
|
367
387
|
check_legs(['B[0, 0]', 17198710]) # 2 * 5 * 23 * 37 * 43 * 47
|
|
368
388
|
},
|
|
369
389
|
->(event, item) {
|
|
370
390
|
check_event(event, item, [:after_non_terminal, 'B[0, 0]'])
|
|
371
391
|
},
|
|
372
|
-
->(event, parent,
|
|
373
|
-
|
|
392
|
+
->(event, parent, _children) {
|
|
393
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
394
|
+
check_event(event, parent, [:after_subnodes, prediction])
|
|
374
395
|
check_legs(['Alt(A => B A .)[0, 1]', 399970]) # 2 * 5 * 23 * 37 * 47
|
|
375
396
|
check_node_accesses(parent, [8510, 399970])
|
|
376
397
|
},
|
|
377
398
|
->(event, item) {
|
|
378
|
-
|
|
399
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
400
|
+
check_event(event, item, [:after_alternative, prediction])
|
|
379
401
|
},
|
|
380
|
-
->(event, parent,
|
|
402
|
+
->(event, parent, _children) {
|
|
381
403
|
check_event(event, parent, [:after_subnodes, 'A[0, 1]'])
|
|
382
404
|
check_legs(['A[0, 1]', 399970]) # 2 * 5 * 23 * 37 * 47
|
|
383
405
|
},
|
|
384
406
|
->(event, item) {
|
|
385
407
|
check_event(event, item, [:after_non_terminal, 'A[0, 1]'])
|
|
386
408
|
},
|
|
387
|
-
->(event, parent,
|
|
388
|
-
|
|
409
|
+
->(event, parent, _children) {
|
|
410
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
411
|
+
check_event(event, parent, [:after_subnodes, prediction])
|
|
389
412
|
check_legs(['Alt(A => B A .)[0, 1]', 8510]) # 2 * 5 * 23 * 37
|
|
390
413
|
},
|
|
391
414
|
->(event, item) {
|
|
392
|
-
|
|
415
|
+
prediction = 'Alt(A => B A .)[0, 1]'
|
|
416
|
+
check_event(event, item, [:after_alternative, prediction])
|
|
393
417
|
},
|
|
394
|
-
->(event, parent,
|
|
418
|
+
->(event, parent, _children) {
|
|
395
419
|
check_event(event, parent, [:after_subnodes, 'A[0, 1]'])
|
|
396
420
|
check_legs(['A[0, 1]', 230]) # 2 * 5 * 23
|
|
397
421
|
},
|
|
@@ -425,19 +449,20 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
425
449
|
->(event, item) {
|
|
426
450
|
check_event(event, item, [:after_terminal, 'b[3, 4]'])
|
|
427
451
|
},
|
|
428
|
-
->(event, parent,
|
|
452
|
+
->(event, parent, _children) {
|
|
429
453
|
check_event(event, parent, [:after_subnodes, 'T[1, 4]'])
|
|
430
454
|
},
|
|
431
455
|
->(event, item) {
|
|
432
456
|
check_event(event, item, [:after_non_terminal, 'T[1, 4]'])
|
|
433
457
|
},
|
|
434
458
|
->(event, parent, children) {
|
|
435
|
-
|
|
459
|
+
prediction = 'Alt(S => A T .)[0, 4]'
|
|
460
|
+
check_event(event, parent, [:after_subnodes, prediction])
|
|
436
461
|
expect(children.size).to eq(2)
|
|
437
462
|
check_legs(['Alt(S => A T .)[0, 4]', 10]) # 2 * 5
|
|
438
463
|
},
|
|
439
|
-
->(
|
|
440
|
-
check_event(
|
|
464
|
+
->(evt, itm) {
|
|
465
|
+
check_event(evt, itm, [:after_alternative, 'Alt(S => A T .)[0, 4]'])
|
|
441
466
|
},
|
|
442
467
|
->(event, parent, children) {
|
|
443
468
|
check_event(event, parent, [:after_subnodes, 'S[0, 4]'])
|
|
@@ -447,7 +472,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
|
447
472
|
->(event, item) {
|
|
448
473
|
check_event(event, item, [:after_non_terminal, 'S[0, 4]'])
|
|
449
474
|
},
|
|
450
|
-
|
|
475
|
+
->(event, parent, children) {
|
|
451
476
|
check_event(event, parent, [:after_subnodes, 'Phi[0, 4]'])
|
|
452
477
|
expect(children.size).to eq(1)
|
|
453
478
|
},
|