rubic 0.1.1 → 0.1.2

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: f2bade99b079979ddaf7b42551451939fef2ada1
4
- data.tar.gz: d9a0095e5552d69ca3a9dfade6de63c50f268642
3
+ metadata.gz: 51da002edc71251bec55d378b94e41dc2ffe3282
4
+ data.tar.gz: 3c9ca15aebeebf042e077838498437772c31ac65
5
5
  SHA512:
6
- metadata.gz: 36af5fb982d96dc3b615587cddf10509071e3a339468a00dd05a325069bd04bfb46189f4a644f52bce1722d0271144998c760c9255e6db8d609bc9a40f139191
7
- data.tar.gz: 77c4ab92c10839778e319241a8b7921a3ba1d1fc4dd8554ddd8ed3dbe8c1351e1ebe3ab80b38062ddda7258ffa107b47da1398e373896b67be718387cd83f029
6
+ metadata.gz: dcbf36feedcd3b82fd8ba5d80e5adda3c7d9e8857714bdc2c5fd25f9dab2d786a8a67fc049474cb52afdc3bb8f211fc1822df8e14a7c94df34afb59af709f65b
7
+ data.tar.gz: b6519390237eef8156b89ba255af847d62c2edf9eddb2778d0df24503bc43c39f94d25a1c24bbd35ced3ff823f82b23840c147d312c96cee0f635a56afb7f397
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.1
3
+ - 2.1
4
+ - 2.2
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Rubic - A tiny Scheme interpreter
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rubic.svg)](http://badge.fury.io/rb/rubic)
4
+ [![Build Status](https://travis-ci.org/notozeki/rubic.svg)](https://travis-ci.org/notozeki/rubic)
5
+ [![Coverage Status](https://coveralls.io/repos/notozeki/rubic/badge.svg)](https://coveralls.io/r/notozeki/rubic)
6
+
3
7
  **Rubic** is a very simple Scheme interpreter written in Ruby.
4
8
 
5
9
  NOTE: This is my hobby project. You may find it is good for nothing in practical uses :wink:
data/Rakefile CHANGED
@@ -15,4 +15,4 @@ namespace :racc do
15
15
  end
16
16
 
17
17
  task :test => 'racc:compile'
18
- task :default => 'racc:compile'
18
+ task :default => :test
data/bin/rubic CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubic'
4
+ require 'rubic/inspector'
4
5
  require 'readline'
5
6
 
7
+ using Rubic::Inspector
8
+
6
9
  # TODO: read the code from file when argument passed
7
10
 
8
11
  puts "Welcome to interactive Rubic (v#{Rubic::VERSION})"
@@ -12,9 +15,13 @@ rubic = Rubic::Interpreter.new
12
15
 
13
16
  while input = Readline.readline(">> ", true)
14
17
  next if input.empty?
18
+ while input.count('(') > input.count(')')
19
+ input << Readline.readline(' | ', true)
20
+ end
21
+
15
22
  begin
16
23
  puts '=> ' + rubic.evaluate(input).inspect
17
24
  rescue Rubic::RubicError => e
18
- puts "#{e.class}: #{e.message}"
25
+ puts "\e[31mError: #{e.message}\e[0m"
19
26
  end
20
27
  end
@@ -3,6 +3,7 @@ module Rubic
3
3
  class ArgumentError < RubicError; end
4
4
  class NameError < RubicError; end
5
5
  class ParseError < RubicError; end
6
+ class RuntimeError < RubicError; end
6
7
  end
7
8
 
8
9
  require 'rubic/version'
@@ -0,0 +1,25 @@
1
+ module Rubic
2
+ module Inspector
3
+ refine Array do
4
+ def inspect
5
+ "(#{inspect_rec})"
6
+ end
7
+
8
+ def inspect_rec
9
+ if empty?
10
+ ''
11
+ elsif last.is_a?(Array)
12
+ [first.inspect, last.inspect_rec].join(' ').strip
13
+ else
14
+ "#{first.inspect} . #{last.inspect}"
15
+ end
16
+ end
17
+ end
18
+
19
+ refine Proc do
20
+ def inspect
21
+ "#<lambda:#{object_id}>"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -12,6 +12,13 @@ module Rubic
12
12
  '>' => -> (a, b) { a > b },
13
13
  '=' => -> (a, b) { a == b },
14
14
  'not' => -> (a) { !a },
15
+ 'cons' => -> (a, b) { [a, b] },
16
+ 'car' => -> (l) { l.first },
17
+ 'cdr' => -> (l) { l.last },
18
+ 'nil' => [],
19
+ 'list' => -> (*args) { args.reverse.reduce([]) {|res, e| [e, res] } },
20
+ 'null?' => -> (l) { l.is_a?(Array) ? l.empty? : false },
21
+ 'pair?' => -> (l) { l.is_a?(Array) ? l.any? : false },
15
22
  }
16
23
 
17
24
  def initialize
@@ -40,6 +47,10 @@ module Rubic
40
47
  return atom if atom
41
48
 
42
49
  list = list_or_atom
50
+
51
+ # Empty list
52
+ return nil if list.empty?
53
+
43
54
  # Special Forms
44
55
  case list.first
45
56
  when :define
@@ -95,6 +106,9 @@ module Rubic
95
106
 
96
107
  # Procedure call
97
108
  op, *args = list.map {|e| execute(e, env) }
109
+ unless op.respond_to? :call
110
+ raise Rubic::RuntimeError, "`#{op}' is not a procedure"
111
+ end
98
112
  op.call(*args)
99
113
  end
100
114
 
@@ -1,3 +1,3 @@
1
1
  module Rubic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -18,9 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
  spec.executables = ['rubic']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.required_ruby_version = '>= 2.1' # for Refinements
22
+
23
+ spec.add_development_dependency "bundler"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency "minitest", "~> 5.5"
26
+ spec.add_development_dependency 'travis', '~> 1.7'
27
+ spec.add_development_dependency 'coveralls', '~> 0.8'
24
28
 
25
29
  spec.add_dependency "racc", "~> 1.4"
26
30
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - notozeki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.9'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: travis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: racc
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +113,7 @@ files:
85
113
  - bin/setup
86
114
  - lib/rubic.rb
87
115
  - lib/rubic/environment.rb
116
+ - lib/rubic/inspector.rb
88
117
  - lib/rubic/interpreter.rb
89
118
  - lib/rubic/parser.rb
90
119
  - lib/rubic/parser.y
@@ -102,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
131
  requirements:
103
132
  - - ">="
104
133
  - !ruby/object:Gem::Version
105
- version: '0'
134
+ version: '2.1'
106
135
  required_rubygems_version: !ruby/object:Gem::Requirement
107
136
  requirements:
108
137
  - - ">="