nydp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/lisp/boot.nydp +11 -0
- data/lib/lisp/test-runner.nydp +12 -11
- data/lib/lisp/tests/foundation-test.nydp +50 -1
- data/lib/nydp.rb +23 -120
- data/lib/nydp/builtin/error.rb +1 -1
- data/lib/nydp/builtin/inspect.rb +1 -1
- data/lib/nydp/builtin/random_string.rb +3 -5
- data/lib/nydp/builtin/string_replace.rb +14 -0
- data/lib/nydp/builtin/string_split.rb +14 -0
- data/lib/nydp/builtin/to_string.rb +14 -0
- data/lib/nydp/builtin/type_of.rb +11 -0
- data/lib/nydp/core.rb +66 -0
- data/lib/nydp/function_invocation.rb +18 -19
- data/lib/nydp/interpreted_function.rb +1 -1
- data/lib/nydp/pair.rb +5 -4
- data/lib/nydp/parser.rb +11 -11
- data/lib/nydp/runner.rb +66 -0
- data/lib/nydp/string_atom.rb +4 -4
- data/lib/nydp/string_token.rb +1 -3
- data/lib/nydp/symbol.rb +2 -7
- data/lib/nydp/tokeniser.rb +9 -3
- data/lib/nydp/truth.rb +9 -7
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +15 -22
- data/spec/boot_spec.rb +1 -6
- data/spec/embedded_spec.rb +10 -12
- data/spec/nypd_spec.rb +5 -26
- data/spec/pair_spec.rb +16 -17
- data/spec/parser_spec.rb +14 -14
- data/spec/spec_helper.rb +19 -0
- data/spec/string_token_spec.rb +19 -0
- data/spec/symbol_spec.rb +0 -2
- metadata +9 -2
data/spec/nypd_spec.rb
CHANGED
@@ -1,33 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Nydp do
|
4
|
-
let(:
|
5
|
-
let(:parser) { Nydp::Parser.new(root_ns) }
|
4
|
+
let(:parser) { Nydp::Parser.new(ns) }
|
6
5
|
let(:vm) { Nydp::VM.new }
|
7
6
|
|
8
|
-
def sym name
|
9
|
-
Nydp::Symbol.mk name.to_sym, root_ns
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse txt
|
13
|
-
tokens = Nydp::Tokeniser.new txt
|
14
|
-
expressions = []
|
15
|
-
expr = parser.expression(tokens)
|
16
|
-
while (expr != nil)
|
17
|
-
expressions << expr
|
18
|
-
expr = parser.expression(tokens)
|
19
|
-
end
|
20
|
-
expressions
|
21
|
-
end
|
22
|
-
|
23
7
|
def run txt
|
24
|
-
Nydp.setup
|
25
|
-
|
26
|
-
result = nil
|
27
|
-
expressions.each do |expr|
|
28
|
-
result = Nydp.compile_and_eval vm, expr
|
29
|
-
end
|
30
|
-
result
|
8
|
+
Nydp.setup ns
|
9
|
+
Nydp::StreamRunner.new(vm, ns, txt).run
|
31
10
|
end
|
32
11
|
|
33
12
|
it "should make a symbol from a string" do
|
@@ -101,9 +80,9 @@ describe Nydp do
|
|
101
80
|
end
|
102
81
|
|
103
82
|
it "should recurse without consuming extra memory" do
|
104
|
-
program = "(assign f1 (fn (x acc) (cond (< x 1) (vm-info) (f1 (- x 1) (+ x acc))))) (f1 1000)"
|
83
|
+
program = "(assign f1 (fn (x acc) (cond (< x 1) (vm-info) (f1 (- x 1) (+ x acc))))) (f1 1000 0)"
|
105
84
|
expected = parse "((contexts . 0) (instructions . 0) (args . 0))"
|
106
|
-
expect(run program).to eq expected
|
85
|
+
expect(run program).to eq expected
|
107
86
|
end
|
108
87
|
|
109
88
|
describe :cond do
|
data/spec/pair_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Nydp::Pair do
|
4
|
-
let(:ns) { { } }
|
5
4
|
let(:a) { Nydp::Symbol.mk :a, ns }
|
6
5
|
let(:b) { Nydp::Symbol.mk :b, ns }
|
7
6
|
let(:c) { Nydp::Symbol.mk :c, ns }
|
@@ -23,26 +22,26 @@ describe Nydp::Pair do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
it "should define #== to return true for an identical list" do
|
26
|
-
p1 =
|
27
|
-
p2 =
|
25
|
+
p1 = pair_list [:a, :b, :c, :d]
|
26
|
+
p2 = pair_list [:a, :b, :c, :d]
|
28
27
|
expect(p1).to eq p2
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should define #== to return true for identical improper lists" do
|
32
|
-
p1 =
|
33
|
-
p2 =
|
31
|
+
p1 = pair_list [:a, :b, :c, :d], 4
|
32
|
+
p2 = pair_list [:a, :b, :c, :d], 4
|
34
33
|
expect(p1).to eq p2
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should define #== to return false for a non-identical list" do
|
38
|
-
p1 =
|
39
|
-
p2 =
|
37
|
+
p1 = pair_list [:a, :b, :c, :d]
|
38
|
+
p2 = pair_list [:a, :b, :c, 22]
|
40
39
|
expect(p1).not_to eq p2
|
41
40
|
end
|
42
41
|
|
43
42
|
it "should define #== to return false for lists which differ only in their terminating element" do
|
44
|
-
p1 =
|
45
|
-
p2 =
|
43
|
+
p1 = pair_list [:a, :b, :c], :d
|
44
|
+
p2 = pair_list [:a, :b, :c], 22
|
46
45
|
expect(p1).not_to eq p2
|
47
46
|
end
|
48
47
|
end
|
@@ -54,7 +53,7 @@ describe Nydp::Pair do
|
|
54
53
|
end
|
55
54
|
|
56
55
|
it "should convert a ruby list" do
|
57
|
-
p =
|
56
|
+
p = pair_list [:a, :b, :c, :d]
|
58
57
|
expect(p.car).to eq :a
|
59
58
|
p = p.cdr
|
60
59
|
expect(p.car).to eq :b
|
@@ -71,32 +70,32 @@ describe Nydp::Pair do
|
|
71
70
|
end
|
72
71
|
|
73
72
|
it "should have size zero when empty" do
|
74
|
-
expect(
|
73
|
+
expect(pair_list([]).size).to eq 0
|
75
74
|
end
|
76
75
|
|
77
76
|
it "should report the number of elements is contains" do
|
78
|
-
expect(
|
77
|
+
expect(pair_list([:a, :b, :c]).size).to eq 3
|
79
78
|
end
|
80
79
|
|
81
80
|
it "should report the number of elements in an improper list, excluding last item" do
|
82
|
-
expect(
|
81
|
+
expect(pair_list([:a, :b, :c, :d], :foo).size).to eq 4
|
83
82
|
end
|
84
83
|
|
85
84
|
it "should represent itself as a string" do
|
86
|
-
expect(
|
85
|
+
expect(pair_list([a, b, c, d]).to_s).to eq "(a b c d)"
|
87
86
|
end
|
88
87
|
|
89
88
|
it "should represent an improper list as a string" do
|
90
|
-
expect(
|
89
|
+
expect(pair_list([a, b, c, d], foo).to_s).to eq "(a b c d . foo)"
|
91
90
|
end
|
92
91
|
|
93
92
|
it "should parse a list" do
|
94
|
-
p =
|
93
|
+
p = pair_list [a, b, c, d]
|
95
94
|
expect(Nydp::Pair.parse_list([a, b, c, d])).to eq p
|
96
95
|
end
|
97
96
|
|
98
97
|
it "should parse a list" do
|
99
|
-
p =
|
98
|
+
p = pair_list [a, b, c, d], foo
|
100
99
|
expect(Nydp::Pair.parse_list([a, b, c, d, dot, foo])).to eq p
|
101
100
|
end
|
102
101
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Nydp::Parser do
|
4
|
-
|
5
|
-
let(:ns) { { } }
|
6
4
|
let(:aa) { Nydp::Symbol.mk :aa, ns }
|
7
5
|
let(:a) { Nydp::Symbol.mk :a, ns }
|
8
6
|
let(:b) { Nydp::Symbol.mk :b, ns }
|
@@ -21,18 +19,6 @@ describe Nydp::Parser do
|
|
21
19
|
let(:cocosyn) { Nydp::Symbol.mk :"colon-colon-syntax", ns }
|
22
20
|
let(:colosyn) { Nydp::Symbol.mk :"colon-syntax", ns }
|
23
21
|
|
24
|
-
def sym name
|
25
|
-
Nydp::Symbol.mk name.to_sym, ns
|
26
|
-
end
|
27
|
-
|
28
|
-
def parse txt
|
29
|
-
Nydp::Parser.new(ns).expression(Nydp::Tokeniser.new txt)
|
30
|
-
end
|
31
|
-
|
32
|
-
def pair_list xs, last=Nydp.NIL
|
33
|
-
Nydp::Pair.from_list xs, last
|
34
|
-
end
|
35
|
-
|
36
22
|
it "should return a stream of tokens" do
|
37
23
|
t = Nydp::Tokeniser.new ""
|
38
24
|
expect(t.next_token).to eq nil
|
@@ -120,6 +106,16 @@ describe Nydp::Parser do
|
|
120
106
|
expect(parse '(1 "hello there \"jimmy\"" 3)').to eq expected
|
121
107
|
end
|
122
108
|
|
109
|
+
it "should handle escaped tabs and newlines inside a string" do
|
110
|
+
expected = Nydp::StringAtom.new "hello\tworld\nnice day"
|
111
|
+
parsed = parse "\"hello\\tworld\\nnice day\""
|
112
|
+
expect(parsed).to eq expected
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should parse a brace list" do
|
116
|
+
expect(parse "{a b c d}").to eq pair_list [sym("brace-list"), a, b, c, d]
|
117
|
+
end
|
118
|
+
|
123
119
|
it "should parse a plain symbol" do
|
124
120
|
expect(parse "foo").to eq foo
|
125
121
|
end
|
@@ -128,6 +124,10 @@ describe Nydp::Parser do
|
|
128
124
|
expect(parse "foo.bar").to eq pair_list([dotsyn, foo, bar])
|
129
125
|
end
|
130
126
|
|
127
|
+
it "should parse a dotted symbol" do
|
128
|
+
expect(parse "(list a b foo.bar c)").to eq pair_list([sym(:list), a, b, pair_list([dotsyn, foo, bar]), c])
|
129
|
+
end
|
130
|
+
|
131
131
|
it "should parse a colon-colon symbol" do
|
132
132
|
expect(parse "foo::bar").to eq pair_list([cocosyn, foo, bar])
|
133
133
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,29 @@
|
|
1
1
|
require 'nydp'
|
2
2
|
require 'nydp/symbol'
|
3
3
|
|
4
|
+
module SpecHelper
|
5
|
+
def sym name
|
6
|
+
Nydp::Symbol.mk name.to_sym, ns
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse txt
|
10
|
+
Nydp::Parser.new(ns).expression(Nydp::Tokeniser.new txt)
|
11
|
+
end
|
12
|
+
|
13
|
+
def pair_list xs, last=Nydp.NIL
|
14
|
+
Nydp::Pair.from_list xs, last
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.included base
|
18
|
+
base.let(:ns) { { } }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
4
22
|
RSpec.configure do |config|
|
5
23
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
24
|
config.run_all_when_everything_filtered = true
|
7
25
|
config.filter_run :focus
|
8
26
|
config.order = 'random'
|
9
27
|
config.include Nydp::Helper
|
28
|
+
config.include SpecHelper
|
10
29
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Nydp::StringFragmentToken do
|
4
|
+
it "is equal to another token with the same content" do
|
5
|
+
t1 = Nydp::StringFragmentToken.new "foo", "bar"
|
6
|
+
t2 = Nydp::StringFragmentToken.new "foo", "zub"
|
7
|
+
expect(t1).to eq t2
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is not equal to another string with the same content" do
|
11
|
+
t1 = Nydp::StringFragmentToken.new "foo", "bar"
|
12
|
+
expect(t1).not_to eq "foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is not equal to nil" do
|
16
|
+
t1 = Nydp::StringFragmentToken.new "foo", "bar"
|
17
|
+
expect(t1).not_to eq Nydp.NIL
|
18
|
+
end
|
19
|
+
end
|
data/spec/symbol_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,14 +110,18 @@ files:
|
|
110
110
|
- lib/nydp/builtin/puts.rb
|
111
111
|
- lib/nydp/builtin/quit.rb
|
112
112
|
- lib/nydp/builtin/random_string.rb
|
113
|
+
- lib/nydp/builtin/string_replace.rb
|
114
|
+
- lib/nydp/builtin/string_split.rb
|
113
115
|
- lib/nydp/builtin/times.rb
|
114
116
|
- lib/nydp/builtin/to_string.rb
|
115
117
|
- lib/nydp/builtin/to_sym.rb
|
118
|
+
- lib/nydp/builtin/type_of.rb
|
116
119
|
- lib/nydp/builtin/vm_info.rb
|
117
120
|
- lib/nydp/closure.rb
|
118
121
|
- lib/nydp/compiler.rb
|
119
122
|
- lib/nydp/cond.rb
|
120
123
|
- lib/nydp/context_symbol.rb
|
124
|
+
- lib/nydp/core.rb
|
121
125
|
- lib/nydp/error.rb
|
122
126
|
- lib/nydp/function_invocation.rb
|
123
127
|
- lib/nydp/helper.rb
|
@@ -126,6 +130,7 @@ files:
|
|
126
130
|
- lib/nydp/literal.rb
|
127
131
|
- lib/nydp/pair.rb
|
128
132
|
- lib/nydp/parser.rb
|
133
|
+
- lib/nydp/runner.rb
|
129
134
|
- lib/nydp/string_atom.rb
|
130
135
|
- lib/nydp/string_token.rb
|
131
136
|
- lib/nydp/symbol.rb
|
@@ -142,6 +147,7 @@ files:
|
|
142
147
|
- spec/pair_spec.rb
|
143
148
|
- spec/parser_spec.rb
|
144
149
|
- spec/spec_helper.rb
|
150
|
+
- spec/string_token_spec.rb
|
145
151
|
- spec/symbol_spec.rb
|
146
152
|
homepage: http://github.com/conanite/nydp
|
147
153
|
licenses:
|
@@ -174,4 +180,5 @@ test_files:
|
|
174
180
|
- spec/pair_spec.rb
|
175
181
|
- spec/parser_spec.rb
|
176
182
|
- spec/spec_helper.rb
|
183
|
+
- spec/string_token_spec.rb
|
177
184
|
- spec/symbol_spec.rb
|