nydp 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/README.md +228 -14
- data/lib/lisp/bm.nydp +18 -0
- data/lib/lisp/boot.nydp +69 -10
- data/lib/lisp/tests/boot-tests.nydp +65 -1
- data/lib/lisp/tests/error-tests.nydp +22 -0
- data/lib/lisp/tests/foundation-test.nydp +14 -22
- data/lib/lisp/tests/parser-tests.nydp +55 -0
- data/lib/nydp.rb +22 -12
- data/lib/nydp/assignment.rb +3 -1
- data/lib/nydp/builtin.rb +2 -5
- data/lib/nydp/builtin/ensuring.rb +3 -0
- data/lib/nydp/builtin/eval.rb +5 -1
- data/lib/nydp/builtin/handle_error.rb +39 -0
- data/lib/nydp/builtin/parse_in_string.rb +11 -0
- data/lib/nydp/builtin/sqrt.rb +5 -0
- data/lib/nydp/context_symbol.rb +38 -6
- data/lib/nydp/core.rb +9 -6
- data/lib/nydp/error.rb +4 -0
- data/lib/nydp/function_invocation.rb +1 -1
- data/lib/nydp/lexical_context.rb +13 -3
- data/lib/nydp/parser.rb +19 -18
- data/lib/nydp/runner.rb +9 -4
- data/lib/nydp/string_atom.rb +6 -7
- data/lib/nydp/symbol_lookup.rb +2 -1
- data/lib/nydp/tokeniser.rb +7 -1
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +35 -12
- data/nydp.gemspec +2 -2
- data/spec/parser_spec.rb +10 -0
- metadata +11 -4
data/lib/nydp/parser.rb
CHANGED
@@ -39,6 +39,17 @@ module Nydp
|
|
39
39
|
return Pair.from_list [pfx] + syms.map { |s| parse_symbol s }
|
40
40
|
end
|
41
41
|
|
42
|
+
SYMBOL_OPERATORS =
|
43
|
+
[
|
44
|
+
[ /\!/, "bang-syntax" ],
|
45
|
+
[ /\./, "dot-syntax" ],
|
46
|
+
[ /\$/, "dollar-syntax" ],
|
47
|
+
[ /::/, "colon-colon-syntax"],
|
48
|
+
[ /:/, "colon-syntax" ],
|
49
|
+
[ /->/, "arrow-syntax" ],
|
50
|
+
[ /[=][>]/, "rocket-syntax" ],
|
51
|
+
]
|
52
|
+
|
42
53
|
def parse_symbol txt
|
43
54
|
txt = txt.to_s
|
44
55
|
case txt
|
@@ -46,31 +57,21 @@ module Nydp
|
|
46
57
|
txt.to_f
|
47
58
|
when /^[-+]?[0-9]+$/
|
48
59
|
txt.to_i
|
49
|
-
when /^'(
|
60
|
+
when /^'(.*)$/
|
50
61
|
Pair.from_list [sym(:quote), parse_symbol($1)]
|
51
|
-
when /^`(
|
62
|
+
when /^`(.*)$/
|
52
63
|
Pair.from_list [sym(:quasiquote), parse_symbol($1)]
|
53
|
-
when /^,@(
|
64
|
+
when /^,@(.*)$/
|
54
65
|
Pair.from_list [sym(:"unquote-splicing"), parse_symbol($1)]
|
55
|
-
when /^,(
|
66
|
+
when /^,(.*)$/
|
56
67
|
Pair.from_list [sym(:unquote), parse_symbol($1)]
|
57
68
|
when /^\.$/
|
58
69
|
sym txt
|
59
70
|
else
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
return split_sym syms, sym("colon-colon-syntax") if syms.length > 1
|
65
|
-
|
66
|
-
syms = txt.split /:/, -1
|
67
|
-
return split_sym syms, sym("colon-syntax") if syms.length > 1
|
68
|
-
|
69
|
-
syms = txt.split /->/, -1
|
70
|
-
return split_sym syms, sym("arrow-syntax") if syms.length > 1
|
71
|
-
|
72
|
-
syms = txt.split(/=>/, -1)
|
73
|
-
return split_sym syms, sym("rocket-syntax") if syms.length > 1
|
71
|
+
SYMBOL_OPERATORS.each do |rgx, name|
|
72
|
+
syms = txt.split(rgx, -1)
|
73
|
+
return split_sym syms, sym(name) if syms.length > 1
|
74
|
+
end
|
74
75
|
|
75
76
|
sym txt
|
76
77
|
end
|
data/lib/nydp/runner.rb
CHANGED
@@ -47,9 +47,14 @@ module Nydp
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def compile_and_eval expr
|
50
|
-
vm.thread Pair.new(Compiler.compile(expr, Nydp.NIL), Nydp.NIL)
|
51
|
-
|
52
|
-
|
50
|
+
result = vm.thread Pair.new(Compiler.compile(expr, Nydp.NIL), Nydp.NIL)
|
51
|
+
e = vm.unhandled_error
|
52
|
+
vm.unhandled_error = nil
|
53
|
+
if e
|
54
|
+
new_msg = "failed to eval #{expr.inspect}\nerror was #{Nydp.indent_text e.message}"
|
55
|
+
raise e.class, new_msg, e.backtrace
|
56
|
+
end
|
57
|
+
result
|
53
58
|
end
|
54
59
|
|
55
60
|
def quote expr
|
@@ -78,7 +83,7 @@ module Nydp
|
|
78
83
|
end
|
79
84
|
|
80
85
|
def print val
|
81
|
-
@printer.puts val if @printer
|
86
|
+
@printer.puts val.inspect if @printer
|
82
87
|
end
|
83
88
|
|
84
89
|
def run
|
data/lib/nydp/string_atom.rb
CHANGED
@@ -5,13 +5,12 @@ module Nydp
|
|
5
5
|
@string, @token = string, token
|
6
6
|
end
|
7
7
|
|
8
|
-
def nydp_type
|
9
|
-
def to_s
|
10
|
-
def to_ruby
|
11
|
-
|
12
|
-
def inspect
|
13
|
-
|
14
|
-
end
|
8
|
+
def nydp_type ; :string ; end
|
9
|
+
def to_s ; string ; end
|
10
|
+
def to_ruby ; string ; end
|
11
|
+
def eql? other ; self == other ; end
|
12
|
+
def inspect ; string.inspect ; end
|
13
|
+
def hash ; string.hash ; end
|
15
14
|
|
16
15
|
def == other
|
17
16
|
other.to_s == self.to_s
|
data/lib/nydp/symbol_lookup.rb
CHANGED
@@ -23,7 +23,8 @@ module Nydp
|
|
23
23
|
while Nydp.NIL.isnt? bindings
|
24
24
|
here = bindings.car
|
25
25
|
if here.key? name
|
26
|
-
|
26
|
+
binding_index = here[name]
|
27
|
+
return new ContextSymbol.new(depth, name, binding_index)
|
27
28
|
else
|
28
29
|
depth += 1
|
29
30
|
bindings = bindings.cdr
|
data/lib/nydp/tokeniser.rb
CHANGED
@@ -74,11 +74,17 @@ module Nydp
|
|
74
74
|
tok = [:left_brace, list_prefix[0...-1]]
|
75
75
|
elsif s.scan(/\)/)
|
76
76
|
tok = [:right_paren]
|
77
|
+
elsif s.scan(/\}/)
|
78
|
+
tok = [:right_brace]
|
77
79
|
elsif number = s.scan(/[-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?/)
|
78
80
|
tok = [:number, number.to_f]
|
79
81
|
elsif integer = s.scan(/[-+]?[0-9]+/)
|
80
82
|
tok = [:number, integer.to_i]
|
81
|
-
elsif atom = s.scan(/[^\s()"{}]
|
83
|
+
elsif atom = s.scan(/[^\s()"{}\|]+\|/)
|
84
|
+
atom = atom[0...-1]
|
85
|
+
rest = next_string_fragment("|", /\|/, nil) || Nydp::StringFragmentToken.new("", "")
|
86
|
+
tok = [:symbol, "#{atom}#{rest.string}"]
|
87
|
+
elsif atom = s.scan(/[^\s()"{}\|]+/)
|
82
88
|
tok = [:symbol, atom]
|
83
89
|
else
|
84
90
|
s.getch
|
data/lib/nydp/version.rb
CHANGED
data/lib/nydp/vm.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module Nydp
|
2
2
|
class VM
|
3
3
|
include Helper
|
4
|
-
attr_accessor :instructions, :args, :contexts, :current_context, :locals
|
4
|
+
attr_accessor :instructions, :args, :contexts, :current_context, :locals, :unhandled_error
|
5
|
+
|
6
|
+
module Finally ; end
|
7
|
+
module HandleError ; end
|
5
8
|
|
6
9
|
def initialize
|
7
10
|
@instructions = []
|
@@ -13,15 +16,40 @@ module Nydp
|
|
13
16
|
def thread expr
|
14
17
|
instructions.push expr
|
15
18
|
while instructions.length > 0
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
begin
|
20
|
+
self.current_context = contexts.last
|
21
|
+
ii = instructions.pop
|
22
|
+
i = ii.car
|
23
|
+
ii.cdr.repush instructions, contexts
|
24
|
+
i.execute(self)
|
25
|
+
rescue Exception => e
|
26
|
+
handle_error e
|
27
|
+
end
|
21
28
|
end
|
22
29
|
pop_arg
|
23
30
|
end
|
24
31
|
|
32
|
+
def handle_error ex
|
33
|
+
@unhandled_error = ex
|
34
|
+
|
35
|
+
protecti = []
|
36
|
+
protectc = []
|
37
|
+
|
38
|
+
while (instructions.length > 0) && !(instructions.last.car.is_a? HandleError)
|
39
|
+
if instructions.last.car.is_a? Finally
|
40
|
+
protecti << instructions.last
|
41
|
+
protectc << contexts.last
|
42
|
+
end
|
43
|
+
|
44
|
+
instructions.pop
|
45
|
+
contexts.pop
|
46
|
+
end
|
47
|
+
|
48
|
+
while protecti.length > 0
|
49
|
+
push_instructions protecti.pop, protectc.pop
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
25
53
|
def peek_context; current_context; end
|
26
54
|
def pop_context; contexts.pop; end
|
27
55
|
def push_arg a; args.push a; end
|
@@ -42,7 +70,7 @@ module Nydp
|
|
42
70
|
end
|
43
71
|
end
|
44
72
|
|
45
|
-
def
|
73
|
+
def vm_info
|
46
74
|
msg = ""
|
47
75
|
msg << "\n"
|
48
76
|
msg << "\ninstruction stack"
|
@@ -59,11 +87,6 @@ module Nydp
|
|
59
87
|
end
|
60
88
|
msg << "\n"
|
61
89
|
msg << "\n"
|
62
|
-
|
63
|
-
instructions = []
|
64
|
-
contexts = []
|
65
|
-
args = [Nydp.NIL]
|
66
|
-
|
67
90
|
msg
|
68
91
|
end
|
69
92
|
end
|
data/nydp.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Nydp::VERSION
|
9
9
|
spec.authors = ["Conan Dalton"]
|
10
10
|
spec.email = ["conan@conandalton.net"]
|
11
|
-
spec.description = %q{Not Your Daddy's Parentheses}
|
12
|
-
spec.summary = %q{A
|
11
|
+
spec.description = %q{ NYDP : Not Your Daddy's Parentheses (a kind of Lisp) }
|
12
|
+
spec.summary = %q{ A civilised yet somewhat dangerous kind of Lisp for a new generation }
|
13
13
|
spec.homepage = "http://github.com/conanite/nydp"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/spec/parser_spec.rb
CHANGED
@@ -56,6 +56,16 @@ describe Nydp::Parser do
|
|
56
56
|
expect(parse "(|foo bar| || |\" hello, there, silly billy!\"|)").to eq pair_list([s0, s1, s2])
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should parse untidy symbols with special syntax" do
|
60
|
+
quote_foo_bar = parse "'|foo bar|"
|
61
|
+
expect(quote_foo_bar).to eq pair_list([quote, sym("foo bar")])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should parse empty symbol with special syntax" do
|
65
|
+
quote_empty = parse "'||"
|
66
|
+
expect(quote_empty).to eq pair_list([quote, sym("")])
|
67
|
+
end
|
68
|
+
|
59
69
|
it "should parse numbers expression" do
|
60
70
|
expect(parse "(1 2 3)").to eq pair_list([1, 2, 3])
|
61
71
|
end
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Not Your Daddy's Parentheses
|
69
|
+
description: " NYDP : Not Your Daddy's Parentheses (a kind of Lisp) "
|
70
70
|
email:
|
71
71
|
- conan@conandalton.net
|
72
72
|
executables:
|
@@ -75,6 +75,7 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
+
- ".gitattributes"
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rspec"
|
80
81
|
- Gemfile
|
@@ -83,11 +84,14 @@ files:
|
|
83
84
|
- Rakefile
|
84
85
|
- bin/nydp
|
85
86
|
- bin/nydp-tests
|
87
|
+
- lib/lisp/bm.nydp
|
86
88
|
- lib/lisp/boot.nydp
|
87
89
|
- lib/lisp/test-runner.nydp
|
88
90
|
- lib/lisp/tests/boot-tests.nydp
|
89
91
|
- lib/lisp/tests/dynamic-scope-test.nydp
|
92
|
+
- lib/lisp/tests/error-tests.nydp
|
90
93
|
- lib/lisp/tests/foundation-test.nydp
|
94
|
+
- lib/lisp/tests/parser-tests.nydp
|
91
95
|
- lib/nydp.rb
|
92
96
|
- lib/nydp/assignment.rb
|
93
97
|
- lib/nydp/builtin.rb
|
@@ -102,6 +106,7 @@ files:
|
|
102
106
|
- lib/nydp/builtin/error.rb
|
103
107
|
- lib/nydp/builtin/eval.rb
|
104
108
|
- lib/nydp/builtin/greater_than.rb
|
109
|
+
- lib/nydp/builtin/handle_error.rb
|
105
110
|
- lib/nydp/builtin/hash.rb
|
106
111
|
- lib/nydp/builtin/inspect.rb
|
107
112
|
- lib/nydp/builtin/is_equal.rb
|
@@ -110,11 +115,13 @@ files:
|
|
110
115
|
- lib/nydp/builtin/millisecs.rb
|
111
116
|
- lib/nydp/builtin/minus.rb
|
112
117
|
- lib/nydp/builtin/parse.rb
|
118
|
+
- lib/nydp/builtin/parse_in_string.rb
|
113
119
|
- lib/nydp/builtin/plus.rb
|
114
120
|
- lib/nydp/builtin/pre_compile.rb
|
115
121
|
- lib/nydp/builtin/puts.rb
|
116
122
|
- lib/nydp/builtin/quit.rb
|
117
123
|
- lib/nydp/builtin/random_string.rb
|
124
|
+
- lib/nydp/builtin/sqrt.rb
|
118
125
|
- lib/nydp/builtin/string_replace.rb
|
119
126
|
- lib/nydp/builtin/string_split.rb
|
120
127
|
- lib/nydp/builtin/thread_locals.rb
|
@@ -183,7 +190,7 @@ rubyforge_project:
|
|
183
190
|
rubygems_version: 2.2.2
|
184
191
|
signing_key:
|
185
192
|
specification_version: 4
|
186
|
-
summary: A
|
193
|
+
summary: A civilised yet somewhat dangerous kind of Lisp for a new generation
|
187
194
|
test_files:
|
188
195
|
- spec/embedded_spec.rb
|
189
196
|
- spec/hash_spec.rb
|