superscript 0.5.0 → 0.9.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 +15 -0
- data/e2e/test.rb +2 -1
- data/exe/superscript +25 -8
- data/lib/superscript/ctx.rb +0 -3
- data/lib/superscript/runner.rb +67 -36
- data/lib/superscript/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b27edffef105a196cb8786e25e3079cc8b3c612f4963f8ba3792db2bc4a5fa
|
4
|
+
data.tar.gz: 470039bbf662e48148d9b3f664b9b22624b116113c44b8a5a15c58c666aea8f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6be2215c8cfd8bfb0476c0805eaeca62eb1902fcb01f114de667b2cc0fe2dc700b00e122a6729a1d423c4d7309e4d8c49351dcad894321546dc4e9ae58c41a24
|
7
|
+
data.tar.gz: 44e017dc745a0c216aa881698057b1299a43da81ddcc3652cc9fa65d67e381df26387cc97ba7fa671653571ff3a802cf27162f11863b11843de9a80f9a55e2e9
|
data/Gemfile.lock
CHANGED
data/e2e/dsls/go.rb
CHANGED
@@ -3,10 +3,25 @@ class Go < Superscript::Dsl
|
|
3
3
|
self.say "Go #{args.join(" ")}!"
|
4
4
|
end
|
5
5
|
|
6
|
+
def loop &block
|
7
|
+
::Kernel.loop do
|
8
|
+
block.call
|
9
|
+
sleep 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def hang
|
14
|
+
sleep 9999
|
15
|
+
end
|
16
|
+
|
6
17
|
def say(message)
|
7
18
|
puts message
|
8
19
|
end
|
9
20
|
|
21
|
+
def struct
|
22
|
+
Struct.new(:name).new("joe")
|
23
|
+
end
|
24
|
+
|
10
25
|
def now
|
11
26
|
Time.now
|
12
27
|
end
|
data/e2e/test.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
a = struct
|
2
|
+
go a.name
|
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,13 +29,23 @@ 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
|
-
|
35
|
+
require "readline"
|
36
|
+
|
37
|
+
runner = Superscript::Runner.new nil, options
|
29
38
|
loop do
|
30
|
-
|
31
|
-
contents
|
39
|
+
contents = Readline.readline "> ", true
|
40
|
+
next if contents == ""
|
41
|
+
|
42
|
+
if contents == nil
|
43
|
+
puts "\n-- press ^D to end input"
|
44
|
+
contents = $stdin.readlines.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
next if contents == ""
|
48
|
+
|
32
49
|
value = runner.run! ctx, contents: contents
|
33
50
|
puts " => #{value.inspect}"
|
34
51
|
end
|
data/lib/superscript/ctx.rb
CHANGED
data/lib/superscript/runner.rb
CHANGED
@@ -1,33 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
1
|
+
Signal.trap "TERM" do
|
2
|
+
exit 0
|
3
|
+
end
|
21
4
|
|
22
|
-
|
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
|
5
|
+
module Superscript
|
29
6
|
class Runner
|
30
|
-
def initialize path=nil
|
7
|
+
def initialize path=nil, opts={}
|
8
|
+
@methods = opts[:methods] || false
|
9
|
+
@on_error_exec = opts[:on_error_exec]
|
10
|
+
|
31
11
|
@armed = false
|
32
12
|
@path = if path
|
33
13
|
path
|
@@ -36,6 +16,34 @@ module Superscript
|
|
36
16
|
end
|
37
17
|
end
|
38
18
|
|
19
|
+
def error!(where, *args)
|
20
|
+
puts "-- [ superscript error ] --"
|
21
|
+
error_message = ""
|
22
|
+
case where
|
23
|
+
when :exception
|
24
|
+
exception = args.first
|
25
|
+
error_message = exception
|
26
|
+
when :tp_call_superscript, :tp_call_superscript_global
|
27
|
+
error_message = "Can't touch this"
|
28
|
+
when :ctx_method_missing, :tp_singleton_method_added, :tp_command_not_found
|
29
|
+
error_message = args.first
|
30
|
+
when :tp_class_define, :tp_module_define
|
31
|
+
error_message = args.first
|
32
|
+
else
|
33
|
+
pp [:unknown_where, where, args]
|
34
|
+
error_message = args.join(" ")
|
35
|
+
end
|
36
|
+
|
37
|
+
puts error_message
|
38
|
+
if @on_error_exec
|
39
|
+
system("#{@on_error_exec} #{error_message}")
|
40
|
+
end
|
41
|
+
|
42
|
+
unless @path == "<interactive>"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
39
47
|
def arm!(reason=nil)
|
40
48
|
p [:arm!, reason] if ENV["SUPERSCRIPT_DEBUG"]
|
41
49
|
@armed = true
|
@@ -47,6 +55,10 @@ module Superscript
|
|
47
55
|
|
48
56
|
def run!(ctx, contents:nil)
|
49
57
|
contents = File.read(@path) unless contents
|
58
|
+
$__superscript_none_of_yer_business = self
|
59
|
+
ctx.define_singleton_method "method_missing" do |*args|
|
60
|
+
$__superscript_none_of_yer_business.error! :ctx_method_missing, "No such command or variable '#{args.first}'"
|
61
|
+
end
|
50
62
|
|
51
63
|
disarm! :at_start
|
52
64
|
trace = TracePoint.new do |tp|
|
@@ -74,7 +86,7 @@ module Superscript
|
|
74
86
|
|
75
87
|
case tp.event
|
76
88
|
when :class
|
77
|
-
|
89
|
+
error! :tp_module_define, "Defining modules is not allowed"
|
78
90
|
when :line
|
79
91
|
lines = if tp.path == "<interactive>"
|
80
92
|
contents.split("\n")
|
@@ -85,22 +97,36 @@ module Superscript
|
|
85
97
|
line = lines[tp.lineno-1].lstrip
|
86
98
|
puts "< #{tp.path}:#{tp.lineno-1}"
|
87
99
|
puts line
|
100
|
+
|
101
|
+
if line.match(/\$__superscript_none_of_yer_business/)
|
102
|
+
tp.disable
|
103
|
+
error! :tp_call_superscript_global
|
104
|
+
end
|
88
105
|
when :c_call
|
89
|
-
# allow calls to these
|
106
|
+
# allow calls to these instances
|
107
|
+
if tp.defined_class.ancestors.at(1) == Struct
|
108
|
+
disarm! :safe_instance
|
109
|
+
next
|
110
|
+
end
|
90
111
|
if ["Array", "String","Float", "Integer"].include? tp.defined_class.name
|
91
|
-
disarm! :
|
112
|
+
disarm! :safe_instance
|
92
113
|
next
|
93
114
|
end
|
94
115
|
|
95
116
|
case tp.method_id
|
96
117
|
when :singleton_method_added
|
118
|
+
if @methods
|
119
|
+
next
|
120
|
+
end
|
121
|
+
trace.disable
|
122
|
+
error! :tp_singleton_method_added, "Deffining methods is not allowed"
|
123
|
+
when :method_missing
|
97
124
|
trace.disable
|
98
|
-
::Superscript.error :tp_singleton_method_added, "Deffining methods is not allowed"
|
99
125
|
else
|
100
126
|
trace.disable
|
101
127
|
case tp.defined_class.name
|
102
128
|
when "Class"
|
103
|
-
|
129
|
+
error! :tp_class_define, "Defining classes is not allowed"
|
104
130
|
else
|
105
131
|
class_name = case tp.defined_class.inspect
|
106
132
|
when "Kernel"
|
@@ -121,13 +147,18 @@ module Superscript
|
|
121
147
|
"#{class_name}.#{tp.method_id}"
|
122
148
|
end
|
123
149
|
|
124
|
-
|
150
|
+
error! :tp_command_not_found, "Command not found '#{command_name}'"
|
125
151
|
end
|
126
152
|
end
|
127
153
|
when :call
|
154
|
+
if tp.method_id == :method_missing
|
155
|
+
tp.disable
|
156
|
+
next
|
157
|
+
end
|
158
|
+
|
128
159
|
if tp.defined_class.ancestors.first.to_s == "#<Class:Superscript>"
|
129
160
|
tp.disable
|
130
|
-
|
161
|
+
error! :tp_call_superscript
|
131
162
|
end
|
132
163
|
# disable if calling some other file
|
133
164
|
# but do not allow call to Superscript.error etc
|
@@ -157,7 +188,7 @@ module Superscript
|
|
157
188
|
print "#{@path}:#{ex.backtrace_locations.first.lineno} "
|
158
189
|
puts ex.message.split(" for ").first
|
159
190
|
else
|
160
|
-
|
191
|
+
error! :exception, ex
|
161
192
|
end
|
162
193
|
ensure
|
163
194
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,7 @@ homepage: https://github.com/matti/superscript
|
|
85
85
|
licenses:
|
86
86
|
- MIT
|
87
87
|
metadata: {}
|
88
|
-
post_install_message:
|
88
|
+
post_install_message:
|
89
89
|
rdoc_options: []
|
90
90
|
require_paths:
|
91
91
|
- lib
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubygems_version: 3.0.8
|
104
|
-
signing_key:
|
104
|
+
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: superscript
|
107
107
|
test_files: []
|