skeem 0.2.15 → 0.2.16

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -11
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +2 -0
  5. data/README.md +3 -2
  6. data/Rakefile +2 -0
  7. data/appveyor.yml +3 -4
  8. data/bin/skeem +15 -15
  9. data/lib/skeem.rb +2 -0
  10. data/lib/skeem/datum_dsl.rb +12 -3
  11. data/lib/skeem/element_visitor.rb +5 -2
  12. data/lib/skeem/grammar.rb +86 -24
  13. data/lib/skeem/interpreter.rb +5 -3
  14. data/lib/skeem/parser.rb +6 -4
  15. data/lib/skeem/primitive/primitive_builder.rb +128 -115
  16. data/lib/skeem/primitive/primitive_procedure.rb +17 -20
  17. data/lib/skeem/runtime.rb +9 -5
  18. data/lib/skeem/s_expr_builder.rb +46 -104
  19. data/lib/skeem/s_expr_nodes.rb +116 -90
  20. data/lib/skeem/skeem_exception.rb +0 -0
  21. data/lib/skeem/skm_binding.rb +6 -7
  22. data/lib/skeem/skm_compound_datum.rb +8 -4
  23. data/lib/skeem/skm_element.rb +14 -12
  24. data/lib/skeem/skm_empty_list.rb +6 -4
  25. data/lib/skeem/skm_exception.rb +9 -0
  26. data/lib/skeem/skm_expression.rb +3 -1
  27. data/lib/skeem/skm_frame.rb +3 -2
  28. data/lib/skeem/skm_pair.rb +23 -18
  29. data/lib/skeem/skm_procedure_exec.rb +8 -6
  30. data/lib/skeem/skm_simple_datum.rb +13 -12
  31. data/lib/skeem/skm_unary_expression.rb +15 -17
  32. data/lib/skeem/tokenizer.rb +32 -25
  33. data/lib/skeem/version.rb +3 -1
  34. data/skeem.gemspec +6 -4
  35. data/spec/skeem/add4.skm +4 -0
  36. data/spec/skeem/datum_dsl_spec.rb +13 -12
  37. data/spec/skeem/element_visitor_spec.rb +12 -10
  38. data/spec/skeem/interpreter_spec.rb +74 -46
  39. data/spec/skeem/lambda_spec.rb +9 -7
  40. data/spec/skeem/parser_spec.rb +21 -19
  41. data/spec/skeem/primitive/primitive_builder_spec.rb +57 -48
  42. data/spec/skeem/primitive/primitive_procedure_spec.rb +15 -13
  43. data/spec/skeem/runtime_spec.rb +18 -16
  44. data/spec/skeem/s_expr_nodes_spec.rb +8 -6
  45. data/spec/skeem/skm_compound_datum_spec.rb +11 -9
  46. data/spec/skeem/skm_element_spec.rb +7 -5
  47. data/spec/skeem/skm_empty_list_spec.rb +7 -5
  48. data/spec/skeem/skm_frame_spec.rb +5 -4
  49. data/spec/skeem/skm_pair_spec.rb +4 -3
  50. data/spec/skeem/skm_procedure_exec_spec.rb +2 -0
  51. data/spec/skeem/skm_simple_datum_spec.rb +24 -22
  52. data/spec/skeem/skm_unary_expression_spec.rb +11 -9
  53. data/spec/skeem/tokenizer_spec.rb +53 -44
  54. data/spec/skeem_spec.rb +2 -0
  55. data/spec/spec_helper.rb +4 -2
  56. metadata +7 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../spec_helper' # Use the RSpec framework
2
4
  require_relative '../../lib/skeem/datum_dsl'
3
5
  require_relative '../../lib/skeem/s_expr_nodes'
@@ -12,7 +14,7 @@ module Skeem
12
14
 
13
15
  context 'Initialization:' do
14
16
  it 'should be initialized with a position and a child element' do
15
- expect{ SkmUnaryExpression.new(pos, sample_child) }.not_to raise_error
17
+ expect { SkmUnaryExpression.new(pos, sample_child) }.not_to raise_error
16
18
  end
17
19
 
18
20
  it 'should know its child' do
@@ -38,7 +40,7 @@ module Skeem
38
40
 
39
41
  context 'Initialization:' do
40
42
  it 'should be initialized with a Skeem element' do
41
- expect{ SkmQuotation.new(sample_literal) }.not_to raise_error
43
+ expect { SkmQuotation.new(sample_literal) }.not_to raise_error
42
44
  end
43
45
 
44
46
  it 'should know its datum' do
@@ -84,7 +86,7 @@ module Skeem
84
86
 
85
87
  context 'Initialization:' do
86
88
  it 'should be initialized with a Skeem element' do
87
- expect{ SkmQuasiquotation.new(sample_literal) }.not_to raise_error
89
+ expect { SkmQuasiquotation.new(sample_literal) }.not_to raise_error
88
90
  end
89
91
  end # context
90
92
 
@@ -116,7 +118,7 @@ module Skeem
116
118
  end # describe
117
119
 
118
120
 
119
- describe SkmUnquotation do
121
+ describe SkmUnquotation do
120
122
  include DatumDSL
121
123
 
122
124
  let(:sample_literal) { string('foo') }
@@ -125,7 +127,7 @@ module Skeem
125
127
 
126
128
  context 'Initialization:' do
127
129
  it 'should be initialized with a Skeem element' do
128
- expect{ SkmUnquotation.new(sample_literal) }.not_to raise_error
130
+ expect { SkmUnquotation.new(sample_literal) }.not_to raise_error
129
131
  end
130
132
  end # context
131
133
 
@@ -156,7 +158,7 @@ module Skeem
156
158
  end
157
159
  end # context
158
160
  end # describe
159
-
161
+
160
162
  describe SkmVariableReference do
161
163
  include DatumDSL
162
164
 
@@ -167,7 +169,7 @@ module Skeem
167
169
 
168
170
  context 'Initialization:' do
169
171
  it 'should be initialized with a position and a symbol' do
170
- expect{ SkmVariableReference.new(pos, sample_var) }.not_to raise_error
172
+ expect { SkmVariableReference.new(pos, sample_var) }.not_to raise_error
171
173
  end
172
174
 
173
175
  it 'should know its variable' do
@@ -187,7 +189,7 @@ module Skeem
187
189
  expect(subject.evaluate(runtime)).to eq(3)
188
190
  end
189
191
 
190
- it "should return itself at quasiquotation" do
192
+ it 'should return itself at quasiquotation' do
191
193
  expect(subject.quasiquote(runtime)).to be_equal(subject)
192
194
  end
193
195
 
@@ -197,4 +199,4 @@ module Skeem
197
199
  end
198
200
  end # context
199
201
  end # describe
200
- end # module
202
+ end # module
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../spec_helper' # Use the RSpec framework
2
4
  require_relative '../../lib/skeem/tokenizer' # Load the class under test
3
5
 
@@ -12,14 +14,14 @@ module Skeem
12
14
  end
13
15
 
14
16
  # Assumption: subject is a Skeem::Tokenizer
15
- def check_tokens(tokenTests, tokType)
16
- tokenTests.each do |(input, prediction)|
17
+ def check_tokens(tokenTests, tokType)
18
+ tokenTests.each do |(input, prediction)|
17
19
  subject.reinitialize(input)
18
20
  token = subject.tokens.first
19
21
  expect(token.terminal).to eq(tokType)
20
22
  expect(token.lexeme).to eq(prediction)
21
- end
22
- end
23
+ end
24
+ end
23
25
 
24
26
  def unquoted(aString)
25
27
  aString.gsub(/(^")|("$)/, '')
@@ -45,9 +47,8 @@ module Skeem
45
47
  tokens.each { |token| expect(token).to be_kind_of(Rley::Lexical::Token) }
46
48
  terminals = tokens.map(&:terminal)
47
49
  prediction = %w[LPAREN RPAREN APOSTROPHE
48
- GRAVE_ACCENT PERIOD
49
- COMMA COMMA_AT_SIGN
50
- ]
50
+ GRAVE_ACCENT PERIOD
51
+ COMMA COMMA_AT_SIGN ]
51
52
  expect(terminals).to eq(prediction)
52
53
  end
53
54
  end # context
@@ -80,7 +81,7 @@ module Skeem
80
81
 
81
82
  check_tokens(tests, 'INTEGER')
82
83
  end
83
-
84
+
84
85
  it 'should tokenize integers with explicit radix 10' do
85
86
  tests = [
86
87
  # couple [raw input, expected]
@@ -106,7 +107,7 @@ module Skeem
106
107
  ]
107
108
 
108
109
  check_tokens(tests, 'INTEGER')
109
- end
110
+ end
110
111
  end # context
111
112
 
112
113
  context 'Rational literals recognition:' do
@@ -114,7 +115,7 @@ module Skeem
114
115
  tests = [
115
116
  # couple [raw input, expected]
116
117
  ['1/2', Rational(1, 2)],
117
- ['-22/7', -Rational(22, 7)],
118
+ ['-22/7', -Rational(22, 7)]
118
119
  ]
119
120
 
120
121
  check_tokens(tests, 'RATIONAL')
@@ -145,9 +146,9 @@ module Skeem
145
146
  it 'should tokenize named characters' do
146
147
  tests = [
147
148
  # couple [raw input, expected]
148
- ["#\\alarm", ?\a],
149
- ["#\\newline", ?\n],
150
- ["#\\return", ?\r]
149
+ ['#\alarm', ?\a],
150
+ ['#\newline', ?\n],
151
+ ['#\return', ?\r]
151
152
  ]
152
153
 
153
154
  check_tokens(tests, 'CHAR')
@@ -156,10 +157,10 @@ module Skeem
156
157
  it 'should tokenize escaped characters' do
157
158
  tests = [
158
159
  # couple [raw input, expected]
159
- ["#\\a", ?a],
160
- ["#\\A", ?A],
161
- ["#\\(", ?(],
162
- ["#\\ ", ?\s]
160
+ ['#\a', ?a],
161
+ ['#\A', ?A],
162
+ ['#\(', ?(],
163
+ ['#\ ', ?\s]
163
164
  ]
164
165
 
165
166
  check_tokens(tests, 'CHAR')
@@ -168,9 +169,9 @@ module Skeem
168
169
  it 'should tokenize hex-coded characters' do
169
170
  tests = [
170
171
  # couple [raw input, expected]
171
- ["#\\x07", ?\a],
172
- ["#\\x1B", ?\e],
173
- ["#\\x3BB", ?\u03bb]
172
+ ['#\x07', ?\a],
173
+ ['#\x1B', ?\e],
174
+ ['#\x3BB', ?\u03bb]
174
175
  ]
175
176
 
176
177
  check_tokens(tests, 'CHAR')
@@ -201,10 +202,10 @@ module Skeem
201
202
  # "\x03B1; is named GREEK SMALL LETTER ALPHA."
202
203
 
203
204
  context 'Identifier recognition:' do
204
- it 'should tokenize identifier' do
205
+ it 'should tokenize identifiers' do
205
206
  examples = [
206
207
  # Examples taken from R7RS document
207
- '...', '+', '+soup+', '<=?',
208
+ '+', '+soup+', '<=?',
208
209
  '->string', 'a34kTMNs', 'lambda',
209
210
  'list->vector', 'q', 'V17a',
210
211
  '|two words|', '|two\x20;words|',
@@ -222,6 +223,14 @@ module Skeem
222
223
  expect(token.lexeme).to eq(input)
223
224
  end
224
225
  end
226
+
227
+ it 'should recognize ellipsis' do
228
+ input = '...'
229
+ subject.reinitialize(input)
230
+ token = subject.tokens.first
231
+ expect(token.terminal).to eq('ELLIPSIS')
232
+ expect(token.lexeme).to eq(input)
233
+ end
225
234
  end # context
226
235
 
227
236
  context 'Vector recognition' do
@@ -233,7 +242,7 @@ module Skeem
233
242
  ['INTEGER', 0, 3],
234
243
  ['INTEGER', -2, 5],
235
244
  ['STRING_LIT', 'Sue', 8],
236
- ['RPAREN', ')', 13],
245
+ ['RPAREN', ')', 13]
237
246
  ]
238
247
  tokens = subject.tokens
239
248
  predictions.each_with_index do |(pr_terminal, pr_lexeme, pr_position), i|
@@ -255,7 +264,7 @@ module Skeem
255
264
  end
256
265
 
257
266
  it 'should skip trailing comments' do
258
- input = "\"Some text\"; Trailing comment"
267
+ input = '"Some text"; Trailing comment'
259
268
  subject.reinitialize(input)
260
269
  token = subject.tokens.first
261
270
  expect(token.terminal).to eq('STRING_LIT')
@@ -305,28 +314,28 @@ module Skeem
305
314
  context 'Scanning Scheme sample code' do
306
315
  it 'should produce a sequence of token objects' do
307
316
  # Deeper tokenizer testing
308
- source = "(define circle-area (lambda (r) (* pi (* r r))))"
317
+ source = '(define circle-area (lambda (r) (* pi (* r r))))'
309
318
  subject.reinitialize(source)
310
319
  predicted = [
311
- ['LPAREN', '('],
312
- ['DEFINE', 'define'],
313
- ['IDENTIFIER', 'circle-area'],
314
- ['LPAREN', '('],
315
- ['LAMBDA', 'lambda'],
316
- ['LPAREN', '('],
317
- ['IDENTIFIER', 'r'],
318
- ['RPAREN', ')'],
319
- ['LPAREN', '('],
320
- ['IDENTIFIER', '*'],
321
- ['IDENTIFIER', 'pi'],
322
- ['LPAREN', '('],
323
- ['IDENTIFIER', '*'],
324
- ['IDENTIFIER', 'r'],
325
- ['IDENTIFIER', 'r'],
326
- ['RPAREN', ')'],
327
- ['RPAREN', ')'],
328
- ['RPAREN', ')'],
329
- ['RPAREN', ')']
320
+ %w[LPAREN (],
321
+ %w[DEFINE define],
322
+ %w[IDENTIFIER circle-area],
323
+ %w[LPAREN (],
324
+ %w[LAMBDA lambda],
325
+ %w[LPAREN (],
326
+ %w[IDENTIFIER r],
327
+ %w[RPAREN )],
328
+ %w[LPAREN (],
329
+ %w[IDENTIFIER *],
330
+ %w[IDENTIFIER pi],
331
+ %w[LPAREN (],
332
+ %w[IDENTIFIER *],
333
+ %w[IDENTIFIER r],
334
+ %w[IDENTIFIER r],
335
+ %w[RPAREN )],
336
+ %w[RPAREN )],
337
+ %w[RPAREN )],
338
+ %w[RPAREN )]
330
339
  ]
331
340
  match_expectations(subject, predicted)
332
341
  end
data/spec/skeem_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Skeem do
2
4
  it 'has a version number' do
3
5
  expect(Skeem::VERSION).not_to be nil
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  require 'rspec' # Use the RSpec framework
3
5
  require_relative '../lib/skeem'
@@ -31,9 +33,9 @@ module InterpreterSpec
31
33
  else
32
34
  expect(result).to eq(predicted)
33
35
  end
34
- rescue Exception => exc
36
+ rescue Exception => e
35
37
  $stderr.puts "Row #{index + 1} failed."
36
- throw exc
38
+ throw e
37
39
  end
38
40
  end
39
41
  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.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-02 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -98,10 +98,12 @@ files:
98
98
  - lib/skeem/runtime.rb
99
99
  - lib/skeem/s_expr_builder.rb
100
100
  - lib/skeem/s_expr_nodes.rb
101
+ - lib/skeem/skeem_exception.rb
101
102
  - lib/skeem/skm_binding.rb
102
103
  - lib/skeem/skm_compound_datum.rb
103
104
  - lib/skeem/skm_element.rb
104
105
  - lib/skeem/skm_empty_list.rb
106
+ - lib/skeem/skm_exception.rb
105
107
  - lib/skeem/skm_expression.rb
106
108
  - lib/skeem/skm_frame.rb
107
109
  - lib/skeem/skm_pair.rb
@@ -112,6 +114,7 @@ files:
112
114
  - lib/skeem/tokenizer.rb
113
115
  - lib/skeem/version.rb
114
116
  - skeem.gemspec
117
+ - spec/skeem/add4.skm
115
118
  - spec/skeem/datum_dsl_spec.rb
116
119
  - spec/skeem/element_visitor_spec.rb
117
120
  - spec/skeem/interpreter_spec.rb
@@ -145,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
148
  requirements:
146
149
  - - ">="
147
150
  - !ruby/object:Gem::Version
148
- version: '0'
151
+ version: 2.3.0
149
152
  required_rubygems_version: !ruby/object:Gem::Requirement
150
153
  requirements:
151
154
  - - ">="
152
155
  - !ruby/object:Gem::Version
153
156
  version: '0'
154
157
  requirements: []
155
- rubygems_version: 3.0.2
158
+ rubygems_version: 3.0.3
156
159
  signing_key:
157
160
  specification_version: 4
158
161
  summary: Skeem is an interpreter of a subset of the Scheme programming language. Scheme