intar 2.12 → 2.14

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: a0b8c82a2fd61d3a7fe7be7078c4cf96b37dabd18c00c25ad84a51cb34d06445
4
- data.tar.gz: c8045ce6959c1fda974eec564229bbe95b2adf2acd9470c650863f4e405f7adf
3
+ metadata.gz: dfabe8ba50f5502971175b8ec48582e1c24d68b75cf164ed10b7b1545b8ed1ec
4
+ data.tar.gz: 376905c4c3f81b252662f6df9803ad8bd9038475c8ccc5c9adc6f79239f5c3c8
5
5
  SHA512:
6
- metadata.gz: a3a6d77c597107d260b723a107feae4049a31c81654b420169ef4ec6db55eaa1e23e47f9357f74b9d80308439acfb39da6d14c3d68a09be992d3636b99caf1ca
7
- data.tar.gz: 950d148dc9e33d4d840c3d9187de1db39ebc0b2cabc046f334c8474202f180b4db9e0a65e8f9086f7856f3a858cc5fafae11ffe7f4788a0f77bdef9385ee0d0d
6
+ metadata.gz: 9cf36852e6c4387d6eb85ac8b9dafaced557033bc7be3004eae58ea22529155d08cd7e213d9cfb5a3f630e8ac84b04113e35d39a5f811388c1dcc339b56fc9b0
7
+ data.tar.gz: 156c61b56e014f810f45da42a7500a9ce6b5f937b090eb3d2f6e591c786441b0f51ffb0c5c353ba56e7ece4d9205546f6a9fad48d3bda726b6b6970f2e5ac102
data/README CHANGED
@@ -23,9 +23,9 @@ after this in Irb and in Intar:
23
23
 
24
24
  === Subcommands
25
25
 
26
- obj.method & enter a sub-Intar
27
- obj.each & enter multiple sub-Intars
28
- obj.method &x enter a sub-Intar with variable x
26
+ obj.method ! enter a sub-Intar
27
+ obj.each ! enter multiple sub-Intars
28
+ obj.method !x enter a sub-Intar with variable x
29
29
 
30
30
  \q exit from the innermost sub-Intar
31
31
  \q! exit from the innermost sub-Intar loop
data/lib/intar/prompt.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
 
5
5
  require "supplement"
6
- require "readline"
6
+ require "reline"
7
7
 
8
8
 
9
9
  class Intar
@@ -12,23 +12,23 @@ class Intar
12
12
 
13
13
  def initialize histfile: nil, limit: nil
14
14
  @limit = limit.nonzero?
15
- Readline::HISTORY.clear
15
+ Reline::HISTORY.clear
16
16
  @new = 0
17
17
  end
18
18
 
19
19
  def push text
20
- Readline.pre_input_hook = proc {
21
- Readline.insert_text text
22
- Readline.redisplay
20
+ Reline.pre_input_hook = proc {
21
+ Reline.insert_text text
22
+ Reline.redisplay
23
23
  }
24
24
  nil
25
25
  end
26
26
 
27
27
  def ask prompt
28
28
  begin
29
- Readline.readline prompt
29
+ Reline.readline prompt
30
30
  ensure
31
- Readline.pre_input_hook = nil
31
+ Reline.pre_input_hook = nil
32
32
  end
33
33
  rescue Interrupt
34
34
  puts
@@ -39,21 +39,21 @@ class Intar
39
39
  end
40
40
 
41
41
  def last
42
- Readline::HISTORY[-1] unless Readline::HISTORY.empty?
42
+ Reline::HISTORY[-1] unless Reline::HISTORY.empty?
43
43
  end
44
44
 
45
45
  def scan_history
46
- i = Readline::HISTORY.length
46
+ i = Reline::HISTORY.length
47
47
  while i > 0 do
48
48
  i -= 1
49
- yield Readline::HISTORY[i]
49
+ yield Reline::HISTORY[i]
50
50
  end
51
51
  end
52
52
 
53
53
  def push_history item
54
54
  item.empty? and return
55
55
  last != item or return
56
- Readline::HISTORY.push item
56
+ Reline::HISTORY.push item
57
57
  @new += 1
58
58
  end
59
59
 
@@ -61,14 +61,14 @@ class Intar
61
61
  with_filepath filepath do |p|
62
62
  read_file_if p do |f|
63
63
  h = []
64
- @new.times { h.push Readline::HISTORY.pop }
65
- Readline::HISTORY.clear
64
+ @new.times { h.push Reline::HISTORY.pop }
65
+ Reline::HISTORY.clear
66
66
  f.each_line { |l|
67
67
  l.chomp!
68
68
  l.sub! "\r", "\n"
69
- Readline::HISTORY.push l
69
+ Reline::HISTORY.push l
70
70
  }
71
- Readline::HISTORY.push h.pop while h.any?
71
+ Reline::HISTORY.push h.pop while h.any?
72
72
  end
73
73
  nil
74
74
  end
@@ -86,9 +86,9 @@ class Intar
86
86
  end
87
87
  File.open p, "w" do |f|
88
88
  old.each { |l| f.puts l }
89
- i = Readline::HISTORY.length - @new
90
- while i < Readline::HISTORY.length do
91
- l = Readline::HISTORY[ i].sub "\n", "\r"
89
+ i = Reline::HISTORY.length - @new
90
+ while i < Reline::HISTORY.length do
91
+ l = Reline::HISTORY[ i].sub "\n", "\r"
92
92
  f.puts l
93
93
  i += 1
94
94
  end
@@ -99,8 +99,8 @@ class Intar
99
99
  end
100
100
 
101
101
  def limit_history max
102
- n = Readline::HISTORY.length - max
103
- n.times { Readline::HISTORY.shift }
102
+ n = Reline::HISTORY.length - max
103
+ n.times { Reline::HISTORY.shift }
104
104
  @new > max and @new = max
105
105
  nil
106
106
  end
data/lib/intar/version.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  class Intar
6
6
 
7
- VERSION = "2.12".freeze
7
+ VERSION = "2.14".freeze
8
8
 
9
9
  end
10
10
 
data/lib/intar.rb CHANGED
@@ -40,9 +40,7 @@ everywhere inside your Ruby program.
40
40
 
41
41
 
42
42
  class Object
43
- def intar_binding
44
- binding
45
- end
43
+ def empty_binding ; binding ; end
46
44
  end
47
45
 
48
46
 
@@ -50,15 +48,21 @@ class Intar
50
48
 
51
49
  class <<self
52
50
 
53
- def open obj = nil, **params
51
+ def open obj = main, **params
54
52
  i = new obj, **params
55
53
  yield i
56
54
  end
57
55
 
58
- def run obj = nil, **params
56
+ def run obj = main, **params
59
57
  open obj, **params do |i| i.run end
60
58
  end
61
59
 
60
+ private
61
+
62
+ def main
63
+ TOPLEVEL_BINDING.eval "self"
64
+ end
65
+
62
66
  end
63
67
 
64
68
 
@@ -74,25 +78,33 @@ class Intar
74
78
  histmax: 500,
75
79
  }
76
80
 
77
- @@current = nil
78
81
 
79
- attr_reader :params, :prompt, :depth, :n, :binding
82
+ private
83
+
84
+ @@prev = nil
85
+
86
+ SET_BINDING = "proc { |_| _.instance_eval { binding } }"
87
+
80
88
  def initialize obj = nil, **params
81
- @obj = obj.nil? ? (eval "self", TOPLEVEL_BINDING) : obj
82
- if @@current then
83
- @params = @@current.params
84
- @prompt = @@current.prompt
85
- @depth = @@current.depth + 1
86
- @binding = @@current.binding
89
+ @obj = obj
90
+ @n = 1
91
+ if @@prev then
92
+ @params = @@prev.params
93
+ @prompt = @@prev.prompt
94
+ @depth = @@prev.depth + 1
95
+ sb = @@prev.execute SET_BINDING
87
96
  else
88
97
  @params = DEFAULTS.dup.update params
89
98
  @prompt = Prompt.new
90
- @depth = 0
91
- @binding = @obj.intar_binding
99
+ @depth = 0
100
+ sb = empty_binding.eval SET_BINDING
92
101
  end
93
- @n = 1
102
+ @binding = sb.call @obj
94
103
  end
95
104
 
105
+ public
106
+
107
+ attr_reader :params, :prompt, :depth, :n, :obj
96
108
 
97
109
  class Clear < Exception ; end
98
110
  class Quit < Exception ; end
@@ -103,7 +115,7 @@ class Intar
103
115
  def run
104
116
  handle_history do
105
117
  set_current do
106
- oldset = eval OLDSET, @binding
118
+ execute OLD_INIT
107
119
  loop do
108
120
  l = readline
109
121
  l or break
@@ -135,15 +147,17 @@ class Intar
135
147
  r = $!
136
148
  show_exception
137
149
  end
138
- oldset.call r, @n
150
+ (execute OLD_SET).call r, @n
139
151
  @n += 1
140
152
  end
153
+ ensure
154
+ execute OLD_INIT
141
155
  end
142
156
  end
143
157
  end
144
158
 
145
159
  def execute code
146
- eval code, @binding, "#{self.class}/execute"
160
+ @binding.eval code, @file||"#{self.class}/execute"
147
161
  end
148
162
 
149
163
  def set_var name, val
@@ -154,10 +168,10 @@ class Intar
154
168
  private
155
169
 
156
170
  def eval_line l
157
- ls = l.sub %r/\s+&(\w+)?\s*\z/ do
171
+ ls = l.sub %r/\s+!(\w+)?\s*\z/ do
158
172
  <<~EOT
159
173
  \ do |obj|
160
- Intar.open #{"obj " unless $1}do |i|
174
+ Intar.open #{$1 ? "self" : "obj"} do |i|
161
175
  #{"# " unless $1}i.set_var "#$1", obj
162
176
  i.run
163
177
  end
@@ -166,7 +180,7 @@ class Intar
166
180
  end
167
181
  EOT
168
182
  end
169
- @redir.redirect_output do eval ls, @binding, @file end
183
+ @redir.redirect_output do execute ls end
170
184
  end
171
185
 
172
186
  def handle_history
@@ -183,10 +197,10 @@ class Intar
183
197
  end
184
198
 
185
199
  def set_current
186
- old, @@current = @@current, self
200
+ old, @@prev = @@prev, self
187
201
  yield
188
202
  ensure
189
- @@current = old
203
+ @@prev = old
190
204
  end
191
205
 
192
206
  def find_redirect line
@@ -196,8 +210,11 @@ class Intar
196
210
  end
197
211
 
198
212
 
199
- OLDSET = <<~EOT
213
+ OLD_INIT = <<~EOT
200
214
  _, __, ___ = nil, nil, nil
215
+ EOT
216
+
217
+ OLD_SET = <<~EOT
201
218
  proc { |r,n|
202
219
  Array === __ or __ = []
203
220
  Hash === ___ or ___ = {}
@@ -331,7 +348,7 @@ class Intar
331
348
  def eval_param l
332
349
  eot = "EOT0001"
333
350
  eot.succ! while l[ eot]
334
- l = eval "<<#{eot}\n#{l}\n#{eot}", @binding, @file
351
+ l = execute "<<#{eot}\n#{l}\n#{eot}"
335
352
  l.strip!
336
353
  l.notempty?
337
354
  end
@@ -549,7 +566,7 @@ class Intar
549
566
  x or raise Failed, "No input file given."
550
567
  l = File.read x
551
568
  @redir.redirect_output do
552
- eval l, @binding, x
569
+ @binding.eval l, x
553
570
  end
554
571
  end
555
572
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intar
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.12'
4
+ version: '2.14'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2023-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appl
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: reline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
41
55
  description: 'This is a lean replacement for Irb.
42
56
 
43
57
  '