nisp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/nisp.rb +59 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bd8270198d092eb5fefe36e39eb1d5e0692e5c7
|
4
|
+
data.tar.gz: a712c68b64a6b27624e2fa9349830da4db7c7803
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26fa5602cc5e06030613d92bf6f3fe64c5540358a0e1d78edf76c30a4531139554f24868f5ac48c115b810aa8a869bddf6ac58209b112ed7c6aaffb4999b585b
|
7
|
+
data.tar.gz: '08398c8e14eab325dfee193e3e2ef8d3df8e1b9b9f968878db479d91554145da8788e187546c55df4c4986b33fcf665d6cfeeea673c98c3c23201cfb221a5278'
|
data/lib/nisp.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Nisp
|
2
|
+
module Nisp
|
3
|
+
class ContextEmptyError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class FunctionUndefinedError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class MacroFn < Proc
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.arg(ctx, index)
|
13
|
+
run(
|
14
|
+
ast: ctx[:ast][index],
|
15
|
+
sandbox: ctx[:sandbox],
|
16
|
+
env: ctx[:env],
|
17
|
+
|
18
|
+
# private
|
19
|
+
parent: ctx,
|
20
|
+
index: index
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.apply(fun, ctx)
|
25
|
+
return fun.call(ctx) if fun.is_a? MacroFn
|
26
|
+
|
27
|
+
args = []
|
28
|
+
len = ctx[:ast].size
|
29
|
+
i = 1
|
30
|
+
while i < len
|
31
|
+
args[i - 1] = arg(ctx, i)
|
32
|
+
i += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
fun.call(*args)
|
36
|
+
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nisp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yad Smood
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: https://github.com/ysmood/nisp
|
14
|
+
email: ys@ysmood.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/nisp.rb
|
20
|
+
homepage: https://github.com/ysmood/ruby-nisp
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.14
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A language that for easily build cross-language language
|
44
|
+
test_files: []
|