superscript 0.3.3 → 0.4.1

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: ac52387838919d5e3aca631bd1d4f01a3e95388cf9606089f2a68af59194a10e
4
- data.tar.gz: 57ad91b5dbe5520d2b1e5e1b90f1a697f75459eaa46431b207ccb9c0bdb50d3d
3
+ metadata.gz: 1b9eb09b767191fff8dbd2b482c5b39ed0fe6a05d58604544e0e6c8d3db05660
4
+ data.tar.gz: 7a4e5dbb72eaa3c7e663ece42ca090116ae58f222309fb5d900408873bf7cb6e
5
5
  SHA512:
6
- metadata.gz: b96b4bfac46ace0e24b3b07e60b7b66871f0ad1bb9fe26bb41913b1e56caed4b08a9077121ec1f3adf1dde48d23a318857ca10dd1a97af38de78f5523990f56f
7
- data.tar.gz: 162333d3db399c975ededd7892376c3bc6cff253af6482247a56c32dda0f50aaa110fd7877a50b8d8829da35cfcc642146b670500757ee8ca5bc16c451fa27d3
6
+ metadata.gz: ad60a7b3cbfea6f5f45438afa190dd8dbe2be4f200355f345486643ba3368f3133e5639cd74b0728ba5ab7be20a8ac0eadfa94b7bf8555d174db0bf570f13b42
7
+ data.tar.gz: 5d539f831d963e171ab9d6d4e7050b6ccf5af35c0358e46d188d27a3953e872b43adb9760c615d7ed73ad5d9472adbb76450167956d58d62306acb59550f8836
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superscript (0.3.3)
4
+ superscript (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/e2e/dsls/go.rb CHANGED
@@ -3,6 +3,10 @@ class Go < Superscript::Dsl
3
3
  puts "Go #{args.join(" ")}"
4
4
  end
5
5
 
6
+ def explode!
7
+ asdf
8
+ end
9
+
6
10
  def exit
7
11
  Kernel.exit
8
12
  end
data/e2e/test.rb CHANGED
@@ -1 +1,3 @@
1
1
  go "gators"
2
+
3
+ explode!
@@ -1,8 +1,7 @@
1
1
  module Superscript
2
2
  class Ctx
3
3
  def method_missing(*args)
4
- puts "Error: No such command or variable '#{args.first}'"
5
- exit 1
4
+ ::Superscript.error :ctx_method_missing, "No such command or variable '#{args.first}'"
6
5
  end
7
6
  end
8
7
  end
@@ -1,4 +1,29 @@
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 :ctx_method_missing, :tp_singleton_method_added, :tp_command_not_found
12
+ error_message = args.first
13
+ when :tp_class_define, :tp_module_define
14
+ error_message = args.first
15
+ else
16
+ pp [:unknown_where, where, args]
17
+ error_message = args.join(" ")
18
+ end
19
+
20
+ puts error_message
21
+ if ENV["SUPERSCRIPT_ERROR_EXEC"]
22
+ error_exec_pid = spawn ENV["SUPERSCRIPT_ERROR_EXEC"], error_message
23
+ Process.wait error_exec_pid
24
+ end
25
+ exit 1
26
+ end
2
27
  class Runner
3
28
  def initialize path=nil
4
29
  @path = if path
@@ -29,24 +54,67 @@ module Superscript
29
54
  @armed = true
30
55
  end
31
56
 
57
+ # when returns to execute our script, always force armed
58
+ if tp.path == @path
59
+ @armed = true
60
+ end
61
+
32
62
  next unless @armed
33
63
 
34
64
  case tp.event
65
+ when :class
66
+ ::Superscript.error :tp_module_define, "Defining modules is not allowed"
35
67
  when :line
36
- puts "< " + contents.split("\n")[tp.lineno - 1]
68
+ lines = if tp.path == "<interactive>"
69
+ contents.split("\n")
70
+ else
71
+ File.read(tp.path).split("\n")
72
+ end
73
+
74
+ line = lines[tp.lineno-1].lstrip
75
+ puts "< #{tp.path}:#{tp.lineno-1}"
76
+ puts line
37
77
  when :c_call
38
- next if ["String","Float", "Integer"].include? tp.defined_class.name
78
+ # allow calls to these classes
79
+ next if ["Array", "String","Float", "Integer"].include? tp.defined_class.name
80
+
39
81
  case tp.method_id
40
82
  when :singleton_method_added
41
- puts "Error: Deffining methods is not allowed"
42
83
  trace.disable
43
- exit 1
84
+ ::Superscript.error :tp_singleton_method_added, "Deffining methods is not allowed"
44
85
  else
45
- puts "Error: Command not found '#{tp.method_id}'"
46
86
  trace.disable
47
- exit 1
87
+ case tp.defined_class.name
88
+ when "Class"
89
+ ::Superscript.error :tp_class_define, "Defining classes is not allowed"
90
+ else
91
+ class_name = case tp.defined_class.inspect
92
+ when "Kernel"
93
+ "Kernel"
94
+ when "Module"
95
+ "Module"
96
+ when "Exception"
97
+ "Exception"
98
+ else
99
+ class_name_matches = tp.defined_class.inspect.match(/^#<.*:(.*)>$/)
100
+ class_name_matches[1]
101
+ end
102
+
103
+ command_name = case class_name
104
+ when "Kernel", "Module", "Exception"
105
+ tp.method_id
106
+ else
107
+ "#{class_name}.#{tp.method_id}"
108
+ end
109
+
110
+ ::Superscript.error :tp_command_not_found, "Command not found '#{command_name}'"
111
+ end
48
112
  end
49
113
  when :call
114
+ # disable if calling some other file
115
+ unless tp.path == @path
116
+ @armed = false
117
+ end
50
118
  if tp.defined_class.ancestors.include? Superscript::Ctx
51
119
  @armed = false
52
120
  end
@@ -66,7 +134,7 @@ module Superscript
66
134
  print "#{@path}:#{ex.backtrace_locations.first.lineno} "
67
135
  puts ex.message.split(" for ").first
68
136
  else
69
- p [:exception, ex]
137
+ ::Superscript.error :exception, ex
70
138
  end
71
139
  ensure
72
140
  trace.disable
@@ -1,3 +1,3 @@
1
1
  module Superscript
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.1"
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.3.3
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-29 00:00:00.000000000 Z
11
+ date: 2020-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.0.4
103
+ rubygems_version: 3.0.8
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: superscript