livetext 0.8.96 → 0.8.97
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 +4 -4
- data/lib/formatline.rb +0 -2
- data/lib/functions.rb +0 -1
- data/lib/livetext.rb +37 -22
- data/lib/processor.rb +0 -1
- data/lib/standard.rb +0 -14
- data/lib/userapi.rb +6 -13
- data/plugin/tutorial.rb +3 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42bc8ee5bb8b06789cb472fb038081a29fb00fce64583248ffe15f66cd88b9c8
|
4
|
+
data.tar.gz: 7a4acc91072072ae4dffe193ce4e410ecd7251ebe323fb3c038f76e8da5ee6d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8c49581292b3fbf9a25849f0a3403f29dc73ac4e81bb115ef471a5fab413665e32d763b67571f6ecf095b273b36acdc61ff1790c5522d00c3b9de676395e38
|
7
|
+
data.tar.gz: 4573738653920bd64d296e3f9d65f909a10bf438942dabb0b92aac07a2f0d207e33bf5ed00ea5d89db8adcdd9fa655846f936c3ef11e19b13e14b005a53f8896
|
data/lib/formatline.rb
CHANGED
@@ -51,13 +51,11 @@ class FormatLine
|
|
51
51
|
loop do
|
52
52
|
case curr
|
53
53
|
when Escape; grab; add curr; grab; add curr
|
54
|
-
# puts "Found #{curr.inspect}"
|
55
54
|
when "$"
|
56
55
|
dollar
|
57
56
|
when "*", "_", "`", "~"
|
58
57
|
marker curr
|
59
58
|
add curr
|
60
|
-
# grab
|
61
59
|
when LF
|
62
60
|
break if @i >= line.size - 1
|
63
61
|
when nil
|
data/lib/functions.rb
CHANGED
data/lib/livetext.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Livetext
|
2
|
-
VERSION = "0.8.
|
2
|
+
VERSION = "0.8.97"
|
3
3
|
Path = File.expand_path(File.join(File.dirname(__FILE__)))
|
4
4
|
end
|
5
5
|
|
@@ -34,6 +34,14 @@ class Livetext
|
|
34
34
|
Space = " "
|
35
35
|
Sigil = "." # Can't change yet
|
36
36
|
|
37
|
+
def self.rx(str, space=nil)
|
38
|
+
Regexp.compile("^" + Regexp.escape(str) + "#{space}")
|
39
|
+
end
|
40
|
+
|
41
|
+
Comment = rx(Sigil, Livetext::Space)
|
42
|
+
Dotcmd = rx(Sigil)
|
43
|
+
Ddotcmd = /^ *\$\.[A-Za-z]/
|
44
|
+
|
37
45
|
def initialize(output = ::STDOUT)
|
38
46
|
@source = nil
|
39
47
|
@_mixins = []
|
@@ -63,18 +71,14 @@ class Livetext
|
|
63
71
|
_setvar(:File, file)
|
64
72
|
end
|
65
73
|
|
66
|
-
def process_line(line)
|
74
|
+
def process_line(line) # FIXME inefficient?
|
67
75
|
nomarkup = true
|
68
|
-
#
|
69
|
-
|
70
|
-
dotcmd = rx(Sigil)
|
71
|
-
ddotcmd = /^ *\$\.[A-Za-z]/
|
72
|
-
case line
|
73
|
-
when comment
|
76
|
+
case line # must apply these in order
|
77
|
+
when Comment
|
74
78
|
handle_scomment(line)
|
75
|
-
when
|
79
|
+
when Dotcmd
|
76
80
|
handle_dotcmd(line)
|
77
|
-
when
|
81
|
+
when Ddotcmd
|
78
82
|
indent = line.index("$") + 1
|
79
83
|
@indentation.push(indent)
|
80
84
|
line.sub!(/^ *\$/, "")
|
@@ -97,7 +101,23 @@ class Livetext
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
100
|
-
|
104
|
+
# EXPERIMENTAL and incomplete
|
105
|
+
def xform(*args, file: nil, text: nil, vars: nil)
|
106
|
+
case
|
107
|
+
when file && text.nil?
|
108
|
+
xform_file(file)
|
109
|
+
when file.nil? && text
|
110
|
+
when file.nil? && text.nil?
|
111
|
+
raise "Must specify file or text"
|
112
|
+
when file && text
|
113
|
+
raise "Cannot specify file and text"
|
114
|
+
end
|
115
|
+
self.process_file(file)
|
116
|
+
self.body
|
117
|
+
end
|
118
|
+
|
119
|
+
def xform_file(file, vars: nil)
|
120
|
+
Livetext::Vars.replace(vars) unless vars.nil?
|
101
121
|
self.process_file(file)
|
102
122
|
self.body
|
103
123
|
end
|
@@ -106,7 +126,7 @@ class Livetext
|
|
106
126
|
_setfile!("(string)")
|
107
127
|
@output = ::Livetext.output
|
108
128
|
enum = text.each_line
|
109
|
-
front = text.match(/.*?\n/).to_a.first.chomp
|
129
|
+
front = text.match(/.*?\n/).to_a.first.chomp rescue "..."
|
110
130
|
@main.source(enum, "STDIN: '#{front}...'", 0)
|
111
131
|
loop do
|
112
132
|
line = @main.nextline
|
@@ -135,8 +155,8 @@ class Livetext
|
|
135
155
|
rescue => err
|
136
156
|
puts "process_text: err = #{err}"
|
137
157
|
# puts err.backtrace.join("\n")
|
138
|
-
|
139
|
-
|
158
|
+
puts @body
|
159
|
+
@body = ""
|
140
160
|
return @body
|
141
161
|
end
|
142
162
|
|
@@ -176,18 +196,13 @@ class Livetext
|
|
176
196
|
@main.finalize if @main.respond_to? :finalize
|
177
197
|
end
|
178
198
|
|
179
|
-
def rx(str, space=nil)
|
180
|
-
Regexp.compile("^" + Regexp.escape(str) + "#{space}")
|
181
|
-
end
|
182
|
-
|
183
199
|
def handle_scomment(line)
|
184
200
|
end
|
185
201
|
|
186
202
|
def _check_name(name)
|
187
203
|
@main._error! "Name '#{name}' is not permitted" if @main._disallowed?(name)
|
188
|
-
name = "_def" if name == "def"
|
189
|
-
name = "_include" if name == "include"
|
190
204
|
@main._error! "Mismatched 'end'" if name == "end"
|
205
|
+
name = "_" + name if %w[def include].include?(name)
|
191
206
|
name
|
192
207
|
end
|
193
208
|
|
@@ -211,8 +226,8 @@ class Livetext
|
|
211
226
|
result
|
212
227
|
rescue => err
|
213
228
|
@main._error!(err)
|
214
|
-
|
215
|
-
|
229
|
+
puts @body
|
230
|
+
@body = ""
|
216
231
|
return @body
|
217
232
|
end
|
218
233
|
|
data/lib/processor.rb
CHANGED
@@ -34,7 +34,6 @@ class Livetext
|
|
34
34
|
|
35
35
|
def _error!(err, abort=true, trace=false)
|
36
36
|
where = @sources.last || @save_location
|
37
|
-
# puts "-- body = "
|
38
37
|
puts @parent.body
|
39
38
|
STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
|
40
39
|
STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
|
data/lib/standard.rb
CHANGED
@@ -99,7 +99,6 @@ EOS
|
|
99
99
|
eval str
|
100
100
|
rescue => err
|
101
101
|
_error!(err)
|
102
|
-
# puts @body
|
103
102
|
end
|
104
103
|
|
105
104
|
def set
|
@@ -109,7 +108,6 @@ EOS
|
|
109
108
|
# FIXME *Must* allow for vars/functions
|
110
109
|
assigns.each do |a|
|
111
110
|
var, val = a.split("=")
|
112
|
-
# STDERR.puts "-- var=val #{[var, val].inspect}"
|
113
111
|
var.strip!
|
114
112
|
val.strip!
|
115
113
|
val = val[1..-2] if val[0] == ?" && val[-1] == ?"
|
@@ -222,17 +220,6 @@ EOS
|
|
222
220
|
end
|
223
221
|
indent = @parent.indentation.last
|
224
222
|
indented = " " * indent
|
225
|
-
# s2 = ""
|
226
|
-
# str.each_line do |line|
|
227
|
-
# if line.start_with?(indented)
|
228
|
-
# line.replace(line[indent..-1])
|
229
|
-
# else
|
230
|
-
# STDERR.puts "Error? heredoc not indented?"
|
231
|
-
# return
|
232
|
-
# end
|
233
|
-
# s2 << line
|
234
|
-
# end
|
235
|
-
# STDERR.puts "HERE: #{var} = #{s2.chomp.inspect}"
|
236
223
|
@parent._setvar(var, s2.chomp)
|
237
224
|
_optional_blank_line
|
238
225
|
end
|
@@ -263,7 +250,6 @@ EOS
|
|
263
250
|
# like include, but search upward as needed
|
264
251
|
file = @_args.first
|
265
252
|
file = _seek(file)
|
266
|
-
# STDERR.puts "---- _seek found: #{file.inspect}"
|
267
253
|
_error!(file, "No such include file '#{file}'") unless file
|
268
254
|
@parent.process_file(file)
|
269
255
|
_optional_blank_line
|
data/lib/userapi.rb
CHANGED
@@ -45,9 +45,7 @@ module Livetext::UserAPI
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def _end?(str)
|
48
|
-
str
|
49
|
-
str.gsub!(/^ */, "")
|
50
|
-
return true if str == ".end" || str == "$.end"
|
48
|
+
return true if str == ".end" || str =~ / *\$\.end/
|
51
49
|
return false
|
52
50
|
end
|
53
51
|
|
@@ -70,24 +68,19 @@ module Livetext::UserAPI
|
|
70
68
|
end
|
71
69
|
|
72
70
|
def _body(raw=false)
|
73
|
-
lines = []
|
74
|
-
# @save_location = @sources.last
|
71
|
+
lines = [] # @save_location = @sources.last
|
75
72
|
end_found = false
|
76
73
|
loop do
|
77
74
|
@line = nextline
|
78
75
|
break if @line.nil?
|
79
76
|
@line.chomp!
|
80
|
-
|
81
|
-
if
|
82
|
-
|
83
|
-
break
|
84
|
-
end
|
85
|
-
next if _comment?(@line)
|
86
|
-
# FIXME Will cause problem with $. ?
|
77
|
+
end_found = _end?(@line)
|
78
|
+
break if end_found
|
79
|
+
next if _comment?(@line) # FIXME Will cause problem with $. ?
|
87
80
|
@line = _format(@line) unless raw
|
88
81
|
lines << @line
|
89
82
|
end
|
90
|
-
|
83
|
+
|
91
84
|
_optional_blank_line
|
92
85
|
if block_given?
|
93
86
|
lines.each {|line| yield line } # FIXME what about $. ?
|
data/plugin/tutorial.rb
CHANGED
@@ -9,14 +9,9 @@ def section
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def code
|
12
|
-
# _out "<pre>"
|
13
12
|
first = true # dumb hack! fixes blank space
|
14
13
|
_body do |line|
|
15
|
-
if first
|
16
|
-
tag = "<pre>"
|
17
|
-
first = false
|
18
|
-
else
|
19
|
-
end
|
14
|
+
tag, first = "<pre>", false if first
|
20
15
|
_out "#{tag} #{::CGI.escape_html(line)}" # indentation
|
21
16
|
end
|
22
17
|
_out "</pre>"
|
@@ -34,7 +29,7 @@ def inout
|
|
34
29
|
t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
|
35
30
|
t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
|
36
31
|
|
37
|
-
|
32
|
+
_out <<-HTML
|
38
33
|
<table width=80% cellpadding=4>
|
39
34
|
<tr>
|
40
35
|
<td width=50%><b>Input</b></td>
|
@@ -58,7 +53,7 @@ def put_table(src, exp)
|
|
58
53
|
t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
|
59
54
|
t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
|
60
55
|
|
61
|
-
|
56
|
+
_out <<-HTML
|
62
57
|
<font size=+1>
|
63
58
|
<table width=80% cellpadding=4>
|
64
59
|
<tr>
|
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.
|
4
|
+
version: 0.8.97
|
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-12-
|
11
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A smart text processor extensible in Ruby
|
14
14
|
email: rubyhacker@gmail.com
|