livetext 0.9.05 → 0.9.10

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: 20018f4ffc0706839f4d17412fd107ed9525b6c0958d29fa3e52dd4be8e6eb36
4
- data.tar.gz: f3805cf9788faf459c3abd3b5145d16d806802e641d432a4d0045180115a8ea1
3
+ metadata.gz: 67d6ad974fae59754a4bf3d6c306e01a9028b8d5f0d86968fa2a3de5fbf97018
4
+ data.tar.gz: d250929b203dbfe8bdec044b31abebfe6f7244e2dd19376b876c0daf2634b730
5
5
  SHA512:
6
- metadata.gz: 559f0f7ef52b6b09d47c20577b2febd3ccfdd125d647deb91b71947b5ce9531fa12156889c2f58ea7cad88666aa332eb91cafd58a071fcd2380e88e2e7482274
7
- data.tar.gz: 5f658b46c63d9fdc5b4786ff9f5b9be9cf2bb85e2c2215348b65f0e717af65fc20e8351dea7168765e9149c3f6c0c5ec5c632e20cd90fac4da9bc6d5974eb319
6
+ metadata.gz: 20dfdad9784ef0bab8439b63d2dccac59f21a27ae57c178c8961bc5414a9dc87af4e78b0d7b5d2b61ca9809715e6fa6e1ee0cf6f8e9091053f724be3d1b7d505
7
+ data.tar.gz: 7a8cc51ccf632a8ec43ee06669f54c39276e5d88fbeb990e4c2d23c33993eb308e83ae3aa5213a054d5e868cb5617eab2632cb480764ece197192d03f0a75618
@@ -72,7 +72,6 @@ loop do
72
72
  @backtrace = true
73
73
  when "-m", "--mixin"
74
74
  mod = ARGV.shift
75
- STDERR.puts "Got mod: #{mod}"
76
75
  x.mixin(ARGV.shift)
77
76
  next
78
77
  when "-s", "--stdin"
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.9.05"
2
+ VERSION = "0.9.10"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -126,6 +126,7 @@ class Livetext
126
126
  when Comment
127
127
  handle_scomment(line)
128
128
  when Dotcmd
129
+ # STDERR.puts "line = #{line.inspect}"
129
130
  handle_dotcmd(line)
130
131
  when Ddotcmd
131
132
  indent = line.index("$") + 1
@@ -169,7 +170,7 @@ class Livetext
169
170
  self.body
170
171
  end
171
172
 
172
- def xform_file(file) # , vars: {})
173
+ def xform_file(file, vars: nil)
173
174
  Livetext::Vars.replace(vars) unless vars.nil?
174
175
  @_vars.replace(vars) unless vars.nil?
175
176
  self.process_file(file)
@@ -184,6 +185,7 @@ class Livetext
184
185
  enum = text.each
185
186
  @backtrace = btrace
186
187
  @main.source(enum, fname, 0)
188
+ line = nil
187
189
  loop do
188
190
  line = @main.nextline
189
191
  break if line.nil?
@@ -192,6 +194,7 @@ class Livetext
192
194
  val = @main.finalize if @main.respond_to? :finalize
193
195
  @body
194
196
  rescue => err
197
+ STDERR.puts "[process_file] fname = #{fname.inspect}\n line = #{line.inspect}"
195
198
  STDERR.puts "ERROR #{err} in process_file"
196
199
  err.backtrace.each {|x| STDERR.puts " " + x }
197
200
  @body = ""
@@ -227,8 +230,10 @@ class Livetext
227
230
  end
228
231
  result
229
232
  rescue => err
233
+ STDERR.puts "Error was: #{err.inspect} (calling @main._error!)"
234
+ STDERR.puts err.backtrace
230
235
  @main._error!(err)
231
- puts @body
236
+ # puts @body
232
237
  @body = ""
233
238
  return @body
234
239
  end
@@ -34,8 +34,11 @@ class Livetext
34
34
 
35
35
  def _error!(err, abort=true, trace=false)
36
36
  where = @sources.last || @save_location
37
- puts @parent.body
38
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
37
+ # puts @parent.body
38
+ puts "[lib/processor] Error: #{err}"
39
+ puts err.backtrace.join("\n") if err.respond_to?(:backtrace)
40
+ STDERR.puts "[lib/processor] Error: #{err}" # (at #{where[1]} line #{where[2]})"
41
+ raise "lib/processor error!"
39
42
  STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
40
43
  exit if abort
41
44
  end
@@ -43,12 +43,42 @@ module Livetext::Standard
43
43
  _error! "Illegal name '#{funcname}'" if _disallowed?(funcname)
44
44
  func_def = <<-EOS
45
45
  def #{funcname}(param)
46
- #{_body_text(true)}
46
+ #{_body.to_a.join("\n")}
47
47
  end
48
48
  EOS
49
+ _optional_blank_line
50
+
49
51
  Livetext::Functions.class_eval func_def
50
52
  end
51
53
 
54
+ def h1; _out "<h1>#{@_data}</h1>"; end
55
+ def h2; _out "<h2>#{@_data}</h2>"; end
56
+ def h3; _out "<h3>#{@_data}</h3>"; end
57
+ def h4; _out "<h4>#{@_data}</h4>"; end
58
+ def h5; _out "<h5>#{@_data}</h5>"; end
59
+ def h6; _out "<h6>#{@_data}</h6>"; end
60
+
61
+ def list
62
+ _out "<ul>"
63
+ _body {|line| _out "<li>#{line}</li>" }
64
+ _out "</ul>"
65
+ end
66
+
67
+ def list!
68
+ _out "<ul>"
69
+ lines = _body.each # {|line| _out "<li>#{line}</li>" }
70
+ loop do
71
+ line = lines.next
72
+ line = _format(line)
73
+ if line[0] == " "
74
+ _out line
75
+ else
76
+ _out "<li>#{line}</li>"
77
+ end
78
+ end
79
+ _out "</ul>"
80
+ end
81
+
52
82
  def shell!
53
83
  cmd = @_data.chomp
54
84
  system(cmd)
@@ -195,6 +225,26 @@ EOS
195
225
  end
196
226
  end
197
227
 
228
+ def variables! # cwd, not FileDir - weird, fix later
229
+ prefix = _args[0]
230
+ file = _args[1]
231
+ prefix = nil if prefix == "-" # FIXME dumb hack
232
+ if file
233
+ here = "" # different for ! version
234
+ lines = File.readlines(here + file)
235
+ else
236
+ lines = _body
237
+ end
238
+ lines.map! {|x| x.sub(/# .*/, "").strip } # strip comments
239
+ lines.each do |line|
240
+ next if line.strip.empty?
241
+ var, val = line.split(" ", 2)
242
+ val = FormatLine.var_func_parse(val)
243
+ var = prefix + "." + var if prefix
244
+ @parent._setvar(var, val)
245
+ end
246
+ end
247
+
198
248
  def variables
199
249
  prefix = _args[0]
200
250
  file = _args[1]
@@ -219,13 +269,21 @@ EOS
219
269
  eval _data.chomp
220
270
  end
221
271
 
272
+ def heredoc! # adds <br>...
273
+ _heredoc(true)
274
+ end
275
+
222
276
  def heredoc
277
+ _heredoc
278
+ end
279
+
280
+ def _heredoc(bang=false)
223
281
  var = @_args[0]
224
282
  str = _body.join("\n")
225
283
  s2 = ""
226
284
  str.each_line do |s|
227
285
  str = FormatLine.var_func_parse(s.chomp)
228
- s2 << str # + "<br>"
286
+ s2 << str + "<br>"
229
287
  end
230
288
  indent = @parent.indentation.last
231
289
  indented = " " * indent
@@ -250,8 +308,10 @@ EOS
250
308
  break if value
251
309
  end
252
310
  end
311
+ STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
253
312
  return value
254
313
  rescue
314
+ STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
255
315
  return nil
256
316
  end
257
317
 
@@ -259,21 +319,25 @@ EOS
259
319
  # like include, but search upward as needed
260
320
  file = @_args.first
261
321
  file = _seek(file)
262
- _error!(file, "No such include file '#{file}'") unless file
322
+ _error!("No such include file #{file.inspect}") unless file
263
323
  @parent.process_file(file)
264
324
  _optional_blank_line
325
+ rescue => err
326
+ STDERR.puts ".seek error - #{err}"
327
+ STDERR.puts err.inspect
328
+ return nil
265
329
  end
266
330
 
267
331
  def in_out # FIXME dumb name!
268
332
  file, dest = *@_args
269
- _check_existence(file, "No such include file '#{file}'")
333
+ _check_existence(file, "No such include file #{file.inspect}")
270
334
  @parent.process_file(file, dest)
271
335
  _optional_blank_line
272
336
  end
273
337
 
274
338
  def _include
275
- file = @_args.first
276
- _check_existence(file, "No such include file '#{file}'")
339
+ file = _format(@_args.first) # allows for variables
340
+ _check_existence(file, "No such include file #{file.inspect}")
277
341
  @parent.process_file(file)
278
342
  _optional_blank_line
279
343
  end
@@ -320,9 +384,10 @@ EOS
320
384
  Dir.chdir("..") { mixin }
321
385
  return
322
386
  else
323
- STDERR.puts "No such mixin '#{name}"
324
- puts @body
325
- exit!
387
+ raise "No such mixin '#{name}'"
388
+ # STDERR.puts "No such mixin '#{name}'"
389
+ # puts @body
390
+ # exit!
326
391
  end
327
392
  end
328
393
 
@@ -94,7 +94,7 @@ module Livetext::UserAPI
94
94
  lines
95
95
  end
96
96
  rescue => err
97
- str << err.inspect + "\n"
97
+ str = err.inspect + "\n"
98
98
  str << err.backtrace.map {|x| " " + x }.join("\n")
99
99
  _error!(str)
100
100
  end
@@ -15,27 +15,6 @@ def h1; _out "<h1>#{@_data}</h1>"; end
15
15
  def h2; _out "<h2>#{@_data}</h2>"; end
16
16
  def h3; _out "<h3>#{@_data}</h3>"; end
17
17
 
18
- def list
19
- _out "<ul>"
20
- _body {|line| _out "<li>#{line}</li>" }
21
- _out "</ul>"
22
- end
23
-
24
- def list!
25
- _out "<ul>"
26
- lines = _body.each # {|line| _out "<li>#{line}</li>" }
27
- loop do
28
- line = lines.next
29
- line = _format(line)
30
- if line[0] == " "
31
- _out line
32
- else
33
- _out "<li>#{line}</li>"
34
- end
35
- end
36
- _out "</ul>"
37
- end
38
-
39
18
  def alpha_columns
40
19
  n = @_args.first.to_i # FIXME: what if missing?
41
20
  words = []
@@ -43,7 +22,7 @@ def alpha_columns
43
22
  words << line.chomp
44
23
  end
45
24
  words.sort!
46
- _out "<table cellpadding=10>"
25
+ _out "<table cellpadding=2>"
47
26
  words.each_slice(n) do |w|
48
27
  items = w.map {|x| "<tt>#{x}</tt>" }
49
28
  _out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
@@ -93,7 +72,7 @@ def chapter
93
72
  next_output
94
73
  _out "<title>#{@chapter}. #{title}</title>"
95
74
  _out <<-HTML
96
- <h2>Chapter #{@chapter}</h1>
75
+ <h2>Chapter #{@chapter}</h2>
97
76
  <h1>#{title}</h1>
98
77
 
99
78
  HTML
@@ -109,7 +88,7 @@ def chapterN
109
88
  next_output
110
89
  _out "<title>#{@chapter}. #{title}</title>"
111
90
  _out <<-HTML
112
- <h2>Chapter #{@chapter}</h1>
91
+ <h2>Chapter #{@chapter}</h2>
113
92
  <h1>#{title}</h1>
114
93
 
115
94
  HTML
@@ -166,7 +145,7 @@ def table2
166
145
  wide = "90"
167
146
  extra = _args[2]
168
147
  delim = " :: "
169
- _out "<br><center><table border=1 width=#{wide}% cellpadding=5>"
148
+ _out "<br><center><table width=#{wide}% cellpadding=5>"
170
149
  lines = _body(true)
171
150
  lines.map! {|line| _format(line) }
172
151
 
@@ -219,7 +198,7 @@ def table
219
198
  @table_num += 1
220
199
  title = @_data
221
200
  delim = " :: "
222
- _out "<br><center><table border=1 width=90% cellpadding=5>"
201
+ _out "<br><center><table width=90% cellpadding=5>"
223
202
  lines = _body(true)
224
203
  maxw = nil
225
204
  lines.each do |line|
@@ -22,5 +22,5 @@ def epub!
22
22
  str = `wc -w /tmp/links.out`
23
23
  nw = str.split[0]
24
24
  puts "Approx words: #{nw}"
25
- ::FileUtils.rm("TEMP.html")
25
+ # ::FileUtils.rm("TEMP.html")
26
26
  end
@@ -4,9 +4,9 @@ a comment
4
4
  .end
5
5
  abc 123
6
6
  xyz
7
- .comment # and this is an extra-useless comment
7
+ .comment
8
8
  And so is this.
9
- .end # comment of dubious nature
9
+ .end
10
10
 
11
11
  one
12
12
  more
@@ -0,0 +1 @@
1
+ Error: Name 'foobar' is unknown
@@ -1 +1 @@
1
- Error: Illegal name 'to_s' (at source.lt3 line 5)
1
+ Error: Illegal name 'to_s'
@@ -0,0 +1 @@
1
+ Error: Mismatched 'end'
@@ -0,0 +1 @@
1
+ Error: #<RuntimeError: Expected .end, found end of file>
@@ -1 +1 @@
1
- Error: Name 'class' is not permitted (at source.lt3 line 4)
1
+ Error: Name 'class' is not permitted
@@ -0,0 +1 @@
1
+ Error: No such file 'nosuchfile.txt' to copy
@@ -0,0 +1 @@
1
+ Error: No such include file 'nosuchinc.lt3'
@@ -0,0 +1 @@
1
+ No such mixin 'nosuchthing'
@@ -1,6 +0,0 @@
1
- Test that
2
- we give an error
3
- when a mixin does not
4
- exist:
5
- <p>
6
-
@@ -3,7 +3,7 @@ some functions
3
3
  here...
4
4
 
5
5
  .func myfunc
6
- "Eureka!"
6
+ "Eureka!"
7
7
  .end
8
8
 
9
9
  I am calling $$myfunc here...
@@ -18,7 +18,7 @@ class TestingLivetext < MiniTest::Test
18
18
 
19
19
  TestLines = []
20
20
 
21
- Dir.chdir `livetext --path`.chomp if ARGV.first == "cmdline"
21
+ Dir.chdir `livetext --path`.chomp.chomp if ARGV.first == "cmdline"
22
22
 
23
23
  Dir.chdir(Data)
24
24
 
@@ -31,7 +31,7 @@ class TestingLivetext < MiniTest::Test
31
31
  break if f.eof?
32
32
  end
33
33
 
34
- if File.size("subset.txt") # == 0
34
+ if File.size("subset.txt") == 0
35
35
  puts "Defining via TestLines"
36
36
  TestLines.each.with_index do |item, i|
37
37
  msg, src, exp, blank = *item
@@ -51,8 +51,6 @@ class TestingLivetext < MiniTest::Test
51
51
  selected = File.readlines("subset.txt").map(&:chomp)
52
52
  Subset = selected.empty? ? TestDirs : selected
53
53
 
54
- # puts "Subset = #{Subset.inspect}"
55
-
56
54
  Subset.each do |tdir|
57
55
  define_method("test_#{tdir}") do
58
56
  external_files(tdir)
@@ -60,11 +58,11 @@ class TestingLivetext < MiniTest::Test
60
58
  end
61
59
 
62
60
  def green(str)
63
- "" + str + ""
61
+ "" + str.to_s + ""
64
62
  end
65
63
 
66
64
  def red(str)
67
- "" + str + ""
65
+ "" + str.to_s + ""
68
66
  end
69
67
 
70
68
  def external_files(base)
@@ -85,14 +83,14 @@ class TestingLivetext < MiniTest::Test
85
83
 
86
84
  if File.exist?(expout_regex)
87
85
  rx_out = /#{Regexp.escape(File.read(expout_regex).chomp)}/
88
- expected = "(match test)"
86
+ expected = rx_out # "(match test)"
89
87
  else
90
88
  expected = File.read(exp)
91
89
  end
92
90
 
93
91
  if File.exist?(experr_regex)
94
92
  rx_err = /#{Regexp.escape(File.read(experr_regex).chomp)}/
95
- errexp = "(match test)"
93
+ errexp = rx_err # "(match test)"
96
94
  else
97
95
  errexp = File.read(erx)
98
96
  end
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.05
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -53,34 +53,32 @@ files:
53
53
  - test/data/def_method/expected-error.txt
54
54
  - test/data/def_method/expected-output.txt
55
55
  - test/data/def_method/source.lt3
56
- - test/data/error_inc_line_num/expected-error.txt
56
+ - test/data/error_inc_line_num/expected-err-line1match.txt
57
57
  - test/data/error_inc_line_num/expected-output.txt
58
58
  - test/data/error_inc_line_num/file2.lt3
59
59
  - test/data/error_inc_line_num/source.lt3
60
60
  - test/data/error_invalid_name/expected-err-line1match.txt
61
- - test/data/error_invalid_name/expected-error.txt
62
61
  - test/data/error_invalid_name/expected-output.txt
63
62
  - test/data/error_invalid_name/source.lt3
64
63
  - test/data/error_line_num/expected-err-line1match.txt
65
- - test/data/error_line_num/expected-error.txt
66
64
  - test/data/error_line_num/expected-output.txt
67
65
  - test/data/error_line_num/source.lt3
68
- - test/data/error_mismatched_end/expected-error.txt
66
+ - test/data/error_mismatched_end/expected-err-line1match.txt
69
67
  - test/data/error_mismatched_end/expected-output.txt
70
68
  - test/data/error_mismatched_end/source.lt3
71
- - test/data/error_missing_end/expected-error.txt
69
+ - test/data/error_missing_end/expected-err-line1match.txt
72
70
  - test/data/error_missing_end/expected-output.txt
73
71
  - test/data/error_missing_end/source.lt3
74
72
  - test/data/error_name_not_permitted/expected-error.txt
75
73
  - test/data/error_name_not_permitted/expected-output.txt
76
74
  - test/data/error_name_not_permitted/source.lt3
77
- - test/data/error_no_such_copy/expected-error.txt
75
+ - test/data/error_no_such_copy/expected-err-line1match.txt
78
76
  - test/data/error_no_such_copy/expected-output.txt
79
77
  - test/data/error_no_such_copy/source.lt3
80
- - test/data/error_no_such_inc/expected-error.txt
78
+ - test/data/error_no_such_inc/expected-err-line1match.txt
81
79
  - test/data/error_no_such_inc/expected-output.txt
82
80
  - test/data/error_no_such_inc/source.lt3
83
- - test/data/error_no_such_mixin/expected-error.txt
81
+ - test/data/error_no_such_mixin/expected-err-line1match.txt
84
82
  - test/data/error_no_such_mixin/expected-output.txt
85
83
  - test/data/error_no_such_mixin/source.lt3
86
84
  - test/data/example_alpha/expected-error.txt
@@ -139,7 +137,7 @@ homepage: https://github.com/Hal9000/livetext
139
137
  licenses:
140
138
  - Ruby
141
139
  metadata: {}
142
- post_install_message:
140
+ post_install_message:
143
141
  rdoc_options: []
144
142
  require_paths:
145
143
  - lib
@@ -154,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
152
  - !ruby/object:Gem::Version
155
153
  version: '0'
156
154
  requirements: []
157
- rubygems_version: 3.0.4
158
- signing_key:
155
+ rubygems_version: 3.0.8
156
+ signing_key:
159
157
  specification_version: 4
160
158
  summary: A smart processor for text
161
159
  test_files: []
@@ -1 +0,0 @@
1
- Error: Name 'foobar' is unknown (at file2.lt3 line 5)
@@ -1 +0,0 @@
1
- Error: Illegal name 'to_s' (at source.lt3 line 5)
@@ -1 +0,0 @@
1
- Error: Name 'foobar' is unknown (at source.lt3 line 4)
@@ -1 +0,0 @@
1
- Error: Mismatched 'end' (at source.lt3 line 6)
@@ -1 +0,0 @@
1
- Error: Expecting .end, found end of file (at source.lt3 line 6)
@@ -1 +0,0 @@
1
- Error: No such file 'nosuchfile.txt' to copy (at source.lt3 line 5)
@@ -1 +0,0 @@
1
- Error: No such include file 'nosuchinc.lt3' (at source.lt3 line 5)
@@ -1 +0,0 @@
1
- Error: No such mixin 'nosuchthing' (at source.lt3 line 6)