conflisp 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/conflisp/conflisp_error.rb +20 -1
- data/lib/conflisp/evaluator.rb +16 -13
- data/lib/conflisp/method_missing.rb +7 -1
- data/lib/conflisp/runtime_error.rb +18 -0
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18669bdb4f911170fd797560041c0483aa4e5ed869a586e080000afc46603c63
|
4
|
+
data.tar.gz: 9a86ec4435640d5983b46a874abc4fbe0c1c50ec5ceaccc937754fa2598b11db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a12a5bc2b3b9f1c2ebd965c2296cb3a2082d88ba65084ac13deedb0006fc5bb8043d592d05c2aae0114623d5ebff02497d22a2654fec83413db2595f877853f
|
7
|
+
data.tar.gz: a96e3993311539fa5152704047fc1a32e72fa52bd991992082c5129ff0e3307ea68b707be612deb6e896bbe09685f4537b4d8a73ffac525fdf6ad09d2f49ea79
|
@@ -1,5 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Conflisp
|
4
|
-
|
4
|
+
# Base class for ConflispError
|
5
|
+
class ConflispError < StandardError
|
6
|
+
attr_reader :conflisp_stack
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
|
11
|
+
@conflisp_stack = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
ret = super
|
16
|
+
|
17
|
+
conflisp_stack.each do |expression|
|
18
|
+
ret += "\n in expression #{expression}"
|
19
|
+
end
|
20
|
+
|
21
|
+
ret
|
22
|
+
end
|
23
|
+
end
|
5
24
|
end
|
data/lib/conflisp/evaluator.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'conflisp/method_missing'
|
4
|
+
require 'conflisp/runtime_error'
|
4
5
|
|
5
6
|
module Conflisp
|
6
7
|
# Evaluator takes s-expressions and resolves them into Ruby values
|
@@ -16,17 +17,13 @@ module Conflisp
|
|
16
17
|
case expression
|
17
18
|
when Array
|
18
19
|
# In Lisp, Arrays are function calls
|
19
|
-
|
20
|
-
|
20
|
+
fn_name, *raw_args = expression
|
21
|
+
fn_name = fn_name.to_s
|
21
22
|
args = raw_args.map { |arg| resolve(arg) }
|
22
|
-
if
|
23
|
+
if fn_name == 'global'
|
23
24
|
globals.dig(*args)
|
24
|
-
elsif fn_defined?(fn)
|
25
|
-
apply(fn, *args)
|
26
25
|
else
|
27
|
-
|
28
|
-
# least some context about the parent expressions
|
29
|
-
raise MethodMissing, "Unknown fn #{fn} in expression #{expression}"
|
26
|
+
apply(fn_name, *args)
|
30
27
|
end
|
31
28
|
when Hash
|
32
29
|
expression.transform_values do |value|
|
@@ -35,14 +32,20 @@ module Conflisp
|
|
35
32
|
else
|
36
33
|
expression
|
37
34
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
registry.key?(fn_name)
|
35
|
+
rescue Conflisp::ConflispError => e
|
36
|
+
e.conflisp_stack << expression
|
37
|
+
raise e
|
42
38
|
end
|
43
39
|
|
44
40
|
def apply(fn_name, *args)
|
45
|
-
|
41
|
+
method = registry[fn_name]
|
42
|
+
raise Conflisp::MethodMissing, fn_name unless method
|
43
|
+
|
44
|
+
begin
|
45
|
+
instance_exec(*args, &method)
|
46
|
+
rescue StandardError => e
|
47
|
+
raise Conflisp::RuntimeError.new(e, [fn_name, *args])
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -3,5 +3,11 @@
|
|
3
3
|
require 'conflisp/conflisp_error'
|
4
4
|
|
5
5
|
module Conflisp
|
6
|
-
|
6
|
+
# Error raised when a function is not found
|
7
|
+
class MethodMissing < ConflispError
|
8
|
+
def initialize(fn_name)
|
9
|
+
message = "Unknown fn `#{fn_name}`"
|
10
|
+
super(message)
|
11
|
+
end
|
12
|
+
end
|
7
13
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'conflisp/conflisp_error'
|
4
|
+
|
5
|
+
module Conflisp
|
6
|
+
# Error raised when evaluation of a Conflisp expression fails
|
7
|
+
class RuntimeError < ConflispError
|
8
|
+
attr_reader :original_error
|
9
|
+
|
10
|
+
def initialize(error, expression)
|
11
|
+
message = "#{error.class.name}: #{error.message}"
|
12
|
+
message += "\n while evaluating #{expression}"
|
13
|
+
super(message)
|
14
|
+
|
15
|
+
@original_error = error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conflisp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rocky Meza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -44,28 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.93.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.93.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.19.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.19.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov-lcov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.0
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- rocky@geteverwise.com
|
@@ -79,6 +93,7 @@ files:
|
|
79
93
|
- lib/conflisp/evaluator.rb
|
80
94
|
- lib/conflisp/language.rb
|
81
95
|
- lib/conflisp/method_missing.rb
|
96
|
+
- lib/conflisp/runtime_error.rb
|
82
97
|
homepage: https://github.com/everwise/conflisp
|
83
98
|
licenses:
|
84
99
|
- MIT
|
@@ -91,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
106
|
requirements:
|
92
107
|
- - ">="
|
93
108
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
109
|
+
version: '2.5'
|
95
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
111
|
requirements:
|
97
112
|
- - ">="
|