livetext 0.9.46 → 0.9.47

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: 05c23cb9790ecbd684af4888ff8237bcf0aa792462bb1da1d183d18b786ab462
4
- data.tar.gz: c0adc17493388b920557b09029213ab558fa43df3c6a7c23dce75d54c38fc298
3
+ metadata.gz: c1f67c2785b935c3c940db118d04f6613e186df48b4473659e14c69089e23a35
4
+ data.tar.gz: 6b08485471ca1c9aa2d44a83d9e5670f876999e70f3c20e975caa8fb3aadc2ac
5
5
  SHA512:
6
- metadata.gz: a8717d55d1775c6947b79f008d6a01a64b5e3c084e936b79f7faa243b7776233734fb3e56518ac249faf95bf5b86cbfcde006b50e449762b6bb96788b8c84ec0
7
- data.tar.gz: d552b53c1b82e5b650d65a9e49e45bdf80447ecc0a4af0a290e9d6415979ef71dd3c4da35ca6b1cacff42c062c4e7896613ce05175b0040147e00a349c8ecb3d
6
+ metadata.gz: 1becbb55d5267f754ee0c3dacc3c894fc6814aefd71386aaf0bc3f77f4dbefe76554d42ca78ade718e027b96874616219582dfcb0a4295eae10aac12bff11481
7
+ data.tar.gz: f169d21ca5e99b17869e10836fe4b4ae39cc5a239408562d95a3928e89b954f42184b2b51c8603e9d7570f3578acd81761417c56be7217942c7f4a8624089e8c
@@ -10,16 +10,19 @@
10
10
  end
11
11
 
12
12
  def checkpoint(msg = nil)
13
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
13
14
  file, line, meth = whence(1)
14
15
  display(file, line, meth, msg)
15
16
  end
16
17
 
17
18
  def checkpoint?(msg = nil) # with sleep 3
19
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
18
20
  file, line, meth = whence(1)
19
21
  display(file, line, meth, msg)
20
22
  end
21
23
 
22
24
  def checkpoint!(msg = nil) # with pause
25
+ return unless ENV['LIVETEXT_DEBUG'] == "true"
23
26
  file, line, meth = whence(1)
24
27
  display(file, line, meth, msg)
25
28
  print "::: Pause..."
@@ -71,6 +74,3 @@ make_exception(:ExpectedDotEnd, "Error: expected .end but found end of file")
71
74
  make_exception(:ExpectedAlphaNum, "Error: expected an alphanumeric but foun '%1'") # parser/set.rb
72
75
  make_exception(:ExpectedCommaEOS, "Error: expected comma or end of string") # parser/set.rb
73
76
 
74
-
75
-
76
-
@@ -8,7 +8,7 @@ class Livetext::Expansion
8
8
  Lbrack = "\\["
9
9
  Colon = ":"
10
10
 
11
- def initialize(instance)
11
+ def initialize(instance) # Livetext::Expansion
12
12
  @live = instance
13
13
  end
14
14
 
@@ -1,14 +1,6 @@
1
1
  module Formatter
2
2
 
3
- ## Hmmm...
4
- #
5
- # Double: b, i, t, s
6
- # Single: bits
7
- # Brackt: bits
8
- #
9
-
10
-
11
- def self.format(str)
3
+ def self.format(str) # FIXME - unneeded?
12
4
  str = str.chomp
13
5
  s2 = Double.process(str.chomp)
14
6
  s3 = Bracketed.process(s2)
@@ -16,8 +8,15 @@ module Formatter
16
8
  s4
17
9
  end
18
10
 
11
+ ## Hmmm...
12
+ #
13
+ # Double: b, i, t, s
14
+ # Single: bits
15
+ # Brackt: bits
16
+ #
17
+
19
18
  class Delimited
20
- def initialize(str, marker, tag)
19
+ def initialize(str, marker, tag) # Delimited
21
20
  @str, @marker, @tag = str.dup, marker, tag
22
21
  @buffer = ""
23
22
  @cdata = ""
@@ -170,7 +169,7 @@ module Formatter
170
169
  end
171
170
 
172
171
  class Double < Delimited
173
- def initialize(str, sigil, tag)
172
+ def initialize(str, sigil, tag) # Double
174
173
  super
175
174
  # Convention: marker is "**", sigil is "*"
176
175
  @marker = sigil + sigil
@@ -183,7 +182,7 @@ module Formatter
183
182
  end
184
183
 
185
184
  class Bracketed < Delimited
186
- def initialize(str, sigil, tag)
185
+ def initialize(str, sigil, tag) # Bracketed
187
186
  super
188
187
  # Convention: marker is "*[", sigil is "*"
189
188
  @marker = sigil + "["
@@ -19,7 +19,7 @@ class Livetext::Functions
19
19
  "\b"
20
20
  end
21
21
 
22
- # FIXME Function parameters need to be fixed...
22
+ # FIXME Function parameters need to be fixed...
23
23
 
24
24
  def isqrt(param = nil) # "integer square root" - Just for testing
25
25
  arg = num = param # Takes any number
@@ -9,7 +9,7 @@ class Livetext::Handler::Import
9
9
 
10
10
  attr_reader :file
11
11
 
12
- def initialize(name)
12
+ def initialize(name) # Livetext::Handler::Import
13
13
  @name = name
14
14
  @file = find_file(name)
15
15
  end
@@ -9,7 +9,7 @@ class Livetext::Handler::Mixin
9
9
 
10
10
  attr_reader :file
11
11
 
12
- def initialize(name, parent)
12
+ def initialize(name, parent) # Livetext::Handler::Mixin
13
13
  @name = name
14
14
  @file = find_file(name, ".rb", "plugin")
15
15
  parent.graceful_error FileNotFound(name) if @file.nil?
@@ -2,9 +2,7 @@
2
2
  require_relative 'global_helpers'
3
3
  require_relative 'expansion'
4
4
 
5
-
6
5
  module Livetext::Helpers
7
-
8
6
  Space = " "
9
7
  Sigil = "." # Can't change yet
10
8
 
@@ -75,6 +73,7 @@ module Livetext::Helpers
75
73
  ## FIXME process_file[!] should call process[_text] ?
76
74
 
77
75
  def process_file(fname, btrace=false)
76
+ checkpoint "fname = #{fname.inspect}"
78
77
  unless File.exist?(fname)
79
78
  api.dump
80
79
  raise FileNotFound(fname)
@@ -127,6 +126,7 @@ module Livetext::Helpers
127
126
  api.data = data0.dup # should permit _ in function names at least
128
127
  args0 = data0.split
129
128
  api.args = args0.dup
129
+ checkpoint "name = #{name} args = #{args0.inspect}"
130
130
  retval = @main.send(name) # , *args) # was 125
131
131
  retval
132
132
  rescue => err
@@ -258,14 +258,6 @@ module Livetext::Helpers
258
258
  api.setvar(:File, file)
259
259
  end
260
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
261
  def graceful_error(err, msg = nil)
270
262
  api.dump
271
263
  STDERR.puts msg if msg
data/lib/livetext/html.rb CHANGED
@@ -1,39 +1,6 @@
1
+ class HTML # FIXME - better as Livetext::HTML ?
1
2
 
2
- # module HTMLHelper
3
- #
4
- # def wrapped(str, *tags) # helper
5
- # open, close = open_close_tags(*tags)
6
- # open + str + close
7
- # end
8
- #
9
- # def wrapped!(str, tag, **extras) # helper
10
- # open, close = open_close_tags(tag)
11
- # extras.each_pair do |name, value|
12
- # open.sub!(">", " #{name}='#{value}'>")
13
- # end
14
- # open + str + close
15
- # end
16
- #
17
- # def wrap(*tags) # helper
18
- # open, close = open_close_tags(*tags)
19
- # api.out open
20
- # yield
21
- # api.out close
22
- # end
23
- #
24
- # def open_close_tags(*tags)
25
- # open, close = "", ""
26
- # tags.each do |tag|
27
- # open << "<#{tag}>"
28
- # close.prepend("</#{tag}>")
29
- # end
30
- # [open, close]
31
- # end
32
- # end
33
-
34
- class HTML
35
-
36
- def initialize(api)
3
+ def initialize(api) # HTML
37
4
  raise "API is nil!" unless api
38
5
  @api = api
39
6
  @indent = 0
data/lib/livetext/more.rb CHANGED
@@ -5,10 +5,10 @@ class Livetext
5
5
 
6
6
  include Helpers
7
7
 
8
- class Variables
8
+ class Variables # FIXME - split out into file as Livetext::Variables
9
9
  attr_reader :vars
10
10
 
11
- def initialize(hash = {})
11
+ def initialize(hash = {}) # Livetext::Variables
12
12
  @vars = {}
13
13
  hash.each_pair do |k, v|
14
14
  sym = k.to_sym
@@ -98,7 +98,7 @@ class Livetext
98
98
  @save_location = where # delegate
99
99
  end
100
100
 
101
- def initialize(output = ::STDOUT)
101
+ def initialize(output = ::STDOUT) # Livetext
102
102
  @source = nil
103
103
  @_mixins = []
104
104
  @_imports = []
@@ -123,8 +123,6 @@ class Livetext
123
123
  end
124
124
  call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
125
125
  obj.api.setvars(vars)
126
- # puts "------ init: obj = "
127
- # p obj
128
126
  obj
129
127
  end
130
128
 
@@ -6,7 +6,7 @@ make_exception(:ExpectedString, "Error: expected a string")
6
6
 
7
7
  class Livetext::ParseGeneral < StringParser
8
8
 
9
- def initialize(str)
9
+ def initialize(str) # Livetext::ParseGeneral
10
10
  super
11
11
  end
12
12
 
@@ -10,7 +10,7 @@ class Livetext::ParseSet < StringParser
10
10
  self.new(str).parse
11
11
  end
12
12
 
13
- def initialize(line)
13
+ def initialize(line) # Livetext::ParseSet
14
14
  super
15
15
  end
16
16
 
@@ -2,7 +2,7 @@ class StringParser
2
2
 
3
3
  attr_reader :line, :eos, :i, :len
4
4
 
5
- def initialize(line)
5
+ def initialize(line) # StringParser
6
6
  raise NilValue if line.nil?
7
7
  raise ExpectedString unless String === line
8
8
  @line = line
@@ -1,4 +1,4 @@
1
- # Reopening for paths... do differently?
1
+ # Reopening for paths... do differently? FIXME
2
2
 
3
3
  class Livetext
4
4
  def self.get_path(dir = "")
@@ -23,7 +23,7 @@ class Processor
23
23
 
24
24
  attr_reader :parent, :sources
25
25
 
26
- def initialize(parent, output = nil)
26
+ def initialize(parent, output = nil) # Processor
27
27
  @parent = parent || self
28
28
  # STDERR.puts "PARENT.api = #{parent.api.inspect}"
29
29
  @parent.api ||= Livetext::UserAPI.new(@parent)
@@ -85,6 +85,4 @@ class Processor
85
85
  @sources.pop
86
86
  nil
87
87
  end
88
-
89
-
90
88
  end
@@ -1,4 +1,3 @@
1
-
2
1
  require 'pathname' # For _seek - remove later??
3
2
 
4
3
  require_relative 'parser' # nested requires
@@ -9,7 +8,6 @@ make_exception(:ExpectedOnOff, "Error: expected 'on' or 'off'")
9
8
  make_exception(:DisallowedName, "Error: name '%1' is invalid")
10
9
  make_exception(:FileNotFound, "Error: file '%1' not found")
11
10
 
12
-
13
11
  # Module Standard comprises most of the standard or "common" methods.
14
12
 
15
13
  module Livetext::Standard
@@ -74,6 +72,8 @@ module Livetext::Standard
74
72
  return true
75
73
  end
76
74
 
75
+ # FIXME - move these to a single universal place in code
76
+
77
77
  def h1(args = nil, body = nil); api.out html.tag(:h1, cdata: api.data); return true; end
78
78
  def h2(args = nil, body = nil); api.out html.tag(:h2, cdata: api.data); return true; end
79
79
  def h3(args = nil, body = nil); api.out html.tag(:h3, cdata: api.data); return true; end
@@ -258,7 +258,7 @@ module Livetext::Standard
258
258
  def dot_include(args = nil, body = nil) # dot command
259
259
  file = api.expand_variables(api.args.first) # allows for variables
260
260
  check_file_exists(file)
261
- # checkpoint "====== self.methods = #{self.methods.sort.inspect}"
261
+ checkpoint
262
262
  @parent.process_file(file)
263
263
  api.optional_blank_line
264
264
  end
@@ -4,8 +4,7 @@ require_relative 'html'
4
4
  # Encapsulate the UserAPI as a class
5
5
 
6
6
  class Livetext::UserAPI
7
-
8
- include ::Livetext::Standard
7
+ include ::Livetext::Standard # FIXME - feels wonky?
9
8
 
10
9
  KBD = File.new("/dev/tty", "r")
11
10
  TTY = File.new("/dev/tty", "w")
@@ -14,7 +13,7 @@ class Livetext::UserAPI
14
13
 
15
14
  attr_accessor :data, :args
16
15
 
17
- def initialize(live)
16
+ def initialize(live) # Livetext::UserAPI
18
17
  @live = live
19
18
  @vars = live.vars
20
19
  @html = HTML.new(self)
@@ -45,7 +44,7 @@ class Livetext::UserAPI
45
44
  # checkpoint "DATA = #{file.inspect}"
46
45
  api.data = file
47
46
  api.args = [file]
48
- api.dot_include
47
+ dot_include
49
48
  end
50
49
 
51
50
  def expand_variables(str)
@@ -215,6 +214,5 @@ class Livetext::UserAPI
215
214
  def debug(*args)
216
215
  TTY.puts *args if @live.debug
217
216
  end
218
-
219
217
  end
220
218
 
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.46"
5
+ VERSION = "0.9.47"
6
6
  end
data/lib/livetext.rb CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  require_relative 'livetext/skeleton'
3
3
  require_relative 'livetext/version'
4
+ require_relative 'livetext/helpers'
5
+ require_relative 'livetext/more'
4
6
  require_relative 'livetext/paths'
5
7
 
6
8
  require_relative 'livetext/reopen'
@@ -11,8 +13,6 @@ require_relative 'livetext/functions'
11
13
  require_relative 'livetext/userapi'
12
14
  require_relative 'livetext/formatter'
13
15
  require_relative 'livetext/processor'
14
- require_relative 'livetext/helpers'
15
- require_relative 'livetext/more'
16
16
 
17
17
  require_relative 'livetext/handler'
18
18
 
@@ -5,11 +5,19 @@ Testing heredocs (used in a table)
5
5
 
6
6
  <center><table width=90% cellpadding=5>
7
7
  <tr>
8
- <td valign=top>This is <br>only <br>a test.<br></td>
9
- <td valign=top>This is <br>just <br>some <br>random text.<br></td>
8
+ <td valign=top>This is <br><br>
9
+ only <br><br>
10
+ a test.<br></td>
11
+ <td valign=top>This is <br><br>
12
+ just <br><br>
13
+ some <br><br>
14
+ random text.<br></td>
10
15
  </tr>
11
16
  <tr>
12
- <td valign=top>And so<br>is this.<br></td>
13
- <td valign=top>This is <br>row 2<br>col 2<br></td>
17
+ <td valign=top>And so<br><br>
18
+ is this.<br></td>
19
+ <td valign=top>This is <br><br>
20
+ row 2<br><br>
21
+ col 2<br></td>
14
22
  </tr>
15
23
  </table></center>
@@ -0,0 +1,15 @@
1
+ Testing heredocs (used in a table)
2
+ <p>
3
+
4
+ <br>
5
+
6
+ <center><table width=90% cellpadding=5>
7
+ <tr>
8
+ <td valign=top>This is <br>only <br>a test.<br></td>
9
+ <td valign=top>This is <br>just <br>some <br>random text.<br></td>
10
+ </tr>
11
+ <tr>
12
+ <td valign=top>And so<br>is this.<br></td>
13
+ <td valign=top>This is <br>row 2<br>col 2<br></td>
14
+ </tr>
15
+ </table></center>
data/test/snapshots.rb CHANGED
@@ -132,7 +132,7 @@ class TestingLivetext < MiniTest::Test
132
132
  @included - @excluded
133
133
  end
134
134
 
135
- def initialize(base, assertion = nil)
135
+ def initialize(base, assertion = nil) # Testing::Livetext
136
136
  @assertion = assertion
137
137
  @base = base
138
138
  @errors = false
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.46
4
+ version: 0.9.47
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-24 00:00:00.000000000 Z
11
+ date: 2024-05-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -26,7 +26,6 @@ files:
26
26
  - imports/markdown.rb
27
27
  - imports/pyggish.rb
28
28
  - imports/tutorial.rb
29
- - lib/cmdargs.rb
30
29
  - lib/livetext.rb
31
30
  - lib/livetext/errors.rb
32
31
  - lib/livetext/expansion.rb
@@ -186,6 +185,7 @@ files:
186
185
  - test/snapshots/subset.txt
187
186
  - test/snapshots/table_with_heredocs/expected-error.txt
188
187
  - test/snapshots/table_with_heredocs/expected-output.txt
188
+ - test/snapshots/table_with_heredocs/old-exp-out.txt
189
189
  - test/snapshots/table_with_heredocs/source.lt3
190
190
  - test/snapshots/var_into_func/expected-error.txt
191
191
  - test/snapshots/var_into_func/expected-output.txt
data/lib/cmdargs.rb DELETED
@@ -1,106 +0,0 @@
1
-
2
- require_relative 'livetext'
3
-
4
- =begin
5
- Weird concepts to understand here...
6
-
7
- 1. A Livetext dot-command (flush left) usually looks like:
8
- .foobar
9
-
10
- 2. A dot-command (left-indented) usually looks like:
11
- $.foobar
12
-
13
- 3. More generally, it may have any number of parameters (0, 1, ...)
14
- .redirect somefile.txt append
15
-
16
- 4. Variables and functions *can* appear (rare in practice??)
17
- .redirect somefile$my_suffix $$my_mode
18
-
19
- 5. A trailing # comment may appear
20
- a. Stripped... saved in #raw ? #data ? #comment ? elsewhere?
21
- b. NOT the "dot" as a comment!
22
-
23
- 6. .foobar # This here is a comment
24
-
25
- 7. #data accessor returns all data on the .foo line...
26
- a. ...After the initial space
27
- b. ...Including later spaces
28
- c. Including comment??
29
- d. .foo This is o n l y a test.
30
- # #data returns: "This is o n l y a test."
31
- e. What about formatting???
32
- f. What about: comments? variables? functions?
33
-
34
- 8. Some commands have NO body while others have an OPTIONAL or REQUIRED body
35
- a. Assume .cmd1 definition forbids a body (then a body is an error)
36
- .cmd1 # may NOT have a body
37
- b. Assume .cmd2 definition PERMITS a body
38
- .cmd2 # may or MAY NOT have body/.end
39
- c. Assume .cmd3 definition REQUIRES a body
40
- .cmd3 # REQUIRES a body/.end
41
- . stuff...
42
- .end
43
-
44
- 9. Inside a body:
45
- a. Leading dot has no special meaning (though the associated method may parse it!)
46
- b. BUG? Currently leading dot is a comment INSIDE a body?
47
- c. No leading char is special (though the associated method may parse it!)
48
- d. No trailing #-comments (though the associated method may parse it!)
49
- e. ?? We should or shouldn't look for variables/functions? or make it an option?
50
- f. .end may naturally not be used (but see .raw where it may)
51
-
52
- 10. The args accessor is a simple array of strings
53
- a. there is also raw_args (without variables/functions, etc.)
54
- b. Much of this HAS NOT been thought through yet!
55
-
56
- =end
57
-
58
- class Livetext::CmdData
59
-
60
- attr_reader :data, :args, :nargs, :arity, :comment, :raw # , ...?
61
-
62
- def initialize(data, body: false, arity: :N) # FIXME maybe just add **options ??
63
- # arity: (num) fixed number 0 or more
64
- # :N arbitrary number
65
- # n1..n2 range
66
- # body: true => this command has a body + .end
67
- # how raw is raw?
68
- # remove comment - always/sometimes/never?
69
- # interpolate - always/sometimes/never?
70
- # interpolate inside body??
71
- @data = data.dup # comment? vars? funcs?
72
- @raw = data.dup # comment? vars? funcs?
73
- @args = data.split # simple array
74
- @nargs = nargs # not really "needed"
75
- check_num_args(nargs)
76
- # @varfunc = Livetext.interpolate(data.dup)
77
- end
78
-
79
- def check_num_args(num)
80
- num_range = /(\d{0,2})(\.\.)(\d{0,2})/ # Not "really" right...
81
- min, max = 0, 9999
82
- mdata = num_range.match(@nargs).to_a
83
- bad_args = nil
84
- case
85
- when @nargs == ":N" # arbitrary
86
- # max already set
87
- when mdata[2] == ".." # range: 4..6 1.. ..4
88
- vmin, vmax = mdata.values_at(1, 2)
89
- min = Integer(vmin) unless vmin.empty?
90
- max = Integer(vmax) unless vmax.empty?
91
- min, max = Integer(min), Integer(max)
92
- when %r[^\d+$] =~ num
93
- min = max = Integer(num) # can raise error
94
- else
95
- raise "Invalid value or range '#{num.inspect}'"
96
- end
97
-
98
- bad_args = @args.size.between?(min, max)
99
- raise "Expected #{num} args but found #{@args.size}!" if bad_args
100
- end
101
-
102
- def strip_comments(str)
103
- str.sub!(/ # .*/, "")
104
- end
105
-
106
- end