nisp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nisp.rb +32 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a150e3b1c2411fc1726fa685200ac50f709d678
|
4
|
+
data.tar.gz: da5552b921e4f54b531d935e66f6f804e7b7e1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0844a1935912960c3ccc40602201ea4b370fc4dcc1f9d33674846d8059fd7ac34780e9c0312731cec9f7ff2f1e69aee55031c8c3ccd48939378c9c3541804296'
|
7
|
+
data.tar.gz: 42bc128206fa794262ae9bc535604f83e495c3a6363486e71a463597bc00cfb18bc641b6006951df44d68dcee65492d58d837f546aae482a9ac7165619ceb68e
|
data/lib/nisp.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Nisp
|
2
2
|
module Nisp
|
3
|
-
class
|
3
|
+
class SandboxEmptyError < StandardError
|
4
4
|
end
|
5
5
|
|
6
6
|
class FunctionUndefinedError < StandardError
|
@@ -9,6 +9,37 @@ module Nisp
|
|
9
9
|
class MacroFn < Proc
|
10
10
|
end
|
11
11
|
|
12
|
+
# Run nisp
|
13
|
+
# @param ctx [Hash] the context to run
|
14
|
+
# @return [Object]
|
15
|
+
def self.run(ctx)
|
16
|
+
sandbox = ctx[:sandbox]
|
17
|
+
raise SandboxEmptyError, 'sandbox is missing' if sandbox.nil?
|
18
|
+
|
19
|
+
ast = ctx[:ast]
|
20
|
+
|
21
|
+
if ast.is_a? Array
|
22
|
+
return if ast.size.zero?
|
23
|
+
|
24
|
+
action = arg(ctx, 0)
|
25
|
+
|
26
|
+
return apply(action, ctx) if action.is_a? Proc
|
27
|
+
|
28
|
+
unless sandbox.key? action
|
29
|
+
raise FunctionUndefinedError, "function '#{action}' is undefined"
|
30
|
+
end
|
31
|
+
|
32
|
+
fun = sandbox[action]
|
33
|
+
fun.is_a?(Proc) ? apply(fun, ctx) : fun
|
34
|
+
else
|
35
|
+
ast
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Expand an argument
|
40
|
+
# @param ctx [Hash]
|
41
|
+
# @param indes [Integer] index of the arg in the ast array
|
42
|
+
# @return [Object]
|
12
43
|
def self.arg(ctx, index)
|
13
44
|
run(
|
14
45
|
ast: ctx[:ast][index],
|
@@ -34,26 +65,4 @@ module Nisp
|
|
34
65
|
|
35
66
|
fun.call(*args)
|
36
67
|
end
|
37
|
-
|
38
|
-
def self.run(ctx)
|
39
|
-
sandbox = ctx[:sandbox]
|
40
|
-
ast = ctx[:ast]
|
41
|
-
|
42
|
-
if ast.is_a? Array
|
43
|
-
return if ast.size.zero?
|
44
|
-
|
45
|
-
action = arg(ctx, 0)
|
46
|
-
|
47
|
-
return apply(action, ctx) if action.is_a? Proc
|
48
|
-
|
49
|
-
unless sandbox.key? action
|
50
|
-
raise FunctionUndefinedError, "function #{action} is undefined"
|
51
|
-
end
|
52
|
-
|
53
|
-
fun = sandbox[action]
|
54
|
-
fun.is_a?(Proc) ? apply(fun, ctx) : fun
|
55
|
-
else
|
56
|
-
ast
|
57
|
-
end
|
58
|
-
end
|
59
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nisp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yad Smood
|
@@ -40,5 +40,5 @@ rubyforge_project:
|
|
40
40
|
rubygems_version: 2.6.14
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary:
|
43
|
+
summary: Ruby implementaion for nisp
|
44
44
|
test_files: []
|