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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34e85b7514e76a0fb5709c69c5cafaa87cdd42be254f708acf48564e30ea4712
4
- data.tar.gz: 6d39a6a091b1e2e8de18f875efcdea4b14d19c686ea2c626bb1f67a032f0824c
3
+ metadata.gz: 18669bdb4f911170fd797560041c0483aa4e5ed869a586e080000afc46603c63
4
+ data.tar.gz: 9a86ec4435640d5983b46a874abc4fbe0c1c50ec5ceaccc937754fa2598b11db
5
5
  SHA512:
6
- metadata.gz: 3bdaf8b254d7c0deeb2ba60e5e81bcc9718f5382e726bc4396655378fddfe38f5ba674549dcc3d54fcade64bef81acc4ef634f983ee648e00c93219026225bd3
7
- data.tar.gz: 9faf45a09a04e50e634e5ba5ce2556931c82ea5487d43e530ad8fec0d3fc317540411dfbc8dbcdc3e2e669e2c223ddd420ad90c1d7c18adf86757785a6ed91f4
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
- ConflispError = Class.new(StandardError)
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
@@ -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
- fn, *raw_args = expression
20
- fn = fn.to_s
20
+ fn_name, *raw_args = expression
21
+ fn_name = fn_name.to_s
21
22
  args = raw_args.map { |arg| resolve(arg) }
22
- if fn == 'global'
23
+ if fn_name == 'global'
23
24
  globals.dig(*args)
24
- elsif fn_defined?(fn)
25
- apply(fn, *args)
26
25
  else
27
- # TODO: It would be nice to get error messages with a stacktrace or at
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
- end
39
-
40
- def fn_defined?(fn_name)
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
- instance_exec(*args, &registry[fn_name])
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
- MethodMissing = Class.new(ConflispError)
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: 1.0.0
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: 2019-06-06 00:00:00.000000000 Z
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.71.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.71.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.16.1
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.16.1
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: '0'
109
+ version: '2.5'
95
110
  required_rubygems_version: !ruby/object:Gem::Requirement
96
111
  requirements:
97
112
  - - ">="