superscript 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/e2e/dsls/go.rb +4 -0
- data/e2e/test.rb +5 -1
- data/exe/superscript +13 -6
- data/lib/superscript/runner.rb +46 -36
- data/lib/superscript/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03fa28470be7d3daf81b57dfd9e87fd02a9a43980f3ef09dde087e044e39de6e
|
4
|
+
data.tar.gz: aa3102b743ef7c70aa6fa87d51536ba47303f5dbed871e8d50aadbf9b9109b94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 300c1faf4ce94007f9d6bb4077414dcef9d5c5ed2d477027d22c531c7c948913d7969fa6151fa7d0c02b69b08f76f48b7445b4ecbfc5fda58b4e635df3e6c80b
|
7
|
+
data.tar.gz: e0e8aeeb413a3cb079fe11ac30e9933a8770d1e9bea483256951319e92c25ada09bacbda7c9937146672c8e754e5a10707abb643b4833df732edbaa0f8df094b
|
data/Gemfile.lock
CHANGED
data/e2e/dsls/go.rb
CHANGED
data/e2e/test.rb
CHANGED
data/exe/superscript
CHANGED
@@ -4,11 +4,18 @@ $stdout.sync = true
|
|
4
4
|
|
5
5
|
require "bundler/setup"
|
6
6
|
require "superscript"
|
7
|
+
require "optparse"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
options = {
|
10
|
+
methods: false,
|
11
|
+
on_error_exec: nil
|
12
|
+
}
|
13
|
+
ARGV << "-h" if ARGV.empty?
|
14
|
+
|
15
|
+
optparse = OptionParser.new do |opt|
|
16
|
+
opt.on('--allow-methods') { |o| options[:methods] = true }
|
17
|
+
opt.on('--on-error-exec CMD') { |o| options[:on_error_exec] = o }
|
18
|
+
end.parse!
|
12
19
|
|
13
20
|
best_guess_path = if ARGV[0].start_with? "/"
|
14
21
|
ARGV[0]
|
@@ -22,10 +29,10 @@ ctx_classname = File.basename(ARGV[0]).split(".").first.capitalize
|
|
22
29
|
ctx = (eval "#{ctx_classname}").new
|
23
30
|
|
24
31
|
if ARGV[1]
|
25
|
-
runner = Superscript::Runner.new ARGV[1]
|
32
|
+
runner = Superscript::Runner.new ARGV[1], options
|
26
33
|
runner.run! ctx
|
27
34
|
else
|
28
|
-
runner = Superscript::Runner.new
|
35
|
+
runner = Superscript::Runner.new nil, options
|
29
36
|
loop do
|
30
37
|
print "> "
|
31
38
|
contents = STDIN.gets
|
data/lib/superscript/runner.rb
CHANGED
@@ -1,33 +1,9 @@
|
|
1
1
|
module Superscript
|
2
|
-
def self.error(where, *args)
|
3
|
-
puts "-- [ superscript error ] --"
|
4
|
-
error_message = ""
|
5
|
-
case where
|
6
|
-
when :exception
|
7
|
-
exception = args.first
|
8
|
-
pp exception
|
9
|
-
pp exception.backtrace_locations
|
10
|
-
error_message = exception
|
11
|
-
when :tp_call_superscript
|
12
|
-
error_message = "Can't touch this"
|
13
|
-
when :ctx_method_missing, :tp_singleton_method_added, :tp_command_not_found
|
14
|
-
error_message = args.first
|
15
|
-
when :tp_class_define, :tp_module_define
|
16
|
-
error_message = args.first
|
17
|
-
else
|
18
|
-
pp [:unknown_where, where, args]
|
19
|
-
error_message = args.join(" ")
|
20
|
-
end
|
21
|
-
|
22
|
-
puts error_message
|
23
|
-
if ENV["SUPERSCRIPT_ERROR_EXEC"]
|
24
|
-
error_exec_pid = spawn ENV["SUPERSCRIPT_ERROR_EXEC"], error_message
|
25
|
-
Process.wait error_exec_pid
|
26
|
-
end
|
27
|
-
exit 1
|
28
|
-
end
|
29
2
|
class Runner
|
30
|
-
def initialize path=nil
|
3
|
+
def initialize path=nil, opts={}
|
4
|
+
@methods = opts[:methods] || false
|
5
|
+
@on_error_exec = opts[:on_error_exec]
|
6
|
+
|
31
7
|
@armed = false
|
32
8
|
@path = if path
|
33
9
|
path
|
@@ -36,6 +12,33 @@ module Superscript
|
|
36
12
|
end
|
37
13
|
end
|
38
14
|
|
15
|
+
def error!(where, *args)
|
16
|
+
puts "-- [ superscript error ] --"
|
17
|
+
error_message = ""
|
18
|
+
case where
|
19
|
+
when :exception
|
20
|
+
exception = args.first
|
21
|
+
pp exception
|
22
|
+
pp exception.backtrace_locations
|
23
|
+
error_message = exception
|
24
|
+
when :tp_call_superscript
|
25
|
+
error_message = "Can't touch this"
|
26
|
+
when :ctx_method_missing, :tp_singleton_method_added, :tp_command_not_found
|
27
|
+
error_message = args.first
|
28
|
+
when :tp_class_define, :tp_module_define
|
29
|
+
error_message = args.first
|
30
|
+
else
|
31
|
+
pp [:unknown_where, where, args]
|
32
|
+
error_message = args.join(" ")
|
33
|
+
end
|
34
|
+
|
35
|
+
puts error_message
|
36
|
+
if @on_error_exec
|
37
|
+
system("#{@on_error_exec} #{error_message}")
|
38
|
+
end
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
39
42
|
def arm!(reason=nil)
|
40
43
|
p [:arm!, reason] if ENV["SUPERSCRIPT_DEBUG"]
|
41
44
|
@armed = true
|
@@ -74,7 +77,7 @@ module Superscript
|
|
74
77
|
|
75
78
|
case tp.event
|
76
79
|
when :class
|
77
|
-
|
80
|
+
error! :tp_module_define, "Defining modules is not allowed"
|
78
81
|
when :line
|
79
82
|
lines = if tp.path == "<interactive>"
|
80
83
|
contents.split("\n")
|
@@ -86,21 +89,28 @@ module Superscript
|
|
86
89
|
puts "< #{tp.path}:#{tp.lineno-1}"
|
87
90
|
puts line
|
88
91
|
when :c_call
|
89
|
-
# allow calls to these
|
92
|
+
# allow calls to these instances
|
93
|
+
if tp.defined_class.ancestors.at(1) == Struct
|
94
|
+
disarm! :safe_instance
|
95
|
+
next
|
96
|
+
end
|
90
97
|
if ["Array", "String","Float", "Integer"].include? tp.defined_class.name
|
91
|
-
disarm! :
|
98
|
+
disarm! :safe_instance
|
92
99
|
next
|
93
100
|
end
|
94
101
|
|
95
102
|
case tp.method_id
|
96
103
|
when :singleton_method_added
|
104
|
+
if @methods
|
105
|
+
next
|
106
|
+
end
|
97
107
|
trace.disable
|
98
|
-
|
108
|
+
error! :tp_singleton_method_added, "Deffining methods is not allowed"
|
99
109
|
else
|
100
110
|
trace.disable
|
101
111
|
case tp.defined_class.name
|
102
112
|
when "Class"
|
103
|
-
|
113
|
+
error! :tp_class_define, "Defining classes is not allowed"
|
104
114
|
else
|
105
115
|
class_name = case tp.defined_class.inspect
|
106
116
|
when "Kernel"
|
@@ -121,13 +131,13 @@ module Superscript
|
|
121
131
|
"#{class_name}.#{tp.method_id}"
|
122
132
|
end
|
123
133
|
|
124
|
-
|
134
|
+
error! :tp_command_not_found, "Command not found '#{command_name}'"
|
125
135
|
end
|
126
136
|
end
|
127
137
|
when :call
|
128
138
|
if tp.defined_class.ancestors.first.to_s == "#<Class:Superscript>"
|
129
139
|
tp.disable
|
130
|
-
|
140
|
+
error! :tp_call_superscript
|
131
141
|
end
|
132
142
|
# disable if calling some other file
|
133
143
|
# but do not allow call to Superscript.error etc
|
@@ -157,7 +167,7 @@ module Superscript
|
|
157
167
|
print "#{@path}:#{ex.backtrace_locations.first.lineno} "
|
158
168
|
puts ex.message.split(" for ").first
|
159
169
|
else
|
160
|
-
|
170
|
+
error! :exception, ex
|
161
171
|
end
|
162
172
|
ensure
|
163
173
|
trace.disable
|
data/lib/superscript/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|