rley 0.8.01 → 0.8.02
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 +29 -5
- data/CHANGELOG.md +7 -0
- data/examples/NLP/pico_en_demo.rb +2 -2
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/notation/all_notation_nodes.rb +3 -1
- data/lib/rley/notation/ast_builder.rb +185 -191
- data/lib/rley/notation/ast_node.rb +5 -5
- data/lib/rley/notation/ast_visitor.rb +3 -1
- data/lib/rley/notation/grammar.rb +1 -1
- data/lib/rley/notation/grammar_builder.rb +16 -15
- data/lib/rley/notation/grouping_node.rb +1 -1
- data/lib/rley/notation/parser.rb +56 -56
- data/lib/rley/notation/sequence_node.rb +3 -3
- data/lib/rley/notation/symbol_node.rb +2 -2
- data/lib/rley/notation/tokenizer.rb +3 -15
- data/lib/rley/parse_rep/ast_base_builder.rb +5 -6
- data/lib/rley/parser/gfg_chart.rb +5 -4
- data/lib/rley/parser/gfg_earley_parser.rb +1 -1
- data/lib/rley/syntax/base_grammar_builder.rb +3 -3
- data/lib/rley/syntax/match_closest.rb +7 -7
- data/spec/rley/notation/grammar_builder_spec.rb +6 -6
- data/spec/rley/notation/parser_spec.rb +183 -184
- data/spec/rley/notation/tokenizer_spec.rb +98 -104
- data/spec/rley/parser/dangling_else_spec.rb +15 -13
- data/spec/rley/parser/gfg_earley_parser_spec.rb +11 -9
- data/spec/rley/parser/gfg_parsing_spec.rb +1 -0
- data/spec/rley/syntax/base_grammar_builder_spec.rb +0 -1
- data/spec/rley/syntax/match_closest_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 490bce9cb193d9e7b49222e8e1bae90d0dba64e663990cacef56ea69881c418a
|
4
|
+
data.tar.gz: 2f9380c53ff442992acb2629ab1f197078e0b403f373a2ed394a1cbfca85bc2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1ffe315ef7ddbb50e18244e233320ac592347997a7a84ce55545d24564e39aeeda56f5002e4645cac54e7e91dfa1ac79bc0567592e84720113622e3976539e
|
7
|
+
data.tar.gz: e7272a73b9f2359564d6783a5b0d8f38564ea9788cd7e568a4207de0176233bf0b29f7b37be991dc039dea45e5795d2eb59f7e8751940302c59d02dc23f33b85
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
- '
|
4
|
-
- '
|
3
|
+
- 'examples/**/*'
|
4
|
+
- 'exp/**/*'
|
5
5
|
|
6
6
|
Gemspec/DateAssignment:
|
7
7
|
Enabled: true
|
@@ -50,6 +50,9 @@ Layout/IndentationConsistency:
|
|
50
50
|
Layout/HeredocIndentation:
|
51
51
|
Enabled: false
|
52
52
|
|
53
|
+
Layout/LineEndStringConcatenationIndentation:
|
54
|
+
Enabled: true
|
55
|
+
|
53
56
|
Layout/MultilineHashBraceLayout:
|
54
57
|
Enabled: true
|
55
58
|
|
@@ -81,6 +84,9 @@ Layout/TrailingWhitespace:
|
|
81
84
|
Lint/AmbiguousAssignment:
|
82
85
|
Enabled: true
|
83
86
|
|
87
|
+
Lint/AmbiguousRange:
|
88
|
+
Enabled: true
|
89
|
+
|
84
90
|
Lint/DeprecatedConstants:
|
85
91
|
Enabled: true
|
86
92
|
|
@@ -96,6 +102,9 @@ Lint/EmptyBlock:
|
|
96
102
|
Lint/EmptyClass:
|
97
103
|
Enabled: false
|
98
104
|
|
105
|
+
Lint/EmptyInPattern:
|
106
|
+
Enabled: true
|
107
|
+
|
99
108
|
Lint/LambdaWithoutLiteralBlock:
|
100
109
|
Enabled: true
|
101
110
|
|
@@ -192,6 +201,9 @@ Naming/ClassAndModuleCamelCase:
|
|
192
201
|
Naming/BlockParameterName:
|
193
202
|
Enabled: true
|
194
203
|
|
204
|
+
Naming/InclusiveLanguage:
|
205
|
+
Enabled: true
|
206
|
+
|
195
207
|
Naming/MethodParameterName:
|
196
208
|
Enabled: false
|
197
209
|
|
@@ -201,9 +213,6 @@ Naming/MethodName:
|
|
201
213
|
Naming/VariableName:
|
202
214
|
Enabled: false
|
203
215
|
|
204
|
-
Style/AccessorGrouping:
|
205
|
-
Enabled: false
|
206
|
-
|
207
216
|
Style/Alias:
|
208
217
|
Enabled: true
|
209
218
|
|
@@ -276,11 +285,17 @@ Style/HashTransformValues:
|
|
276
285
|
Style/IfUnlessModifier:
|
277
286
|
Enabled: false
|
278
287
|
|
288
|
+
Style/InPatternThen:
|
289
|
+
Enabled: true
|
290
|
+
|
279
291
|
Style/InverseMethods:
|
280
292
|
Enabled: false
|
281
293
|
|
282
294
|
Style/MissingRespondToMissing:
|
283
295
|
Enabled: false
|
296
|
+
|
297
|
+
Style/MultilineInPatternThen:
|
298
|
+
Enabled: true
|
284
299
|
|
285
300
|
Style/NegatedIfElseCondition:
|
286
301
|
Enabled: true
|
@@ -293,6 +308,9 @@ Style/NilLambda:
|
|
293
308
|
|
294
309
|
Style/NumericLiterals:
|
295
310
|
Enabled: false
|
311
|
+
|
312
|
+
Style/QuotedSymbols:
|
313
|
+
Enabled: true
|
296
314
|
|
297
315
|
Style/RaiseArgs:
|
298
316
|
Enabled: true
|
@@ -305,6 +323,9 @@ Style/RedundantReturn:
|
|
305
323
|
|
306
324
|
Style/RedundantSelf:
|
307
325
|
Enabled: true
|
326
|
+
|
327
|
+
Style/RedundantSelfAssignmentBranch:
|
328
|
+
Enabled: true
|
308
329
|
|
309
330
|
Style/RegexpLiteral:
|
310
331
|
Enabled: false
|
@@ -367,6 +388,9 @@ Lint/TopLevelReturnWithArgument:
|
|
367
388
|
Lint/UnreachableLoop:
|
368
389
|
Enabled: true
|
369
390
|
|
391
|
+
Style/AccessorGrouping:
|
392
|
+
Enabled: true
|
393
|
+
|
370
394
|
Style/ArrayCoercion:
|
371
395
|
Enabled: true
|
372
396
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.8.02 / 2021-08-23
|
2
|
+
- Code restyling to please Rubocop 1.19.1
|
3
|
+
|
4
|
+
* [CHANGE] File `.rubocp.yml` updated to take into account new cops.
|
5
|
+
* [CHANGE] File `*.rb` files updated to fix Rubocop findings
|
6
|
+
|
7
|
+
|
1
8
|
### 0.8.01 / 2021-08-22
|
2
9
|
- Unused/redundant file removal. Fix in rule generation
|
3
10
|
|
@@ -26,8 +26,8 @@ engine.build_grammar do
|
|
26
26
|
rule 'S' => 'NP VP'
|
27
27
|
rule 'NP' => 'Proper-Noun'
|
28
28
|
rule 'NP' => 'Determiner Noun'
|
29
|
-
rule 'NP' => 'Determiner Noun PP'
|
30
|
-
rule 'VP' => 'Verb NP'
|
29
|
+
rule 'NP' => 'Determiner Noun PP'
|
30
|
+
rule 'VP' => 'Verb NP'
|
31
31
|
rule 'VP' => 'Verb NP PP'
|
32
32
|
rule 'PP' => 'Preposition NP'
|
33
33
|
end
|
data/lib/rley/constants.rb
CHANGED
@@ -1,191 +1,185 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../parse_rep/ast_base_builder'
|
4
|
-
require_relative '../engine'
|
5
|
-
require_relative 'all_notation_nodes'
|
6
|
-
|
7
|
-
module Rley
|
8
|
-
module Notation
|
9
|
-
# The purpose of ASTBuilder is to build piece by piece an AST
|
10
|
-
# (Abstract Syntax Tree) from a sequence of input tokens and
|
11
|
-
# visit events produced by walking over a GFGParsing object.
|
12
|
-
class ASTBuilder < Rley::ParseRep::ASTBaseBuilder
|
13
|
-
unless defined?(Name2special)
|
14
|
-
# Mapping Token name => operator | separator | delimiter characters
|
15
|
-
# @return [Hash{String => String}]
|
16
|
-
Name2special = {
|
17
|
-
'COMMA' => ',',
|
18
|
-
'ELLIPSIS' => '..',
|
19
|
-
'LEFT_BRACE' => '{',
|
20
|
-
'LEFT_PAREN' => '(',
|
21
|
-
'PLUS' => '+',
|
22
|
-
'QUESTION_MARK' => '?',
|
23
|
-
'RIGHT_BRACE' => '}',
|
24
|
-
'RIGHT_PAREN' => ')',
|
25
|
-
'STAR' => '*'
|
26
|
-
}.freeze
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
# rule('
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
theChildren[
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
key
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
[
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
Range.new(low.to_i, high.to_i)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end # class
|
190
|
-
end # module
|
191
|
-
end # module
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../parse_rep/ast_base_builder'
|
4
|
+
require_relative '../engine'
|
5
|
+
require_relative 'all_notation_nodes'
|
6
|
+
|
7
|
+
module Rley
|
8
|
+
module Notation
|
9
|
+
# The purpose of ASTBuilder is to build piece by piece an AST
|
10
|
+
# (Abstract Syntax Tree) from a sequence of input tokens and
|
11
|
+
# visit events produced by walking over a GFGParsing object.
|
12
|
+
class ASTBuilder < Rley::ParseRep::ASTBaseBuilder
|
13
|
+
unless defined?(Name2special)
|
14
|
+
# Mapping Token name => operator | separator | delimiter characters
|
15
|
+
# @return [Hash{String => String}]
|
16
|
+
Name2special = {
|
17
|
+
'COMMA' => ',',
|
18
|
+
'ELLIPSIS' => '..',
|
19
|
+
'LEFT_BRACE' => '{',
|
20
|
+
'LEFT_PAREN' => '(',
|
21
|
+
'PLUS' => '+',
|
22
|
+
'QUESTION_MARK' => '?',
|
23
|
+
'RIGHT_BRACE' => '}',
|
24
|
+
'RIGHT_PAREN' => ')',
|
25
|
+
'STAR' => '*'
|
26
|
+
}.freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def terminal2node
|
32
|
+
Terminal2NodeClass
|
33
|
+
end
|
34
|
+
|
35
|
+
# Method override
|
36
|
+
def new_leaf_node(_production, _terminal, aTokenPosition, aToken)
|
37
|
+
Rley::PTree::TerminalNode.new(aToken, aTokenPosition)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Factory method for creating a parent node object.
|
41
|
+
# @param aProduction [Production] Production rule
|
42
|
+
# @param aRange [Range] Range of tokens matched by the rule
|
43
|
+
# @param theTokens [Array] The input tokens
|
44
|
+
# @param theChildren [Array] Children nodes (one per rhs symbol)
|
45
|
+
def new_parent_node(aProduction, aRange, theTokens, theChildren)
|
46
|
+
mth_name = method_name(aProduction.name)
|
47
|
+
if respond_to?(mth_name, true)
|
48
|
+
node = send(mth_name, aProduction, aRange, theTokens, theChildren)
|
49
|
+
else
|
50
|
+
# Default action...
|
51
|
+
node = case aProduction.rhs.size
|
52
|
+
when 0
|
53
|
+
return_epsilon(aRange, theTokens, theChildren)
|
54
|
+
when 1
|
55
|
+
return_first_child(aRange, theTokens, theChildren)
|
56
|
+
else
|
57
|
+
node = Rley::PTree::NonTerminalNode.new(aProduction.lhs, aRange)
|
58
|
+
theChildren&.reverse_each do |child|
|
59
|
+
node.add_subnode(child) if child
|
60
|
+
end
|
61
|
+
|
62
|
+
node
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
node
|
67
|
+
end
|
68
|
+
|
69
|
+
# Return the AST node corresponding to the second symbol in the rhs
|
70
|
+
def reduce_to_2nd_symbol(_production, _range, _tokens, theChildren)
|
71
|
+
theChildren[1]
|
72
|
+
end
|
73
|
+
|
74
|
+
#####################################
|
75
|
+
# SEMANTIC ACTIONS
|
76
|
+
#####################################
|
77
|
+
|
78
|
+
# rule('rhs' => 'member_seq').tag 'sequence'
|
79
|
+
def reduce_sequence(_production, _range, _tokens, theChildren)
|
80
|
+
if theChildren[0].size == 1
|
81
|
+
theChildren[0].first
|
82
|
+
else
|
83
|
+
SequenceNode.new(theChildren[0].first.position, theChildren[0], nil)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# rule('member_seq' => 'member_seq member').tag 'more_members'
|
88
|
+
def reduce_more_members(_production, _range, _tokens, theChildren)
|
89
|
+
theChildren[0] << theChildren[1]
|
90
|
+
end
|
91
|
+
|
92
|
+
# rule('member_seq' => 'member')
|
93
|
+
def reduce_one_member(_production, _range, _tokens, theChildren)
|
94
|
+
[theChildren[0]]
|
95
|
+
end
|
96
|
+
|
97
|
+
# rule('strait_member' => 'base_member annotation')
|
98
|
+
def reduce_annotated_member(_production, _range, _tokens, theChildren)
|
99
|
+
theChildren[0].annotation = theChildren[1]
|
100
|
+
|
101
|
+
theChildren[0]
|
102
|
+
end
|
103
|
+
|
104
|
+
# rule('base_member' => 'SYMBOL')
|
105
|
+
def reduce_symbol(_production, _range, _tokens, theChildren)
|
106
|
+
SymbolNode.new(theChildren[0].token.position, theChildren[0].token.lexeme)
|
107
|
+
end
|
108
|
+
|
109
|
+
# rule('base_member' => 'LEFT_PAREN member_seq RIGHT_PAREN')
|
110
|
+
def reduce_grouping(_production, _range, tokens, theChildren)
|
111
|
+
if theChildren[1].size == 1
|
112
|
+
theChildren[1].first
|
113
|
+
else
|
114
|
+
rank = theChildren[0].range.high
|
115
|
+
pos = tokens[rank].position
|
116
|
+
GroupingNode.new(pos, theChildren[1], nil)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# rule('quantified_member' => 'base_member quantifier')
|
121
|
+
def reduce_quantified_member(_production, _range, _tokens, theChildren)
|
122
|
+
theChildren[0].repetition = theChildren[1]
|
123
|
+
theChildren[0]
|
124
|
+
end
|
125
|
+
|
126
|
+
# rule('quantifier' => 'QUESTION_MARK')
|
127
|
+
def reduce_question_mark(_production, _range, _tokens, _theChildren)
|
128
|
+
:zero_or_one
|
129
|
+
end
|
130
|
+
|
131
|
+
# rule('quantifier' => 'STAR')
|
132
|
+
def reduce_star(_production, _range, _tokens, _theChildren)
|
133
|
+
:zero_or_more
|
134
|
+
end
|
135
|
+
|
136
|
+
# rule('quantifier' => 'PLUS')
|
137
|
+
def reduce_plus(_production, _range, _tokens, _theChildren)
|
138
|
+
:one_or_more
|
139
|
+
end
|
140
|
+
|
141
|
+
# rule('annotation' => 'LEFT_BRACE mapping RIGHT_BRACE').tag ''
|
142
|
+
def reduce_annotation(_production, _range, _tokens, theChildren)
|
143
|
+
theChildren[1]
|
144
|
+
end
|
145
|
+
|
146
|
+
# rule('mapping' => 'mapping COMMA key_value')
|
147
|
+
def reduce_more_pairs(_production, _range, _tokens, theChildren)
|
148
|
+
hsh = theChildren[0]
|
149
|
+
hsh[theChildren[2].first] = theChildren[2].last
|
150
|
+
|
151
|
+
hsh
|
152
|
+
end
|
153
|
+
|
154
|
+
# rule('mapping' => 'key_value').tag 'one_pair'
|
155
|
+
def reduce_one_pair(_production, _range, _tokens, theChildren)
|
156
|
+
{ theChildren[0].first => theChildren[0].last }
|
157
|
+
end
|
158
|
+
|
159
|
+
# rule('key_value' => 'KEY value')
|
160
|
+
def reduce_raw_pair(_production, _range, _tokens, theChildren)
|
161
|
+
key = theChildren[0].token.lexeme
|
162
|
+
value = if theChildren[1].kind_of?(Rley::PTree::TerminalNode)
|
163
|
+
theChildren[1].token.lexeme
|
164
|
+
else
|
165
|
+
theChildren[1]
|
166
|
+
end
|
167
|
+
[key, value]
|
168
|
+
end
|
169
|
+
|
170
|
+
# rule('range' => 'INT_LIT ELLIPSIS INT_LIT')
|
171
|
+
def reduce_bound_range(_production, _range, _tokens, theChildren)
|
172
|
+
low = theChildren[0].token.lexeme
|
173
|
+
high = theChildren[2].token.lexeme
|
174
|
+
case [low, high]
|
175
|
+
when %w[0 1]
|
176
|
+
:zero_or_one
|
177
|
+
when %w[1 1]
|
178
|
+
:exactly_one
|
179
|
+
else
|
180
|
+
Range.new(low.to_i, high.to_i)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end # class
|
184
|
+
end # module
|
185
|
+
end # module
|