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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b7dee019db4e0c13b9a654eac37c84d4e736254709b2423726ecc8e559ecbe
4
- data.tar.gz: 7b7e43e336d1c7ab0a2a60eb1947efcc0afcdc3115f5b5de3f61a950b1dbd4fa
3
+ metadata.gz: 03fa28470be7d3daf81b57dfd9e87fd02a9a43980f3ef09dde087e044e39de6e
4
+ data.tar.gz: aa3102b743ef7c70aa6fa87d51536ba47303f5dbed871e8d50aadbf9b9109b94
5
5
  SHA512:
6
- metadata.gz: 51d7792af18af63fe4f37a18f99d60faa1a231e36c11ae778c11045b568b541ee4d920e63d757344a9e82b551b3969fbc5a24691afdefdb092d6f466ca90ed4b
7
- data.tar.gz: 24c1e948e23287751a7a33f6905cba77c20b6ec8672b2b468e4148d5766362a9f220aa07b4e29b461de7802cdab828ad30c24bc9d90b50312227347071465563
6
+ metadata.gz: 300c1faf4ce94007f9d6bb4077414dcef9d5c5ed2d477027d22c531c7c948913d7969fa6151fa7d0c02b69b08f76f48b7445b4ecbfc5fda58b4e635df3e6c80b
7
+ data.tar.gz: e0e8aeeb413a3cb079fe11ac30e9933a8770d1e9bea483256951319e92c25ada09bacbda7c9937146672c8e754e5a10707abb643b4833df732edbaa0f8df094b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superscript (0.5.0)
4
+ superscript (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/e2e/dsls/go.rb CHANGED
@@ -7,6 +7,10 @@ class Go < Superscript::Dsl
7
7
  puts message
8
8
  end
9
9
 
10
+ def struct
11
+ Struct.new(:name).new("joe")
12
+ end
13
+
10
14
  def now
11
15
  Time.now
12
16
  end
data/e2e/test.rb CHANGED
@@ -1 +1,5 @@
1
- go "gators"
1
+ def muna
2
+
3
+ end
4
+
5
+ muna
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
- if ARGV.length == 0
9
- puts "USAGE: superscript dsl.rb [script.rb]"
10
- exit 1
11
- end
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
@@ -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
- ::Superscript.error :tp_module_define, "Defining modules is not allowed"
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 classes
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! :safe_class
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
- ::Superscript.error :tp_singleton_method_added, "Deffining methods is not allowed"
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
- ::Superscript.error :tp_class_define, "Defining classes is not allowed"
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
- ::Superscript.error :tp_command_not_found, "Command not found '#{command_name}'"
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
- ::Superscript.error :tp_call_superscript
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
- ::Superscript.error :exception, ex
170
+ error! :exception, ex
161
171
  end
162
172
  ensure
163
173
  trace.disable
@@ -1,3 +1,3 @@
1
1
  module Superscript
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
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.5.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-20 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler