livetext 0.8.78 → 0.8.79

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
- SHA256:
3
- metadata.gz: 14f8d44bfa9cd1fbcd49da2f848df5ed1e8dd6086555a8b163d43e0137303284
4
- data.tar.gz: f695e704124133507245e5ec0c7e596aa1b4c97117e14c2ac79b6497a83224c8
2
+ SHA1:
3
+ metadata.gz: b10afcc4cb31c7ee535b019ad71dceb81642288b
4
+ data.tar.gz: 31071b49e22b3a45638588cfc626364e47a1c205
5
5
  SHA512:
6
- metadata.gz: 39c10beb0b76dbcfa9221bba0b0dccde17294b943d4a50639b7b1e66766040ce32a780d1849df3512efdfeb016abbccdd78298bde802001d8f131bee06f0ee39
7
- data.tar.gz: 794dbdb41daed694e3d1f3fce433c7cfaa2a5846ffb7b03610b35ce9ab8b52d48b4d1ebf66a7a1bb15da41dd59baa380fcfc82f97d0d719512034372799f99a0
6
+ metadata.gz: 6174fa5fd3f5c0b4169adf59f89fe8aa438d324819ddb382210cf6e1ef3a4f26a2120f69d9c3fd8d85dcd709a081cdfb6ba35a68ae1be2c94958c95751718678
7
+ data.tar.gz: 2ff43baa577625b28d82b7ba2dcfaee894216124de6ed60c4252369dd28f158dc94141954d7b92243acd57469eee9f6e6af319bf691900bc3c82a705c916496c
@@ -28,7 +28,7 @@ class FormatLine
28
28
 
29
29
  attr_reader :out
30
30
 
31
- def initialize(line, context)
31
+ def initialize(line, context=nil)
32
32
  context ||= binding
33
33
  @context = context
34
34
  @line = line
@@ -38,8 +38,9 @@ class FormatLine
38
38
  end
39
39
 
40
40
  def self.parse!(line, context = nil)
41
+ return nil if line.nil?
41
42
  x = self.new(line.chomp, context)
42
- x.tokenize(line)
43
+ t = x.tokenize(line)
43
44
  x.evaluate # (context)
44
45
  end
45
46
 
@@ -49,7 +50,7 @@ class FormatLine
49
50
  case curr
50
51
  when Escape; go; add curr; grab
51
52
  when "$"
52
- _dollar
53
+ dollar
53
54
  when "*", "_", "`", "~"
54
55
  marker curr
55
56
  add curr
@@ -78,6 +79,8 @@ class FormatLine
78
79
  break if token.nil?
79
80
  sym, val = *token
80
81
  case sym
82
+ when :ddot
83
+ return [@out, val]
81
84
  when :str
82
85
  @out << val unless val == "\n" # BUG
83
86
  when :var
@@ -97,7 +100,7 @@ class FormatLine
97
100
  end
98
101
  token = gen.next
99
102
  end
100
- @out
103
+ [@out, nil]
101
104
  end
102
105
 
103
106
  def curr
@@ -181,14 +184,14 @@ class FormatLine
181
184
  str
182
185
  end
183
186
 
184
- def _dollar
187
+ def dollar
185
188
  grab
186
189
  case curr
187
190
  when LF; add "$"; add_token :str
188
191
  when " "; add "$ "; add_token :str
189
192
  when nil; add "$"; add_token :str
190
- when "$"; _double_dollar
191
- when "."; _dollar_dot
193
+ when "$"; double_dollar
194
+ when "."; dollar_dot
192
195
  when /[A-Za-z]/
193
196
  add_token :str
194
197
  var = curr + grab_alpha
@@ -199,7 +202,7 @@ class FormatLine
199
202
  end
200
203
  end
201
204
 
202
- def _double_dollar
205
+ def double_dollar
203
206
  case next!
204
207
  when Space; add_token :string, "$$ "; grab; return
205
208
  when LF, nil; add "$$"; add_token :str
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.8.78"
2
+ VERSION = "0.8.79"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -32,6 +32,7 @@ class Livetext
32
32
  end
33
33
 
34
34
  Space = " "
35
+ Sigil = "." # Can't change yet
35
36
 
36
37
  def initialize(output = ::STDOUT)
37
38
  @source = nil
@@ -45,17 +46,17 @@ class Livetext
45
46
  def process_line(line, context=nil)
46
47
  context ||= binding
47
48
  @context = context
48
- sigil = "." # Can't change yet
49
49
  nomarkup = true
50
50
  # FIXME inefficient
51
- scomment = rx(sigil, Livetext::Space) # apply these in order
52
- sname = rx(sigil)
51
+ scomment = rx(Sigil, Livetext::Space) # apply these in order
52
+ sname = rx(Sigil)
53
53
  if line =~ scomment
54
54
  handle_scomment(line)
55
55
  elsif line =~ sname
56
- handle_sname(line)
56
+ handle_dotcmd(line)
57
57
  else
58
58
  @main._passthru(line, context)
59
+ # Can output extra line(s) in $. scenario
59
60
  end
60
61
  end
61
62
 
@@ -142,7 +143,7 @@ class Livetext
142
143
  Regexp.compile("^" + Regexp.escape(str) + "#{space}")
143
144
  end
144
145
 
145
- def handle_scomment(line, sigil=".")
146
+ def handle_scomment(line)
146
147
  end
147
148
 
148
149
  def _check_name(name)
@@ -153,15 +154,15 @@ class Livetext
153
154
  name
154
155
  end
155
156
 
156
- def _get_name(line, sigil=".")
157
+ def _get_name(line)
157
158
  name, data = line.split(" ", 2)
158
159
  name = name[1..-1] # chop off sigil
159
160
  @main.data = data
160
161
  name = _check_name(name)
161
162
  end
162
163
 
163
- def handle_sname(line, sigil=".")
164
- name = _get_name(line, sigil)
164
+ def handle_dotcmd(line)
165
+ name = _get_name(line)
165
166
  result = nil
166
167
  if @main.respond_to?(name)
167
168
  result = @main.send(name)
@@ -34,7 +34,7 @@ class Livetext
34
34
  where = @sources.last || @save_location
35
35
  puts @parent.body
36
36
  STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
37
- # STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
37
+ STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
38
38
  exit if abort
39
39
  end
40
40
 
@@ -59,13 +59,13 @@ module Livetext::Standard
59
59
  end
60
60
 
61
61
  def say
62
- str = _formatting(@_data)
62
+ str = _format(@_data)
63
63
  TTY.puts str
64
64
  _optional_blank_line
65
65
  end
66
66
 
67
67
  def banner
68
- str = _formatting(@_data)
68
+ str = _format(@_data)
69
69
  n = str.length - 1
70
70
  _errout "-"*n
71
71
  _errout str
@@ -157,7 +157,8 @@ module Livetext::Standard
157
157
  var, val = a.split("=")
158
158
  val = val[1..-2] if val[0] == ?" and val[-1] == ?"
159
159
  val = val[1..-2] if val[0] == ?' and val[-1] == ?'
160
- Livetext::Vars[var] = val
160
+ Livetext::Vars[var.to_sym] = val
161
+ Livetext::Vars[var] = val # FIXME
161
162
  end
162
163
  _optional_blank_line
163
164
  end
@@ -199,6 +200,7 @@ module Livetext::Standard
199
200
  meths = grab_file(file)
200
201
  modname = name.gsub("/","_").capitalize
201
202
  string = "module ::#{modname}\n#{meths}\nend"
203
+ # puts string # .inspect
202
204
  eval(string)
203
205
  newmod = Object.const_get("::" + modname)
204
206
  self.extend(newmod)
@@ -284,7 +286,7 @@ module Livetext::Standard
284
286
  delim = _args.first
285
287
  _out "<dl>"
286
288
  _body do |line|
287
- line = _formatting(line)
289
+ line = _format(line)
288
290
  term, defn = line.split(delim)
289
291
  _out "<dt>#{term}</dt>"
290
292
  _out "<dd>#{defn}</dd>"
@@ -296,7 +298,7 @@ module Livetext::Standard
296
298
  delim = _args.first
297
299
  _out "<table>"
298
300
  _body do |line|
299
- line = _formatting(line)
301
+ line = _format(line)
300
302
  term, defn = line.split(delim)
301
303
  _out "<tr>"
302
304
  _out "<td width=3%><td width=10%>#{term}</td><td>#{defn}</td>"
@@ -318,7 +320,7 @@ module Livetext::Standard
318
320
  lines = _body(true)
319
321
  maxw = nil
320
322
  lines.each do |line|
321
- _formatting(line) # May split into multiple lines!
323
+ line = _format(line)
322
324
  line.gsub!(/\n+/, "<br>")
323
325
  cells = line.split(delim)
324
326
  wide = cells.map {|x| x.length }
@@ -24,7 +24,8 @@ module Livetext::UserAPI
24
24
  @line = nextline if peek_nextline =~ /^ *$/
25
25
  end
26
26
 
27
- def _comment?(str, sigil=".")
27
+ def _comment?(str)
28
+ sigil = Livetext::Sigil
28
29
  c1 = sigil + Livetext::Space
29
30
  c2 = sigil + sigil + Livetext::Space
30
31
  str.index(c1) == 0 || str.index(c2) == 0
@@ -35,21 +36,20 @@ module Livetext::UserAPI
35
36
  return false
36
37
  end
37
38
 
38
- def _end?(str, sigil=".")
39
+ def _end?(str)
39
40
  return false if str.nil?
40
- cmd = sigil + "end"
41
+ cmd = Livetext::Sigil + "end"
41
42
  return false if str.index(cmd) != 0
42
43
  return false unless _trailing?(str[5])
43
44
  return true
44
45
  end
45
46
 
46
- def _raw_body(tag = "__EOF__", sigil = ".")
47
+ def _raw_body(tag = "__EOF__")
47
48
  lines = []
48
49
  @save_location = @sources.last
49
50
  loop do
50
51
  @line = nextline
51
52
  break if @line.chomp.strip == tag
52
- # STDERR.puts "_raw_body adds: #{@line.inspect}"
53
53
  lines << @line
54
54
  end
55
55
  _optional_blank_line
@@ -58,39 +58,39 @@ module Livetext::UserAPI
58
58
  else
59
59
  lines
60
60
  end
61
- # STDERR.puts "_raw_body returns: #{lines.inspect}"
62
61
  lines
63
62
  end
64
63
 
65
- def _body(raw=false, sigil=".")
64
+ def _body(raw=false)
66
65
  lines = []
67
66
  @save_location = @sources.last
68
67
  loop do
69
68
  @line = nextline
70
69
  raise if @line.nil?
71
- break if _end?(@line, sigil)
72
- next if _comment?(@line, sigil) # FIXME?
73
- @line = _formatting(@line) unless raw
74
- lines << @line
70
+ break if _end?(@line)
71
+ next if _comment?(@line)
72
+ # FIXME Will cause problem with $. ?
73
+ @line = _format(@line) unless raw
74
+ lines << @line
75
75
  end
76
76
  _optional_blank_line
77
77
  if block_given?
78
- lines.each {|line| yield line }
78
+ lines.each {|line| yield line } # FIXME what about $. ?
79
79
  else
80
80
  lines
81
81
  end
82
82
  rescue => err
83
- # FIXME ?
83
+ p err.inspect
84
+ puts err.backtrace
84
85
  _error!("Expecting .end, found end of file")
85
- # puts @body
86
86
  end
87
87
 
88
- def _body_text(raw=false, sigil=".")
89
- _body(sigil).join("")
88
+ def _body_text(raw=false)
89
+ _body(Livetext::Sigil).join("")
90
90
  end
91
91
 
92
- def _raw_body!(sigil=".")
93
- _raw_body(sigil).join("\n")
92
+ def _raw_body!
93
+ _raw_body(Livetext::Sigil).join("\n")
94
94
  end
95
95
 
96
96
  def _handle_escapes(str, set)
@@ -101,26 +101,39 @@ module Livetext::UserAPI
101
101
  str
102
102
  end
103
103
 
104
- def _formatting(line, context = nil)
104
+ def _format(line, context = nil)
105
+ return ["", nil] if line == "\n"
106
+ l2 = FormatLine.parse!(line, context)
107
+ line1, line2 = *l2
108
+ line.replace(line1) unless line.nil?
109
+ line
110
+ end
111
+
112
+ def _format!(line, context = nil)
113
+ return ["", nil] if line == "\n"
105
114
  l2 = FormatLine.parse!(line, context)
106
- line.replace(l2)
115
+ # maybe move fix back toward parse! ?
116
+ line1, line2 = *l2
117
+ line2 = line2.dup
118
+ line.replace(line1) unless line.nil?
119
+ line2 = @parent.handle_dotcmd(line2) unless line2.nil?
120
+ [line, line2]
107
121
  end
108
122
 
109
123
  def _passthru(line, context = nil)
110
124
  return if @_nopass
111
125
  _out "<p>" if line == "\n" and ! @_nopara
112
- line = _formatting(line, context)
126
+ line, line2 = *_format!(line, context)
127
+ p line
128
+ p line2
113
129
  _out line
130
+ _out line2
114
131
  end
115
132
 
116
133
  def _out(str = "")
117
- # if @no_puts
118
- # STDERR.puts "_out: #{str.inspect}"
119
- @parent.body << str
120
- @parent.body << "\n" unless str.end_with?("\n")
121
- # else
122
- # _puts str
123
- # end
134
+ return if str.nil?
135
+ @parent.body << str
136
+ @parent.body << "\n" unless str.end_with?("\n")
124
137
  end
125
138
 
126
139
  def _out!(str = "")
@@ -25,7 +25,7 @@ def list!
25
25
  lines = _body.each # {|line| _out "<li>#{line}</li>" }
26
26
  loop do
27
27
  line = lines.next
28
- line = _formatting(line)
28
+ line = _format(line)
29
29
  if line[0] == " "
30
30
  _out line
31
31
  else
@@ -77,7 +77,7 @@ def figure
77
77
  name = @_args[0]
78
78
  num = @_args[1]
79
79
  title = @_args[2..-1].join(" ")
80
- title = _formatting(title)
80
+ title = _format(title)
81
81
  _out "<img src='#{name}'></img>"
82
82
  _out "<center><b>Figure #{num}</b> #{title}</center>"
83
83
  end
@@ -138,7 +138,7 @@ def table2
138
138
  delim = " :: "
139
139
  _out "<br><center><table border=1 width=#{wide}% cellpadding=5>"
140
140
  lines = _body(true)
141
- lines.map! {|line| _formatting(line) }
141
+ lines.map! {|line| _format(line) }
142
142
 
143
143
  lines.each do |line|
144
144
  cells = line.split(delim)
@@ -162,7 +162,7 @@ def simple_table
162
162
  lines = _body(true)
163
163
  maxw = nil
164
164
  lines.each do |line|
165
- _formatting(line)
165
+ _format(line)
166
166
  cells = line.split(delim)
167
167
  wide = cells.map {|x| x.length }
168
168
  maxw = [0] * cells.size
@@ -193,7 +193,7 @@ def table
193
193
  lines = _body(true)
194
194
  maxw = nil
195
195
  lines.each do |line|
196
- _formatting(line)
196
+ _format(line)
197
197
  cells = line.split(delim)
198
198
  wide = cells.map {|x| x.length }
199
199
  maxw = [0] * cells.size
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
 
3
3
  def epub!
4
- out = _formatting(@_args[0])
4
+ out = _format(@_args[0])
5
5
  src = @_args[1]
6
6
  @cover = @_args[2]
7
7
  if ::File.directory?(src)
@@ -33,7 +33,7 @@ def olist # Doesn't handle paragraphs yet
33
33
  n = 0
34
34
  _body do |line|
35
35
  n += 1
36
- _out "#{n}. #{_formatting(line)}"
36
+ _out "#{n}. #{_format(line)}"
37
37
  end
38
38
  end
39
39
 
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.8.78
4
+ version: 0.8.79
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-27 00:00:00.000000000 Z
11
+ date: 2019-04-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -20,8 +20,6 @@ files:
20
20
  - "./README.lt3"
21
21
  - "./README.md"
22
22
  - bin/livetext
23
- - lib/SAVE.formatline
24
- - lib/SAVE2.formatline.rb
25
23
  - lib/formatline.rb
26
24
  - lib/functions.rb
27
25
  - lib/livetext.rb
@@ -38,7 +36,6 @@ files:
38
36
  - test/affirm/kbks.jpg
39
37
  - test/affirm/lm-kbks.lt
40
38
  - test/cleanup
41
- - test/data/SAVE.lines
42
39
  - test/data/basic_formatting/expected-error.txt
43
40
  - test/data/basic_formatting/expected-output.txt
44
41
  - test/data/basic_formatting/source.lt3
@@ -153,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
150
  version: '0'
154
151
  requirements: []
155
152
  rubyforge_project:
156
- rubygems_version: 2.7.7
153
+ rubygems_version: 2.4.6
157
154
  signing_key:
158
155
  specification_version: 4
159
156
  summary: A smart processor for text