skeem 0.2.18 → 0.2.19

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
  SHA256:
3
- metadata.gz: 8031a69d8a362bbe17e4dabe5fb6ced12ff4ca70f2d6577f5ec13ff81b8bd3ad
4
- data.tar.gz: 17f74953cc15cd97d84ede36c17f9d4e97873710d8c94ecfdb50e76019cf3bd2
3
+ metadata.gz: 6ab3868544bc84674f7828b4bf258177afc7f1192ca46ea3979328ca4a410a8c
4
+ data.tar.gz: 178e5b66fed7677ef7f7a6409cd7c8fb91284654622935389cd3a0c4009b3fed
5
5
  SHA512:
6
- metadata.gz: 65521fe50624af6e01bacb890ae3b1ddf9f6acb5a1a3a31fd5cfb1b20143101c0aad531a1f3773b50585a6bed8a18380897f47786ecfdc3c53140e7686e17876
7
- data.tar.gz: 3a5d8cac363099882da772135498df5c24449eedc6831a2fe09f840764afd12d22ad4fa74589dd92309875407cf77a334fc704d6914a93988debfd65b31a2d35
6
+ metadata.gz: 33868367a6683ed547c5ebe19cbad9e2dee76c6b0dbd07e4a0077b6012b698a8e8d551095e82484911a71df0590f373d24e7b11a334fa760c23507e030a44314
7
+ data.tar.gz: f9726a3849a9eee31061404cf900e9529fa07db9d63663b9334105397b4c02fe2754951561049419c5e436cf846635548cd15c02e006e17ad4170e33a24be487
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.2.19] - 2021-08-30
2
+ - Grammar refactoring: use ?, * and + modifiers in Rley 0.8.03 rules
3
+
4
+ ### Changed
5
+ - File `grammar.rb`: Remove redundant rules after introduction og ?, * and + modifiers
6
+ - Class `SkmBuilder`: Removal of useless methods after removal of their rule counterpart
7
+
8
+
9
+
1
10
  ## [0.2.18] - 2021-08-29
2
11
  - Minor refactoring for Rley 0.8.03
3
12
  - Code restyling to please rubocop 1.19.1.
data/lib/skeem/grammar.rb CHANGED
@@ -36,7 +36,7 @@ module Skeem
36
36
  rule('definition' => 'LPAREN DEFINE IDENTIFIER expression RPAREN').as 'definition'
37
37
  rule('definition' => 'LPAREN DEFINE LPAREN IDENTIFIER def_formals RPAREN body RPAREN').as 'alt_definition'
38
38
  rule('definition' => 'syntax_definition')
39
- rule('definition' => 'LPAREN BEGIN definition_star RPAREN').as 'definitions_within_begin'
39
+ rule('definition' => 'LPAREN BEGIN definition* RPAREN').as 'definitions_within_begin'
40
40
  rule('expression' => 'IDENTIFIER').as 'variable_reference'
41
41
  rule 'expression' => 'literal'
42
42
  rule 'expression' => 'procedure_call'
@@ -63,143 +63,104 @@ module Skeem
63
63
  rule 'simple_datum' => 'symbol'
64
64
  rule 'compound_datum' => 'list'
65
65
  rule 'compound_datum' => 'vector'
66
- rule('list' => 'LPAREN datum_star RPAREN').as 'list'
66
+ rule('list' => 'LPAREN datum* RPAREN').as 'list'
67
67
  rule('list' => 'LPAREN datum_plus PERIOD datum RPAREN').as 'dotted_list'
68
- rule('vector' => 'VECTOR_BEGIN datum_star RPAREN').as 'vector'
68
+ rule('vector' => 'VECTOR_BEGIN datum* RPAREN').as 'vector'
69
69
  rule('datum_plus' => 'datum_plus datum').as 'multiple_datums'
70
70
  rule('datum_plus' => 'datum').as 'last_datum'
71
- rule('datum_star' => 'datum_star datum').as 'star_default'
72
- rule('datum_star' => []).as 'star_base' ## 'no_datum_yet'
73
71
  rule 'symbol' => 'IDENTIFIER'
74
72
  rule('procedure_call' => 'LPAREN operator RPAREN').as 'proc_call_nullary'
75
- rule('procedure_call' => 'LPAREN operator operand_plus RPAREN').as 'proc_call_args'
76
- rule('operand_plus' => 'operand_plus operand').as 'multiple_operands'
77
- rule('operand_plus' => 'operand').as 'last_operand'
73
+ rule('procedure_call' => 'LPAREN operator operand+ RPAREN').as 'proc_call_args'
78
74
  rule 'operator' => 'expression'
79
75
  rule 'operand' => 'expression'
80
- rule('def_formals' => 'identifier_star').as 'def_formals'
81
- rule('def_formals' => 'identifier_star PERIOD IDENTIFIER').as 'pair_formals'
76
+ rule('def_formals' => 'IDENTIFIER*').as 'def_formals'
77
+ rule('def_formals' => 'IDENTIFIER* PERIOD IDENTIFIER').as 'pair_formals'
82
78
  rule('lambda_expression' => 'LPAREN LAMBDA formals body RPAREN').as 'lambda_expression'
83
- rule('formals' => 'LPAREN identifier_star RPAREN').as 'fixed_arity_formals'
79
+ rule('formals' => 'LPAREN IDENTIFIER* RPAREN').as 'fixed_arity_formals'
84
80
  rule('formals' => 'IDENTIFIER').as 'variadic_formals'
85
- rule('formals' => 'LPAREN identifier_plus PERIOD IDENTIFIER RPAREN').as 'dotted_formals'
81
+ rule('formals' => 'LPAREN IDENTIFIER+ PERIOD IDENTIFIER RPAREN').as 'dotted_formals'
86
82
  rule('syntax_definition' => 'LPAREN DEFINE-SYNTAX keyword transformer_spec RPAREN').as 'syntax_definition'
87
- rule('identifier_star' => 'identifier_star IDENTIFIER').as 'star_default'
88
- rule('identifier_star' => []).as 'star_base' ## 'no_identifier_yet'
89
- rule('identifier_plus' => 'identifier_plus IDENTIFIER').as 'multiple_identifiers'
90
- rule('identifier_plus' => 'IDENTIFIER').as 'last_identifier'
91
- rule('body' => 'definition_star sequence').as 'body'
92
- rule('definition_star' => 'definition_star definition').as 'star_default'
93
- rule('definition_star' => []).as 'star_base' ## 'no_definition_yet'
94
- rule('sequence' => 'command_star expression').as 'sequence'
95
- rule('command_star' => 'command_star command').as 'star_default'
96
- rule('command_star' => []).as 'star_base' ## 'no_command_yet'
97
- rule('conditional' => 'LPAREN IF test consequent alternate RPAREN').as 'conditional'
83
+ rule('body' => 'definition* sequence').as 'body'
84
+ rule('sequence' => 'command* expression').as 'sequence'
85
+ rule('conditional' => 'LPAREN IF test consequent expression? RPAREN').as 'conditional'
98
86
  rule 'test' => 'expression'
99
87
  rule 'consequent' => 'expression'
100
- rule 'alternate' => 'expression'
101
- rule 'alternate' => []
102
88
  rule 'number' => 'INTEGER'
103
89
  rule 'number' => 'RATIONAL'
104
90
  rule 'number' => 'REAL'
105
91
  rule('assignment' => 'LPAREN SET! IDENTIFIER expression RPAREN').as 'assignment'
106
- rule('derived_expression' => 'LPAREN COND cond_clause_plus RPAREN').as 'cond_form'
107
- rule('derived_expression' => 'LPAREN COND cond_clause_star LPAREN ELSE sequence RPAREN RPAREN').as 'cond_else_form'
108
- rule('derived_expression' => 'LPAREN LET LPAREN binding_spec_star RPAREN body RPAREN').as 'short_let_form'
92
+ rule('derived_expression' => 'LPAREN COND cond_clause+ RPAREN').as 'cond_form'
93
+ rule('derived_expression' => 'LPAREN COND cond_clause* LPAREN ELSE sequence RPAREN RPAREN').as 'cond_else_form'
94
+ rule('derived_expression' => 'LPAREN LET LPAREN binding_spec* RPAREN body RPAREN').as 'short_let_form'
109
95
  # TODO: implement "named let"
110
- rule('derived_expression' => 'LPAREN LET IDENTIFIER LPAREN binding_spec_star RPAREN body RPAREN') # .as 'named_form'
111
- rule('derived_expression' => 'LPAREN LET_STAR LPAREN binding_spec_star RPAREN body RPAREN').as 'let_star_form'
96
+ rule('derived_expression' => 'LPAREN LET IDENTIFIER LPAREN binding_spec* RPAREN body RPAREN') # .as 'named_form'
97
+ rule('derived_expression' => 'LPAREN LET_STAR LPAREN binding_spec* RPAREN body RPAREN').as 'let_star_form'
112
98
 
113
99
  # As the R7RS grammar is too restrictive,
114
100
  # the next rule was made more general than its standard counterpart
115
101
  rule('derived_expression' => 'LPAREN BEGIN body RPAREN').as 'begin_expression'
116
102
  do_syntax = <<-END_SYNTAX
117
- LPAREN DO LPAREN iteration_spec_star RPAREN
103
+ LPAREN DO LPAREN iteration_spec* RPAREN
118
104
  LPAREN test do_result RPAREN
119
105
  command_star RPAREN
120
106
  END_SYNTAX
121
107
  rule('derived_expression' => do_syntax).as 'do_expression'
122
108
  rule 'derived_expression' => 'quasiquotation'
123
- rule('cond_clause_plus' => 'cond_clause_plus cond_clause').as 'multiple_cond_clauses'
124
- rule('cond_clause_plus' => 'cond_clause').as 'last_cond_clauses'
125
- rule('cond_clause_star' => 'cond_clause_star cond_clause').as 'star_default'
126
- rule('cond_clause_star' => []).as 'star_base' ## 'last_cond_clauses_star'
127
109
  rule('cond_clause' => 'LPAREN test sequence RPAREN').as 'cond_clause'
128
110
  rule('cond_clause' => 'LPAREN test RPAREN')
129
111
  rule('cond_clause' => 'LPAREN test ARROW recipient RPAREN').as 'cond_arrow_clause'
130
112
  rule('recipient' => 'expression')
131
113
  rule('quasiquotation' => 'LPAREN QUASIQUOTE qq_template RPAREN').as 'quasiquotation'
132
114
  rule('quasiquotation' => 'GRAVE_ACCENT qq_template').as 'quasiquotation_short'
133
- rule('binding_spec_star' => 'binding_spec_star binding_spec').as 'star_default'
134
- rule('binding_spec_star' => []).as 'star_base' ## 'no_binding_spec_yet'
135
115
  rule('binding_spec' => 'LPAREN IDENTIFIER expression RPAREN').as 'binding_spec'
136
- rule('iteration_spec_star' => 'iteration_spec_star iteration_spec').as 'star_default'
137
- rule('iteration_spec_star' => []).as 'star_base' ## 'no_iter_spec_yet'
138
116
  rule('iteration_spec' => 'LPAREN IDENTIFIER init step RPAREN').as 'iteration_spec_long'
139
117
  rule('iteration_spec' => 'LPAREN IDENTIFIER init RPAREN').as 'iteration_spec_short'
140
118
  rule('init' => 'expression')
141
119
  rule('step' => 'expression')
142
- rule 'do_result' => 'sequence'
143
- rule('do_result' => []).as 'star_base' ## 'empty_do_result'
120
+ rule 'do_result' => 'sequence?'
144
121
  rule('keyword' => 'IDENTIFIER')
145
- rule('includer' => 'LPAREN INCLUDE string_plus RPAREN').as 'include'
146
- rule('string_plus' => 'string_plus STRING_LIT').as 'multiple_string'
147
- rule('string_plus' => 'STRING_LIT').as 'last_single_string'
122
+ rule('includer' => 'LPAREN INCLUDE STRING_LIT+ RPAREN').as 'include'
148
123
  rule 'qq_template' => 'simple_datum'
149
124
  rule 'qq_template' => 'list_qq_template'
150
125
  rule 'qq_template' => 'vector_qq_template'
151
126
  rule 'qq_template' => 'unquotation'
152
- rule('list_qq_template' => 'LPAREN qq_template_or_splice_star RPAREN').as 'list_qq'
153
- rule 'list_qq_template' => 'LPAREN qq_template_or_splice_plus PERIOD qq_template RPAREN'
127
+ rule('list_qq_template' => 'LPAREN qq_template_or_splice* RPAREN').as 'list_qq'
128
+ rule 'list_qq_template' => 'LPAREN qq_template_or_splice+ PERIOD qq_template RPAREN'
154
129
  rule 'list_qq_template' => 'GRAVE_ACCENT qq_template'
155
- rule('vector_qq_template' => 'VECTOR_BEGIN qq_template_or_splice_star RPAREN').as 'vector_qq'
130
+ rule('vector_qq_template' => 'VECTOR_BEGIN qq_template_or_splice* RPAREN').as 'vector_qq'
156
131
  rule('unquotation' => 'COMMA qq_template').as 'unquotation_short'
157
132
  rule 'unquotation' => 'LPAREN UNQUOTE qq_template RPAREN'
158
- rule('qq_template_or_splice_star' => 'qq_template_or_splice_star qq_template_or_splice').as 'star_default'
159
- rule('qq_template_or_splice_star' => []).as 'star_base' ## 'no_template_splice_yet'
160
- rule 'qq_template_or_splice_plus' => 'qq_template_or_splice_plus qq_template_or_splice'
161
- rule 'qq_template_or_splice_plus' => 'qq_template_or_splice'
162
133
  rule 'qq_template_or_splice' => 'qq_template'
163
134
  rule 'qq_template_or_splice' => 'splicing_unquotation'
164
135
  rule 'splicing_unquotation' => 'COMMA_AT_SIGN qq_template'
165
136
  rule 'splicing_unquotation' => 'LPAREN UNQUOTE-SPLICING qq_template RPAREN'
166
- rule('transformer_spec' => 'LPAREN SYNTAX-RULES LPAREN identifier_star RPAREN syntax_rule_star RPAREN').as 'transformer_syntax'
167
- rule('transformer_spec' => 'LPAREN SYNTAX-RULES IDENTIFIER LPAREN identifier_star RPAREN syntax_rule_star RPAREN')
168
- rule('syntax_rule_star' => 'syntax_rule_star syntax_rule').as 'star_default'
169
- rule('syntax_rule_star' => []).as 'star_base'
137
+ rule('transformer_spec' => 'LPAREN SYNTAX-RULES LPAREN IDENTIFIER* RPAREN syntax_rule* RPAREN').as 'transformer_syntax'
138
+ rule('transformer_spec' => 'LPAREN SYNTAX-RULES IDENTIFIER LPAREN IDENTIFIER* RPAREN syntax_rule* RPAREN')
170
139
  rule('syntax_rule' => 'LPAREN pattern template RPAREN').as 'syntax_rule'
171
140
  rule('pattern' => 'pattern_identifier')
172
141
  rule('pattern' => 'UNDERSCORE')
173
- rule('pattern' => 'LPAREN pattern_star RPAREN')
174
- rule('pattern' => 'LPAREN pattern_plus PERIOD pattern RPAREN')
175
- rule('pattern' => 'LPAREN pattern_plus ELLIPSIS pattern_star RPAREN')
176
- rule('pattern' => 'LPAREN pattern_plus ELLIPSIS pattern_star PERIOD pattern RPAREN')
177
- rule('pattern' => 'VECTOR_BEGIN pattern_star RPAREN')
178
- rule('pattern' => 'VECTOR_BEGIN pattern_plus ELLIPSIS pattern_star RPAREN')
142
+ rule('pattern' => 'LPAREN pattern* RPAREN')
143
+ rule('pattern' => 'LPAREN pattern+ PERIOD pattern RPAREN')
144
+ rule('pattern' => 'LPAREN pattern+ ELLIPSIS pattern* RPAREN')
145
+ rule('pattern' => 'LPAREN pattern+ ELLIPSIS pattern* PERIOD pattern RPAREN')
146
+ rule('pattern' => 'VECTOR_BEGIN pattern* RPAREN')
147
+ rule('pattern' => 'VECTOR_BEGIN pattern+ ELLIPSIS pattern* RPAREN')
179
148
  rule('pattern' => 'pattern_datum')
180
- rule('pattern_star' => 'pattern_star pattern').as 'star_default'
181
- rule('pattern_star' => []).as 'star_base'
182
- rule('pattern_plus' => 'pattern_plus pattern')
183
- rule('pattern_plus' => 'pattern')
184
149
  rule('pattern_datum' => 'STRING_LIT')
185
150
  rule('pattern_datum' => 'CHAR')
186
151
  rule('pattern_datum' => 'BOOLEAN')
187
152
  rule('pattern_datum' => 'number')
188
153
  # rule('pattern_datum' => 'bytevector')
189
154
  rule('template' => 'pattern_identifier')
190
- rule('template' => 'LPAREN template_element_star RPAREN')
191
- rule('template' => 'LPAREN template_element_plus PERIOD template RPAREN')
192
- rule('template' => 'VECTOR_BEGIN template_element_star RPAREN')
155
+ rule('template' => 'LPAREN template_element* RPAREN')
156
+ rule('template' => 'LPAREN template_element+ PERIOD template RPAREN')
157
+ rule('template' => 'VECTOR_BEGIN template_element* RPAREN')
193
158
  rule('template' => 'template_datum')
194
- rule('template_element_star' => 'template_element_star template_element').as 'star_default'
195
- rule('template_element_star' => []).as 'star_base'
196
- rule('template_element_plus' => 'template_element_plus template_element')
197
- rule('template_element_plus' => 'template_element')
198
159
  rule('template_element' => 'template')
199
160
  rule('template_element' => 'template ELLIPSIS')
200
161
  rule('template_datum' => 'pattern_datum')
201
162
  rule('pattern_identifier' => 'IDENTIFIER')
202
- # Ugly: specailized production rule per keyword...
163
+ # Ugly: specialized production rule per keyword...
203
164
  rule('pattern_identifier' => 'BEGIN')
204
165
  rule('pattern_identifier' => 'COND')
205
166
  rule('pattern_identifier' => 'DEFINE')
@@ -157,16 +157,6 @@ module Skeem
157
157
  pcall
158
158
  end
159
159
 
160
- # rule('operand_plus' => 'operand_plus operand').as 'multiple_operands'
161
- def reduce_multiple_operands(_production, _range, _tokens, theChildren)
162
- theChildren[0] << theChildren[1]
163
- end
164
-
165
- # rule('operand_plus' => 'operand').as 'last_operand'
166
- def reduce_last_operand(_production, _range, _tokens, theChildren)
167
- [theChildren.last]
168
- end
169
-
170
160
  # rule('def_formals' => 'identifier_star').as 'def_formals'
171
161
  def reduce_def_formals(_production, _range, _tokens, theChildren)
172
162
  SkmFormals.new(theChildren[0], :fixed)
@@ -202,16 +192,6 @@ module Skeem
202
192
  SkmFormals.new(formals, :variadic)
203
193
  end
204
194
 
205
- # rule('identifier_plus' => 'identifier_plus IDENTIFIER').as 'multiple_identifiers'
206
- def reduce_multiple_identifiers(_production, _range, _tokens, theChildren)
207
- theChildren[0] << theChildren[1]
208
- end
209
-
210
- # rule('identifier_plus' => 'IDENTIFIER').as 'last_identifier'
211
- def reduce_last_identifier(_production, _range, _tokens, theChildren)
212
- [theChildren[0]]
213
- end
214
-
215
195
  # rule('body' => 'definition_star sequence').as 'body'
216
196
  def reduce_body(_production, _range, _tokens, theChildren)
217
197
  definitions = theChildren[0].nil? ? [] : theChildren[0]
@@ -273,16 +253,6 @@ module Skeem
273
253
  SkmBindingBlock.new(:let_star, worker.bindings, body)
274
254
  end
275
255
 
276
- # rule('cond_clause_plus' => 'cond_clause_plus cond_clause').as 'multiple_cond_clauses'
277
- def reduce_multiple_cond_clauses(_production, _range, _tokens, theChildren)
278
- theChildren[0] << theChildren[1]
279
- end
280
-
281
- # rule('cond_clause_plus' => 'cond_clause').as 'last_cond_clauses'
282
- def reduce_last_cond_clauses(_production, _range, _tokens, theChildren)
283
- [theChildren[0]]
284
- end
285
-
286
256
  # rule('cond_clause' => 'LPAREN test sequence RPAREN').as 'cond_clause'
287
257
  def reduce_cond_clause(_production, _range, _tokens, theChildren)
288
258
  [theChildren[1], SkmSequencingBlock.new(SkmPair.create_from_a(theChildren[2]))]
@@ -329,16 +299,6 @@ module Skeem
329
299
  includer.build
330
300
  end
331
301
 
332
- # rule('string_plus' => 'string_plus STRING_LIT').as 'multiple_string'
333
- def reduce_multiple_string(_production, _range, _tokens, theChildren)
334
- theChildren[0] << theChildren[1]
335
- end
336
-
337
- # rule('string_plus' => 'STRING_LIT').as 'last_single_string'
338
- def reduce_last_single_string(_production, _range, _tokens, theChildren)
339
- [theChildren[0]]
340
- end
341
-
342
302
  # rule('list_qq_template' => 'LPAREN qq_template_or_splice_star RPAREN').as 'list_qq'
343
303
  def reduce_list_qq(_production, _range, _tokens, theChildren)
344
304
  SkmPair.create_from_a(theChildren[1])
@@ -114,7 +114,7 @@ module Skeem
114
114
  elsif (lexeme = scanner.scan(/[+-]?[0-9]+(?:\.[0-9]*)?(?:(?:e|E)[+-]?[0-9]+)?/))
115
115
  # Order dependency: must be tested after INTEGER case
116
116
  token = build_token('REAL', lexeme)
117
- elsif (lexeme = scanner.scan(/#(?:(?:true)|(?:false)|(?:u8)|[\\\(tfeiodx]|(?:\d+[=#]))/))
117
+ elsif (lexeme = scanner.scan(/#(?:(?:true)|(?:false)|(?:u8)|[\\(tfeiodx]|(?:\d+[=#]))/))
118
118
  token = cardinal_token(lexeme)
119
119
  elsif (lexeme = scanner.scan(/"(?:\\"|[^"])*"/)) # Double quotes literal?
120
120
  token = build_token('STRING_LIT', lexeme)
@@ -124,7 +124,7 @@ module Skeem
124
124
  token = build_token(tok_type, lexeme)
125
125
  elsif (lexeme = scanner.scan(/\|(?:[^|])*\|/)) # Vertical bar delimited
126
126
  token = build_token('IDENTIFIER', lexeme)
127
- elsif (lexeme = scanner.scan(/([\+\-])((?=\s|[|()";])|$)/))
127
+ elsif (lexeme = scanner.scan(/([+\-])((?=\s|[|()";])|$)/))
128
128
  # # R7RS peculiar identifiers case 1: isolated plus and minus as identifiers
129
129
  token = build_token('IDENTIFIER', lexeme)
130
130
  elsif (lexeme = scanner.scan(/[+-][a-zA-Z!$%&*\/:<=>?@^_~+-@][a-zA-Z0-9!$%&*+-.\/:<=>?@^_~+-]*/))
data/lib/skeem/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skeem
4
- VERSION = '0.2.18'
4
+ VERSION = '0.2.19'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skeem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-29 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley