livetext 0.9.44 → 0.9.46

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: 77c132b3f86809adfbbed149564227c061911a51bc57124fdd17ed9fb67bae55
4
- data.tar.gz: dc92358a343e8096f7e982005585fa9633d8860f6fe569e0db61bc40a764bd73
3
+ metadata.gz: 05c23cb9790ecbd684af4888ff8237bcf0aa792462bb1da1d183d18b786ab462
4
+ data.tar.gz: c0adc17493388b920557b09029213ab558fa43df3c6a7c23dce75d54c38fc298
5
5
  SHA512:
6
- metadata.gz: e8ec2c7c373c5587c1a492c0cd183bb6143c16a59ed49084fcc11294ed48e05c3e076ad48f03de56a5b60f2bad828629f54c086e51b8785e4eb6b39b6366bb7f
7
- data.tar.gz: e129c8269d51269f635b4a4995abe568cdbd0b1aa61060986ffa34528157d79ae4a455a88d309010085928d8897204fadff094f79a94bb0d89aa9a83edd4903d
6
+ metadata.gz: a8717d55d1775c6947b79f008d6a01a64b5e3c084e936b79f7faa243b7776233734fb3e56518ac249faf95bf5b86cbfcde006b50e449762b6bb96788b8c84ec0
7
+ data.tar.gz: d552b53c1b82e5b650d65a9e49e45bdf80447ecc0a4af0a290e9d6415979ef71dd3c4da35ca6b1cacff42c062c4e7896613ce05175b0040147e00a349c8ecb3d
data/bin/livetext CHANGED
@@ -115,7 +115,7 @@ def parse_command_line
115
115
  STDERR.puts "Command line - #{arg.inspect} is unknown"
116
116
  end
117
117
  end
118
- @live.dump if success
118
+ @live.api.dump if success
119
119
  rescue => err
120
120
  STDERR.puts "Unexpected error! #{err.inspect}\n#{err.backtrace.join("\n")}"
121
121
  end
@@ -1,3 +1,51 @@
1
+ private def whence(back = 0)
2
+ file, line, inmeth = caller[back].split(":")
3
+ meth = inmeth[4..-2]
4
+ [file, line, meth]
5
+ end
6
+
7
+ private def display(file, line, meth, msg)
8
+ puts "--- #{meth} #{line} in #{file}"
9
+ puts "::: " + msg if msg
10
+ end
11
+
12
+ def checkpoint(msg = nil)
13
+ file, line, meth = whence(1)
14
+ display(file, line, meth, msg)
15
+ end
16
+
17
+ def checkpoint?(msg = nil) # with sleep 3
18
+ file, line, meth = whence(1)
19
+ display(file, line, meth, msg)
20
+ end
21
+
22
+ def checkpoint!(msg = nil) # with pause
23
+ file, line, meth = whence(1)
24
+ display(file, line, meth, msg)
25
+ print "::: Pause..."
26
+ gets
27
+ end
28
+
29
+ def warning(err)
30
+ file, line, meth = whence(2) # 2 = skip rescue
31
+ puts "Error in #{meth} in #{file} (non-fatal?)"
32
+ puts " err = #{err.inspect}"
33
+ puts " #{err.backtrace[0]}" if err.respond_to?(:backtrace)
34
+ puts
35
+ end
36
+
37
+ def fatal(err)
38
+ file, line, meth = whence(2) # 2 = skip rescue
39
+ puts "Error in #{meth} in #{file}"
40
+ puts "WTF??"
41
+ puts " err = #{err.inspect}"
42
+ if err.respond_to?(:backtrace)
43
+ context = err.backtrace.map {|x| " " + x + "\n" }
44
+ puts context
45
+ end
46
+ abort "Terminated."
47
+ end
48
+
1
49
 
2
50
  # More later?
3
51
 
@@ -16,3 +64,13 @@ end
16
64
  make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
17
65
  make_exception(:UnknownMethod, "Error: name '%1' is unknown")
18
66
  make_exception(:NoSuchFile, "Error: can't find file '%1' (method '%2')")
67
+
68
+ # Move others here? DisallowedName, etc.
69
+
70
+ make_exception(:ExpectedDotEnd, "Error: expected .end but found end of file")
71
+ make_exception(:ExpectedAlphaNum, "Error: expected an alphanumeric but foun '%1'") # parser/set.rb
72
+ make_exception(:ExpectedCommaEOS, "Error: expected comma or end of string") # parser/set.rb
73
+
74
+
75
+
76
+
@@ -2,7 +2,6 @@
2
2
  module GlobalHelpers
3
3
 
4
4
  def check_disallowed(name)
5
- api.tty "GLOBAL cdis"
6
5
  raise DisallowedName(name) if disallowed?(name)
7
6
  end
8
7
 
@@ -17,8 +17,8 @@ module Livetext::Helpers
17
17
  return graceful_error(err) if self.respond_to?(:graceful_error)
18
18
  return self.parent.graceful_error(err) if self.respond_to?(:parent)
19
19
  raise err
20
- rescue => myerr
21
- TTY.puts "--- Warning: friendly_error #{myerr.inspect}"
20
+ # rescue => myerr
21
+ # TTY.puts "--- Warning: friendly_error #{myerr.inspect}"
22
22
  end
23
23
 
24
24
  def escape_html(string)
@@ -75,7 +75,10 @@ module Livetext::Helpers
75
75
  ## FIXME process_file[!] should call process[_text] ?
76
76
 
77
77
  def process_file(fname, btrace=false)
78
- graceful_error FileNotFound(fname) unless File.exist?(fname)
78
+ unless File.exist?(fname)
79
+ api.dump
80
+ raise FileNotFound(fname)
81
+ end
79
82
  setfile(fname)
80
83
  text = File.readlines(fname)
81
84
  enum = text.each
@@ -107,7 +110,7 @@ module Livetext::Helpers
107
110
  end
108
111
  success
109
112
  rescue => err
110
- STDERR.puts "ERROR: #{err}\n#{err.backtrace.join("\n")}"
113
+ STDERR.puts "ERROR: #{err.inspect}\n#{err.backtrace.join("\n")}"
111
114
  exit
112
115
  end
113
116
 
@@ -186,8 +189,9 @@ module Livetext::Helpers
186
189
  def grab_file(fname)
187
190
  File.read(fname)
188
191
  rescue
189
- ::STDERR.puts "Can't find #{fname.inspect} \n "
190
- return nil
192
+ graceful_error NoSuchFile(fname)
193
+ # ::STDERR.puts "Can't find #{fname.inspect} \n "
194
+ # return nil
191
195
  end
192
196
 
193
197
  def search_upward(file)
@@ -212,8 +216,9 @@ module Livetext::Helpers
212
216
  end
213
217
 
214
218
  def include_file(file)
219
+ api.data = file
215
220
  api.args = [file]
216
- dot_include
221
+ api.dot_include
217
222
  end
218
223
 
219
224
  def onoff(arg) # helper
@@ -253,5 +258,18 @@ module Livetext::Helpers
253
258
  api.setvar(:File, file)
254
259
  end
255
260
 
261
+ # def dump(file = nil) # not a dot command!
262
+ # file ||= ::STDOUT
263
+ # TTY.puts "--- Writing body (#{@body.size} bytes)" if @body
264
+ # file.puts @body
265
+ # rescue => err
266
+ # TTY.puts "#dump had an error: #{err.inspect}"
267
+ # end
268
+
269
+ def graceful_error(err, msg = nil)
270
+ api.dump
271
+ STDERR.puts msg if msg
272
+ raise err
273
+ end
256
274
  end
257
275
 
data/lib/livetext/more.rb CHANGED
@@ -10,7 +10,21 @@ class Livetext
10
10
 
11
11
  def initialize(hash = {})
12
12
  @vars = {}
13
- hash.each_pair {|k, v| @vars[k.to_sym] = v }
13
+ hash.each_pair do |k, v|
14
+ sym = k.to_sym
15
+ str = k.to_s
16
+ @vars[sym] = v
17
+ @vars[str] = v
18
+ end
19
+ end
20
+
21
+ def inspect
22
+ syms = @vars.keys.select {|x| x.is_a? Symbol }
23
+ out = "\nVariables:"
24
+ syms.each do |sym|
25
+ out << " #{sym}: #{@vars[sym].inspect}\n"
26
+ end
27
+ out
14
28
  end
15
29
 
16
30
  def [](var)
@@ -84,17 +98,20 @@ class Livetext
84
98
  @save_location = where # delegate
85
99
  end
86
100
 
87
- def dump(file = nil) # not a dot command!
88
- file ||= ::STDOUT
89
- file.puts @body
90
- rescue => err
91
- TTY.puts "#dump had an error: #{err.inspect}"
92
- end
93
-
94
- def graceful_error(err, msg = nil)
95
- dump
96
- STDERR.puts msg if msg
97
- raise err
101
+ def initialize(output = ::STDOUT)
102
+ @source = nil
103
+ @_mixins = []
104
+ @_imports = []
105
+ @_outdir = "."
106
+ @no_puts = output.nil?
107
+ @body = ""
108
+ @main = Processor.new(self, output) # nil = make @main its own parent??
109
+ @indentation = [0]
110
+ @_vars = Livetext::Vars
111
+ @api = UserAPI.new(self)
112
+ initial_vars
113
+ # puts "------ init: self = "
114
+ # p self
98
115
  end
99
116
 
100
117
  def self.customize(mix: [], call: [], vars: {})
@@ -106,6 +123,8 @@ class Livetext
106
123
  end
107
124
  call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
108
125
  obj.api.setvars(vars)
126
+ # puts "------ init: obj = "
127
+ # p obj
109
128
  obj
110
129
  end
111
130
 
@@ -119,18 +138,16 @@ class Livetext
119
138
  self
120
139
  end
121
140
 
122
- def initialize(output = ::STDOUT)
123
- @source = nil
124
- @_mixins = []
125
- @_imports = []
126
- @_outdir = "."
127
- @no_puts = output.nil?
128
- @body = ""
129
- @main = Processor.new(self, output)
130
- @indentation = [0]
131
- @_vars = Livetext::Vars
132
- @api = UserAPI.new(self)
133
- initial_vars
141
+ def inspect
142
+ "Livetext:\n" +
143
+ " source = #{@source.inspect}\n" +
144
+ " mixins = #{@_mixins.inspect}\n" +
145
+ " import = #{@_mixins.inspect}\n" +
146
+ " main = (not shown)\n" +
147
+ " indent = #{@indentation.inspect}\n" +
148
+ " vars = #{@_vars.inspect}\n" +
149
+ " api = (not shown)\n" +
150
+ " body = (#{@body.size} bytes)"
134
151
  end
135
152
 
136
153
  def api
@@ -181,7 +198,9 @@ class Livetext
181
198
  def xform_file(file, vars: nil)
182
199
  Livetext::Vars.replace(vars) unless vars.nil?
183
200
  @_vars.replace(vars) unless vars.nil?
201
+ # checkpoint! "Calling process_file..."
184
202
  self.process_file(file)
203
+ # checkpoint! "...returned"
185
204
  self.body
186
205
  end
187
206
 
@@ -3,8 +3,6 @@
3
3
 
4
4
  class Processor
5
5
 
6
- GenericError = Class.new(StandardError)
7
-
8
6
  include Livetext::Standard
9
7
 
10
8
  Disallowed =
@@ -26,7 +24,7 @@ class Processor
26
24
  attr_reader :parent, :sources
27
25
 
28
26
  def initialize(parent, output = nil)
29
- @parent = parent
27
+ @parent = parent || self
30
28
  # STDERR.puts "PARENT.api = #{parent.api.inspect}"
31
29
  @parent.api ||= Livetext::UserAPI.new(@parent)
32
30
  @nopass = false
@@ -56,16 +54,8 @@ class Processor
56
54
  ::STDERR.puts *args
57
55
  end
58
56
 
59
- def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
60
- where = @sources.last || @live.save_location
61
- error "Error: #{err} (at #{where[1]} line #{where[2]})"
62
- error(err.backtrace) rescue nil
63
- raise GenericError.new("Error: #{err}") if raise_error
64
- end
65
-
66
57
  def disallowed?(name)
67
58
  flag = Disallowed.include?(name.to_sym)
68
- # api.tty "disa name = #{name.inspect} flag = #{flag}"
69
59
  flag
70
60
  end
71
61
 
@@ -95,4 +85,6 @@ class Processor
95
85
  @sources.pop
96
86
  nil
97
87
  end
88
+
89
+
98
90
  end
@@ -179,39 +179,6 @@ module Livetext::Standard
179
179
  api.optional_blank_line
180
180
  end
181
181
 
182
- =begin
183
- Filename: foobar
184
- get_globals - 1 - transforming /private/tmp/.blogs/views/foobar/data/global.lt3
185
-
186
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
187
- fname = ../settings/view.txt
188
- path = /private/tmp/.blogs/views/foobar/data/../settings/view.txt
189
-
190
- rpath = /private/tmp/.blogs/views/foobar/settings/view.txt
191
- path = /private/tmp/.blogs/views/foobar/settings/view.txt
192
- dir = /private/tmp/.blogs/views/foobar/settings
193
- base = view.txt
194
-
195
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
196
- fname = ../settings/recent.txt
197
- path = /private/tmp/.blogs/views/foobar/data/../settings/recent.txt
198
- rpath = /private/tmp/.blogs/views/foobar/settings/recent.txt
199
- path = /private/tmp/.blogs/views/foobar/settings/recent.txt
200
- dir = /private/tmp/.blogs/views/foobar/settings
201
- base = recent.txt
202
-
203
- >> variables: fdir = /private/tmp/.blogs/views/foobar/data/
204
- fname = ../settings/publish.txt
205
- path = /private/tmp/.blogs/views/foobar/data/../settings/publish.txt
206
- rpath = /private/tmp/.blogs/views/foobar/settings/publish.txt
207
- path = /private/tmp/.blogs/views/foobar/settings/publish.txt
208
- dir = /private/tmp/.blogs/views/foobar/settings
209
- base = publish.txt
210
-
211
- get_globals - 2
212
-
213
- =end
214
-
215
182
  def variables(args = nil, body = nil)
216
183
  prefix = api.args[0]
217
184
  fname = api.args[1]
@@ -221,7 +188,7 @@ get_globals - 2
221
188
  path0 = fdir + fname
222
189
  # puts ">> variables: fdir = #{fdir} fname = #{fname} path = #{path0}"
223
190
  pname = Pathname.new(path0)
224
- rpath = pname.realpath(pname)
191
+ rpath = pname.realpath
225
192
  path, dir, base = rpath.to_s, rpath.dirname.to_s, rpath.basename.to_s
226
193
  # puts " rpath = #{rpath} path = #{path} dir = #{dir} base = #{base}"
227
194
  dok, fok = Dir.exist?(dir), File.exist?(path)
@@ -235,13 +202,7 @@ get_globals - 2
235
202
  api.setvars(pairs)
236
203
  api.optional_blank_line
237
204
  rescue => err
238
- puts "Error in #{__method__} in #{__FILE__}
239
- puts " #{err.inspect}"
240
- if err.respond_to?(:backtrace)
241
- context = err.backtrace.map {|x| " " + x}.join("\n")
242
- puts context
243
- end
244
- abort "\nTerminated."
205
+ fatal(err)
245
206
  end
246
207
 
247
208
  def heredoc(args = nil, body = nil)
@@ -297,6 +258,7 @@ get_globals - 2
297
258
  def dot_include(args = nil, body = nil) # dot command
298
259
  file = api.expand_variables(api.args.first) # allows for variables
299
260
  check_file_exists(file)
261
+ # checkpoint "====== self.methods = #{self.methods.sort.inspect}"
300
262
  @parent.process_file(file)
301
263
  api.optional_blank_line
302
264
  end
@@ -25,6 +25,14 @@ class Livetext::UserAPI
25
25
  @live.api
26
26
  end
27
27
 
28
+ def dump(file = nil) # not a dot command!
29
+ file ||= ::STDOUT
30
+ # TTY.puts "--- Writing body (#{@live.body.size} bytes)"
31
+ file.puts @live.body
32
+ rescue => err
33
+ TTY.puts "#dump had an error: #{err.inspect}"
34
+ end
35
+
28
36
  def html
29
37
  @html
30
38
  end
@@ -34,9 +42,9 @@ class Livetext::UserAPI
34
42
  end
35
43
 
36
44
  def include_file(file)
45
+ # checkpoint "DATA = #{file.inspect}"
37
46
  api.data = file
38
47
  api.args = [file]
39
- STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
40
48
  api.dot_include
41
49
  end
42
50
 
@@ -191,11 +199,13 @@ STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
191
199
  end
192
200
 
193
201
  def puts(*args)
194
- @live.output.puts *args
202
+ # @live.output.puts *args
203
+ @live.api.out *args
195
204
  end
196
205
 
197
206
  def print(*args)
198
- @live.output.print *args
207
+ # @live.output.print *args
208
+ @live.api.out! *args
199
209
  end
200
210
 
201
211
  def debug=(val)
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.44"
5
+ VERSION = "0.9.46"
6
6
  end
data/lib/livetext.rb CHANGED
@@ -12,7 +12,8 @@ require_relative 'livetext/userapi'
12
12
  require_relative 'livetext/formatter'
13
13
  require_relative 'livetext/processor'
14
14
  require_relative 'livetext/helpers'
15
+ require_relative 'livetext/more'
16
+
15
17
  require_relative 'livetext/handler'
16
18
 
17
- require_relative 'livetext/more'
18
19
 
data/test/snapshots.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'simplecov' # These two lines must go first
2
- SimpleCov.use_merging(true)
3
- SimpleCov.start do
4
- puts "SimpleCov: Snapshots"
5
- add_filter "/test/"
6
- enable_coverage :branch
7
- primary_coverage :branch
8
- end
1
+ # require 'simplecov' # These two lines must go first
2
+ # SimpleCov.use_merging(true)
3
+ # SimpleCov.start do
4
+ # puts "SimpleCov: Snapshots"
5
+ # add_filter "/test/"
6
+ # enable_coverage :branch
7
+ # primary_coverage :branch
8
+ # end
9
9
 
10
10
  require 'minitest/autorun'
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.44
4
+ version: 0.9.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-19 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com