skeem 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e25bd8499926a963c98886effec8d51eb78bb441
4
- data.tar.gz: fd5e2e65ceffbe1ce202ab1d620645d74a2e03f7
3
+ metadata.gz: bfe901703f31ea172032969d5a52e73a99467917
4
+ data.tar.gz: e9ea6993d7f4f4a107e4c43dc8e342affe103439
5
5
  SHA512:
6
- metadata.gz: 181ac16e0465292fc39a1ac157e313348afcb36d83243922b7539969a3e506dbbc0e2f97d78cf41f7bcb4a728dd43d1f78477ec8ca3a468841298f61ca51c2ca
7
- data.tar.gz: 8c6a36fd38ebcc92a4f208bba5be6ac9f11423a1cfb405970f40bbf141f4c70dc1fa74279365d9d6277ef68b15bf6ff40bd2903eab6c865a246b25ab1e121dbc
6
+ metadata.gz: 8b034f52223d95e8d40e3de77596b126484116f900a5890d7da6c9f9de56a0ed1cd08d0ac0e80d1e6b92acc17da6663f3da55eb7b01a2041512e109d3a423285
7
+ data.tar.gz: f315e8f48f9c97391df7a665fd01c2fc6ea4ed292bc9c075bec7332e2706a01cfe00c0aad0ea6d54fccc50e3fb84bc8afc10596a8cedc3726413d3824343baac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.0.6] - 2018-09-01
2
+ Initial (minimalistic) interpreter implementation.
3
+ ### Added
4
+ - Class `Interpreter`.
5
+ - Spec file `interpreter_spec.rb` initial test suite for the interpreter.
6
+
7
+ ### Changed
8
+ - File `README.md` Udpates, sample code snippet added, link to other similar project `heist`.
9
+ - Method `SExprTerminalNode#interpret` returns self instead of the `value` attribute.
10
+
11
+
1
12
  ## [0.0.5] - 2018-08-30
2
13
  Parser now generates correct parse trees for expressions consisting of a single literal.
3
14
 
data/README.md CHANGED
@@ -25,32 +25,41 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  The __Skeem__ project has just started.
28
- At this stage, the gem consists of a tokenizer.
29
- At least these steps must be done in order to have a first interpreter:
30
- - TODO: define subset of Scheme grammar
31
- - TODO: buuild parser of Scheme subset
32
- - TODO: Implement Skeem interpreter (and REPL)
28
+ At this stage, the gem consists of a bare-bones interpreter.
29
+
30
+ ```ruby
31
+ require 'skeem'
32
+
33
+ schemer = Skeem::Interpreter.new
34
+ scheme_code = '"Hello, world"'
35
+ result = schemer.run(scheme_code)
36
+ puts result.value # => "Hello, world"
37
+ ```
33
38
 
34
39
  Roadmap:
40
+ - Extend language support
41
+ - Implement REPL
35
42
  - Implement an equivalent of [lis.py](http://www.norvig.com/lispy.html)
36
43
  - Implement an equivalent of [lispy](http://norvig.com/lispy2.html)
37
44
  - Make it pass the test suite
38
45
  - Extend the language in order to support [Minikanren](https://github.com/TheReasonedSchemer2ndEd/CodeFromTheReasonedSchemer2ndEd)
39
46
  - Make it pass all examples from the [Reasoned Schemer](https://mitpress.mit.edu/books/reasoned-schemer-second-edition) book.
40
47
 
41
- TODO: Write usage instructions here
42
48
 
43
49
  Good to know:
44
50
  Online book: [The Scheme Programming Language (4th Ed.)](https://www.scheme.com/tspl4/). Remark: covers an older version of Scheme.
45
-
46
- ## Development
47
-
48
- After checking out the repo, run `bin/setup` to install dependencies.
49
- Then, run `rake spec` to run the tests. You can also run `bin/console`
50
- for an interactive prompt that will allow you to experiment.
51
- To install this gem onto your local machine, run `bundle exec rake install`.
52
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
53
- which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Implemented Scheme R7RS features:
53
+
54
+ ### Literals
55
+ * Boolean literals: `#t`, `#true`, `#f` and `#false`
56
+ * Numeric literals for integers and reals.
57
+ * `string` and `identifier` literals
58
+
59
+ ## Other similar Ruby projects
60
+ __Skeem__ isn't the sole implementation of the Scheme language in Ruby.
61
+ Here are a few other ones:
62
+ - [Heist gem](https://rubygems.org/gems/heist) -- Probably one of best Scheme implementation in Ruby. Really worth a try. Alas, the [project](https://github.com/jcoglan/heist) seems to be dormant for several years.
54
63
 
55
64
  ## Contributing
56
65
 
@@ -0,0 +1,16 @@
1
+ require_relative 'parser'
2
+
3
+ module Skeem
4
+ class Interpreter
5
+ attr_reader(:parser)
6
+
7
+ def initialize()
8
+ end
9
+
10
+ def run(source)
11
+ @parser ||= Parser.new
12
+ @ptree = parser.parse(source)
13
+ return @ptree.root.interpret
14
+ end
15
+ end # class
16
+ end # module
@@ -21,7 +21,7 @@ module Skeem
21
21
  end
22
22
 
23
23
  def interpret()
24
- return value
24
+ return self
25
25
  end
26
26
 
27
27
  def done!()
data/lib/skeem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Skeem
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
data/lib/skeem.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  # for a Skeem client.
4
4
 
5
5
  require_relative './skeem/version'
6
- require_relative './skeem/parser'
6
+ require_relative './skeem/interpreter'
7
7
 
8
8
  # End of file
@@ -0,0 +1,84 @@
1
+ require_relative '../spec_helper' # Use the RSpec framework
2
+ require_relative '../../lib/skeem/interpreter' # Load the class under test
3
+
4
+ module Skeem
5
+ describe Interpreter do
6
+ context 'Initialization:' do
7
+ it 'should be initialized without argument' do
8
+ expect { Interpreter.new() }.not_to raise_error
9
+ end
10
+
11
+ it 'should not have its parser initialized' do
12
+ expect(subject.parser).to be_nil
13
+ end
14
+ end # context
15
+
16
+ context 'Interpreting self-evaluating expressions' do
17
+ it 'should evaluate isolated booleans' do
18
+ samples = [
19
+ ['#f', false],
20
+ ['#false', false],
21
+ ['#t', true],
22
+ ['#true', true]
23
+ ]
24
+ samples.each do |source, predicted|
25
+ result = subject.run(source)
26
+ expect(result).to be_kind_of(SExprBooleanNode)
27
+ expect(result.value).to eq(predicted)
28
+ end
29
+ end
30
+ end
31
+
32
+ it 'should evaluate isolated integers' do
33
+ samples = [
34
+ ['0', 0],
35
+ ['3', 3],
36
+ ['-3', -3],
37
+ ['+12345', 12345],
38
+ ['-12345', -12345]
39
+ ]
40
+ samples.each do |source, predicted|
41
+ result = subject.run(source)
42
+ expect(result).to be_kind_of(SExprIntegerNode)
43
+ expect(result.value).to eq(predicted)
44
+ end
45
+ end
46
+
47
+ it 'should evaluate isolated real numbers' do
48
+ samples = [
49
+ ['0.0', 0.0],
50
+ ['3.14', 3.14],
51
+ ['-3.14', -3.14],
52
+ ['+123e+45', 123e+45],
53
+ ['-123e-45', -123e-45]
54
+ ]
55
+ samples.each do |source, predicted|
56
+ result = subject.run(source)
57
+ expect(result).to be_kind_of(SExprRealNode)
58
+ expect(result.value).to eq(predicted)
59
+ end
60
+ end
61
+
62
+ it 'should evaluate isolated strings' do
63
+ samples = [
64
+ ['"Hello, world"', 'Hello, world']
65
+ ]
66
+ samples.each do |source, predicted|
67
+ result = subject.run(source)
68
+ expect(result).to be_kind_of(SExprStringNode)
69
+ expect(result.value).to eq(predicted)
70
+ end
71
+ end
72
+
73
+ it 'should evaluate isolated identifiers' do
74
+ samples = [
75
+ ['the-word-recursion-has-many-meanings', 'the-word-recursion-has-many-meanings']
76
+ ]
77
+ samples.each do |source, predicted|
78
+ result = subject.run(source)
79
+ expect(result).to be_kind_of(SExprIdentifierNode)
80
+ expect(result.value).to eq(predicted)
81
+ end
82
+ end
83
+ end # describe
84
+ end # module
@@ -3,17 +3,16 @@ require_relative '../../lib/skeem/tokenizer' # Load the class under test
3
3
 
4
4
  module Skeem
5
5
  describe Parser do
6
-
7
6
  context 'Initialization:' do
8
7
  it 'should be initialized without argument' do
9
8
  expect { Parser.new() }.not_to raise_error
10
9
  end
11
10
 
12
- it 'should have its enginer initialized' do
11
+ it 'should have its parse engine initialized' do
13
12
  expect(subject.engine).to be_kind_of(Rley::Engine)
14
- end
13
+ end
15
14
  end # context
16
-
15
+
17
16
  context 'Parsing literals:' do
18
17
  it 'should parse isolated booleans' do
19
18
  samples = [
@@ -26,9 +25,9 @@ module Skeem
26
25
  ptree = subject.parse(source)
27
26
  expect(ptree.root).to be_kind_of(SExprBooleanNode)
28
27
  expect(ptree.root.value).to eq(predicted)
29
- end
28
+ end
30
29
  end
31
-
30
+
32
31
  it 'should parse isolated integers' do
33
32
  samples = [
34
33
  ['0', 0],
@@ -41,9 +40,9 @@ module Skeem
41
40
  ptree = subject.parse(source)
42
41
  expect(ptree.root).to be_kind_of(SExprIntegerNode)
43
42
  expect(ptree.root.value).to eq(predicted)
44
- end
43
+ end
45
44
  end
46
-
45
+
47
46
  it 'should parse isolated real numbers' do
48
47
  samples = [
49
48
  ['0.0', 0.0],
@@ -56,7 +55,7 @@ module Skeem
56
55
  ptree = subject.parse(source)
57
56
  expect(ptree.root).to be_kind_of(SExprRealNode)
58
57
  expect(ptree.root.value).to eq(predicted)
59
- end
58
+ end
60
59
  end
61
60
 
62
61
  it 'should parse isolated strings' do
@@ -67,7 +66,7 @@ module Skeem
67
66
  ptree = subject.parse(source)
68
67
  expect(ptree.root).to be_kind_of(SExprStringNode)
69
68
  expect(ptree.root.value).to eq(predicted)
70
- end
69
+ end
71
70
  end
72
71
 
73
72
  it 'should parse isolated identifiers' do
@@ -78,11 +77,11 @@ module Skeem
78
77
  ptree = subject.parse(source)
79
78
  expect(ptree.root).to be_kind_of(SExprIdentifierNode)
80
79
  expect(ptree.root.value).to eq(predicted)
81
- end
82
- end
80
+ end
81
+ end
83
82
  end # context
84
83
 
85
- context 'Parsing forms:' do
84
+ context 'Parsing forms:' do
86
85
  # it 'should parse definitions' do
87
86
  # source = '(define r 10)'
88
87
  # expect { subject.parse(source) }.not_to raise_error
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.0.5
4
+ version: 0.0.6
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-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -86,6 +86,7 @@ files:
86
86
  - appveyor.yml
87
87
  - lib/skeem.rb
88
88
  - lib/skeem/grammar.rb
89
+ - lib/skeem/interpreter.rb
89
90
  - lib/skeem/parser.rb
90
91
  - lib/skeem/s_expr_builder.rb
91
92
  - lib/skeem/s_expr_nodes.rb
@@ -93,6 +94,7 @@ files:
93
94
  - lib/skeem/tokenizer.rb
94
95
  - lib/skeem/version.rb
95
96
  - skeem.gemspec
97
+ - spec/skeem/interpreter_spec.rb
96
98
  - spec/skeem/parser_spec.rb
97
99
  - spec/skeem/tokenizer_spec.rb
98
100
  - spec/skeem_spec.rb
@@ -124,6 +126,7 @@ specification_version: 4
124
126
  summary: Skeem is an interpreter of a subset of the Scheme programming language. Scheme
125
127
  is a descendent of the Lisp language.
126
128
  test_files:
129
+ - spec/skeem/interpreter_spec.rb
127
130
  - spec/skeem/parser_spec.rb
128
131
  - spec/skeem/tokenizer_spec.rb
129
132
  - spec/skeem_spec.rb