superscript 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00b67ded3aeb2fad07a47cff4981709992b486f76ec85f29aa3b6d571243e01d
4
- data.tar.gz: fa18e3c3a839b6c38d4d9c7f9e9ee33ad1e879207121af2618e1ff76ff7b448c
3
+ metadata.gz: fb201a3a41914340c60d7f07b585c7ff699ce23df79bc6e4902b8423e3e24ccd
4
+ data.tar.gz: d929702d220e470e9b99ec543808480d1509b56db1c41cb27072a19e1ca5eba8
5
5
  SHA512:
6
- metadata.gz: 9e2ae152babd2c2d4a4f8b7ec722635745b50add2b8b03ce5bdd3ea847e47292575d1a6e09a37f4c2f7280ffa5b1ec4a985165c0933bfe75f6e584195fff95e3
7
- data.tar.gz: 6ce4abf268505db22bbce03c353200eface47a21eb548499af8d575d7659002afd51e380495026cebcf4718e23a7f7450c80395a6c9e492b46a40cf7db321d38
6
+ metadata.gz: 299732239cb63cdca05751ff18a9b65da05af80cb6e7451fc8d808ae9668f7817e3bcee06de6096db850063982a9fb08a100a3c32087bb13d615cca52147e2d3
7
+ data.tar.gz: fb5c8796aaf57b948263ceeafdd0beb9cc38ab97e26c35730b62b0b0c0fb8fa68922d8a52e26594eddad3d4e33999c2e5468b9012368c82579832031a5b0872a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superscript (0.1.0)
4
+ superscript (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/e2e/test.rb ADDED
@@ -0,0 +1 @@
1
+ go "gators"
data/exe/superscript ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "superscript"
5
+
6
+ if ARGV[0]
7
+ runner = Superscript::Runner.new ARGV[0]
8
+ runner.run!
9
+ else
10
+ ctx = Superscript::Ctx.new
11
+ runner = Superscript::Runner.new
12
+ loop do
13
+ print "> "
14
+ contents = gets
15
+ runner.run! ctx: ctx, contents: contents
16
+ end
17
+ end
data/lib/superscript.rb CHANGED
@@ -1,4 +1,6 @@
1
- require "superscript/version"
1
+ require_relative "superscript/version"
2
+ require_relative "superscript/ctx"
3
+ require_relative "superscript/runner"
2
4
 
3
5
  module Superscript
4
6
  class Error < StandardError; end
@@ -0,0 +1,29 @@
1
+ module Superscript
2
+ class Ctx
3
+ def method_missing(*args)
4
+ puts "Error: No such command or variable '#{args.first}'"
5
+ exit 1
6
+ end
7
+
8
+ def go *args
9
+ puts "Go #{args.join(" ")}!"
10
+ end
11
+
12
+ def wait seconds_or_random_range
13
+ amount = if seconds_or_random_range.is_a? Range
14
+ rand(seconds_or_random_range)
15
+ else
16
+ seconds_or_random_range
17
+ end
18
+
19
+ sleep amount
20
+ end
21
+
22
+ def exit
23
+ Kernel.exit
24
+ end
25
+ def quit
26
+ exit
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,71 @@
1
+ module Superscript
2
+ class Runner
3
+ def initialize path=nil
4
+ @path = if path
5
+ path
6
+ else
7
+ "<interactive>"
8
+ end
9
+ end
10
+
11
+ def run!(ctx:nil, contents:nil)
12
+ contents = File.read(@path) unless contents
13
+ ctx = Superscript::Ctx.new unless ctx
14
+
15
+ @armed = false
16
+ trace = TracePoint.new do |tp|
17
+ #p [@armed, tp.path, tp.lineno, tp.method_id, tp.event, tp.defined_class]
18
+
19
+ if tp.defined_class.name == "BasicObject" && tp.method_id == :instance_eval
20
+ if tp.event == :script_compiled
21
+ @armed = true
22
+ elsif tp.event == :c_return
23
+ @armed = false
24
+ end
25
+ end
26
+
27
+ if tp.event == :return && tp.defined_class.name == "Superscript::Ctx"
28
+ @armed = true
29
+ end
30
+
31
+ next unless @armed
32
+
33
+ case tp.event
34
+ when :line
35
+ puts "< " + contents.split("\n")[tp.lineno - 1]
36
+ when :c_call
37
+ @armed = false
38
+ trace.disable
39
+
40
+ puts "Error: Command not found '#{tp.method_id}'"
41
+
42
+ exit 1
43
+ when :call
44
+ if tp.defined_class.name == "Superscript::Ctx"
45
+ @armed = false
46
+ end
47
+ end
48
+ end
49
+
50
+ value = begin
51
+ trace.enable
52
+ ctx.instance_eval contents, @path
53
+ trace.disable
54
+ rescue Exception => ex
55
+ case ex.class.to_s
56
+ when "SystemExit"
57
+ exit ex.status
58
+ when "NameError"
59
+ print "#{@path}:#{ex.backtrace_locations.first.lineno} "
60
+ puts ex.message.split(" for ").first
61
+ else
62
+ p [:exception, ex]
63
+ end
64
+ ensure
65
+ trace.disable
66
+ end
67
+
68
+ value
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module Superscript
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
@@ -55,7 +55,8 @@ dependencies:
55
55
  description: superscript
56
56
  email:
57
57
  - matti.paksula@iki.fi
58
- executables: []
58
+ executables:
59
+ - superscript
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -71,7 +72,11 @@ files:
71
72
  - Rakefile
72
73
  - bin/console
73
74
  - bin/setup
75
+ - e2e/test.rb
76
+ - exe/superscript
74
77
  - lib/superscript.rb
78
+ - lib/superscript/ctx.rb
79
+ - lib/superscript/runner.rb
75
80
  - lib/superscript/version.rb
76
81
  - superscript.gemspec
77
82
  homepage: https://github.com/matti/superscript