Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: strings. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source "https://rubygems.org"

group :test do
gem "pry"
gem "simplecov"
gem "codeclimate-test-reporter", require: nil
end
Expand Down
8 changes: 5 additions & 3 deletions lib/lisp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def self.parse tokens, tree = []

def self.atom token
case token
when /\d/
token.to_f % 1 > 0 ? token.to_f : token.to_i
when /^[0-9]+$/
token.to_i
when /[0-9]+\.?[0-9]+?$/
token.to_f
else
token.to_sym
token[0] == token[-1] && token[0] == ?' ? token.slice(1..-2) : token.to_sym
end
end

Expand Down
5 changes: 3 additions & 2 deletions test/test_lisp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def test_parse
# representation

def test_representation
assert_equal [:*, 2, [:+, 1, 0]], Lisp.parse(Lisp.tokenize("(* 2 (+ 1 0) )"))
assert_equal [:*, 2, [:+, 1.5, 0]], Lisp.parse(Lisp.tokenize("(* 2 (+ 1.5 0) )"))
assert_equal [:lambda, [:r], [:*, 3.141592653, [:*, :r, :r]]], Lisp.parse(Lisp.tokenize("(lambda (r) (* 3.141592653 (* r r)))"))
assert_equal [:+, "hello", "world"], Lisp.parse(Lisp.tokenize("(+ 'hello' 'world')"))
end

# execution
Expand Down Expand Up @@ -112,7 +113,7 @@ def test_repl
Process.kill("INT", pid)
thread.join
end

assert_output("ctrl-c to exit\n") do
subject.run
end
Expand Down