code-ruby 1.2.7 → 1.4.0
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/Gemfile.lock +79 -63
- data/TODO +219 -0
- data/VERSION +1 -1
- data/bin/code +3 -0
- data/lib/code/concerns/shared.rb +423 -0
- data/lib/code/concerns.rb +6 -0
- data/lib/code/object/code.rb +6 -0
- data/lib/code/object/dictionary.rb +6 -0
- data/lib/code/object/global.rb +6 -1
- data/lib/code/object/list.rb +17 -0
- data/lib/code/object/nothing.rb +8 -0
- data/lib/code/object/string.rb +23 -3
- data/lib/code/object.rb +8 -446
- data/lib/code/parser/call.rb +7 -2
- data/lib/code/parser/class.rb +1 -34
- data/lib/code/parser/function.rb +18 -2
- data/lib/code/parser/group.rb +14 -0
- data/lib/code/parser/if.rb +25 -4
- data/lib/code/parser/name.rb +11 -2
- data/lib/code/parser/while.rb +26 -1
- data/lib/code-ruby.rb +12 -0
- data/lib/code.rb +25 -18
- data/spec/code_spec.rb +2 -0
- metadata +5 -2
data/lib/code/parser/while.rb
CHANGED
@@ -11,6 +11,10 @@ class Code
|
|
11
11
|
Whitespace
|
12
12
|
end
|
13
13
|
|
14
|
+
def whitespace?
|
15
|
+
whitespace.maybe
|
16
|
+
end
|
17
|
+
|
14
18
|
def code
|
15
19
|
Code
|
16
20
|
end
|
@@ -27,10 +31,31 @@ class Code
|
|
27
31
|
str("end")
|
28
32
|
end
|
29
33
|
|
34
|
+
def do_keyword
|
35
|
+
str("do")
|
36
|
+
end
|
37
|
+
|
38
|
+
def begin_keyword
|
39
|
+
str("begin")
|
40
|
+
end
|
41
|
+
|
30
42
|
def loop_keyword
|
31
43
|
str("loop")
|
32
44
|
end
|
33
45
|
|
46
|
+
def opening_curly_bracket
|
47
|
+
str("{")
|
48
|
+
end
|
49
|
+
|
50
|
+
def closing_curly_bracket
|
51
|
+
str("}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def body
|
55
|
+
((do_keyword | begin_keyword) << code << end_keyword.maybe) |
|
56
|
+
(opening_curly_bracket << code << closing_curly_bracket) | code
|
57
|
+
end
|
58
|
+
|
34
59
|
def root
|
35
60
|
(
|
36
61
|
(
|
@@ -38,7 +63,7 @@ class Code
|
|
38
63
|
(while_keyword | until_keyword).aka(:operator) << whitespace <<
|
39
64
|
statement.aka(:statement)
|
40
65
|
) | (loop_keyword.aka(:operator) << whitespace)
|
41
|
-
) <<
|
66
|
+
) << body.aka(:body)
|
42
67
|
).aka(:while) | statement
|
43
68
|
end
|
44
69
|
end
|
data/lib/code-ruby.rb
CHANGED
@@ -72,6 +72,18 @@ class Object
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
class Class
|
76
|
+
def to_code
|
77
|
+
Code::Object::Class.new(self)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Module
|
82
|
+
def to_code
|
83
|
+
Code::Object::Class.new(self)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
75
87
|
class NilClass
|
76
88
|
def to_code
|
77
89
|
Code::Object::Nothing.new(self)
|
data/lib/code.rb
CHANGED
@@ -1,43 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Code
|
4
|
-
GLOBALS = %i[
|
4
|
+
GLOBALS = %i[context error input object output source object].freeze
|
5
5
|
DEFAULT_TIMEOUT = 0
|
6
6
|
|
7
7
|
def initialize(
|
8
|
-
|
9
|
-
|
8
|
+
source,
|
9
|
+
context: Object::Context.new,
|
10
10
|
error: StringIO.new,
|
11
|
+
input: StringIO.new,
|
12
|
+
object: Object::Global.new,
|
13
|
+
output: StringIO.new,
|
11
14
|
timeout: DEFAULT_TIMEOUT
|
12
15
|
)
|
16
|
+
@context = context
|
17
|
+
@error = error
|
13
18
|
@input = input
|
19
|
+
@object = object
|
14
20
|
@output = output
|
15
|
-
@
|
16
|
-
@timeout = timeout
|
17
|
-
@context = Object::Context.new
|
21
|
+
@source = source
|
22
|
+
@timeout = timeout
|
18
23
|
end
|
19
24
|
|
20
|
-
def self.parse(
|
21
|
-
Timeout.timeout(timeout) { Parser.parse(
|
25
|
+
def self.parse(source, timeout: DEFAULT_TIMEOUT)
|
26
|
+
Timeout.timeout(timeout) { Parser.parse(source).to_raw }
|
22
27
|
end
|
23
28
|
|
24
|
-
def self.evaluate(
|
25
|
-
|
26
|
-
output: StringIO.new,
|
27
|
-
error: StringIO.new,
|
28
|
-
timeout: DEFAULT_TIMEOUT
|
29
|
-
)
|
30
|
-
new(input, output:, error:, timeout:).evaluate
|
29
|
+
def self.evaluate(...)
|
30
|
+
new(...).evaluate
|
31
31
|
end
|
32
32
|
|
33
33
|
def evaluate
|
34
34
|
Timeout.timeout(timeout) do
|
35
|
-
|
36
|
-
|
35
|
+
Node::Code.new(Code.parse(source)).evaluate(
|
36
|
+
context:,
|
37
|
+
error:,
|
38
|
+
input:,
|
39
|
+
object:,
|
40
|
+
output:,
|
41
|
+
source:,
|
42
|
+
timeout:
|
43
|
+
)
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
40
47
|
private
|
41
48
|
|
42
|
-
attr_reader :input, :
|
49
|
+
attr_reader :context, :error, :input, :object, :output, :source, :timeout
|
43
50
|
end
|
data/spec/code_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- LICENSE
|
186
186
|
- README.md
|
187
187
|
- Rakefile
|
188
|
+
- TODO
|
188
189
|
- VERSION
|
189
190
|
- bin/bundle
|
190
191
|
- bin/bundle-audit
|
@@ -198,6 +199,8 @@ files:
|
|
198
199
|
- code-ruby.gemspec
|
199
200
|
- lib/code-ruby.rb
|
200
201
|
- lib/code.rb
|
202
|
+
- lib/code/concerns.rb
|
203
|
+
- lib/code/concerns/shared.rb
|
201
204
|
- lib/code/error.rb
|
202
205
|
- lib/code/node.rb
|
203
206
|
- lib/code/node/base_10.rb
|