livetext 0.9.46 → 0.9.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/livetext/{more.rb → core.rb} +1 -54
- data/lib/livetext/errors.rb +3 -3
- data/lib/livetext/expansion.rb +3 -1
- data/lib/livetext/formatter.rb +158 -159
- data/lib/livetext/functions.rb +1 -1
- data/lib/livetext/global_helpers.rb +1 -1
- data/lib/livetext/handler/import.rb +2 -2
- data/lib/livetext/handler/mixin.rb +2 -2
- data/lib/livetext/helpers.rb +2 -10
- data/lib/livetext/html.rb +2 -35
- data/lib/livetext/parser/general.rb +1 -1
- data/lib/livetext/parser/set.rb +1 -1
- data/lib/livetext/parser/string.rb +1 -1
- data/lib/livetext/paths.rb +1 -1
- data/lib/livetext/processor.rb +2 -4
- data/lib/livetext/skeleton.rb +10 -1
- data/lib/livetext/standard.rb +3 -5
- data/lib/livetext/userapi.rb +4 -6
- data/lib/livetext/variables.rb +50 -0
- data/lib/livetext/version.rb +1 -1
- data/lib/livetext.rb +17 -15
- data/test/all.rb +3 -0
- data/test/extra/README.txt +1 -0
- data/test/snapshots/table_with_heredocs/expected-output.txt +12 -4
- data/test/snapshots/table_with_heredocs/old-exp-out.txt +15 -0
- data/test/snapshots.rb +1 -1
- data/test/unit/all.rb +7 -0
- data/test/unit/html.rb +2 -2
- data/test/{extra → unit}/single.rb +1 -4
- metadata +10 -9
- data/lib/cmdargs.rb +0 -106
- /data/test/{extra → unit}/bracketed.rb +0 -0
- /data/test/{extra → unit}/double.rb +0 -0
- /data/test/{extra → unit}/functions.rb +0 -0
- /data/test/{extra → unit}/variables.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91574e23cbcbe19d5c06d7c1fbbe8fbbe33ca29b06511da502b532bbb28519c6
|
4
|
+
data.tar.gz: 553612fc90e8a6f3676158c3e98997415d0b568fb811fc9d273f8a2ae47478b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 909f58be5cd6ee9d11262bb7213d2fab733d379ac678953c0e0225486cdc7a24152b8f5e5b208f2522bf4ea629abd9597c14b3cce1988b19c89b3b92d96f729b
|
7
|
+
data.tar.gz: e6e9aaec3cba4d466601d9b4d2f2d96bbb3c3697640684d96c23d70b41843d6a5674a4f41e659355df45a72c59842f7e91df44c76455a430425836db17f1e8e7
|
@@ -2,59 +2,8 @@
|
|
2
2
|
# Class Livetext reopened (top level).
|
3
3
|
|
4
4
|
class Livetext
|
5
|
-
|
6
5
|
include Helpers
|
7
6
|
|
8
|
-
class Variables
|
9
|
-
attr_reader :vars
|
10
|
-
|
11
|
-
def initialize(hash = {})
|
12
|
-
@vars = {}
|
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
|
28
|
-
end
|
29
|
-
|
30
|
-
def [](var)
|
31
|
-
@vars[var.to_sym]
|
32
|
-
end
|
33
|
-
|
34
|
-
def []=(var, value)
|
35
|
-
@vars[var.to_sym] = value
|
36
|
-
end
|
37
|
-
|
38
|
-
def get(var)
|
39
|
-
@vars[var.to_sym] || "[#{var} is undefined]"
|
40
|
-
end
|
41
|
-
|
42
|
-
def set(var, value)
|
43
|
-
@vars[var.to_sym] = value.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
def setvars(pairs)
|
47
|
-
pairs = pairs.to_a if pairs.is_a?(Hash)
|
48
|
-
pairs.each do |var, value|
|
49
|
-
api.setvar(var, value)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_a
|
54
|
-
@vars.to_a
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
7
|
Vars = Variables.new
|
59
8
|
|
60
9
|
TTY = ::File.open("/dev/tty", "w")
|
@@ -98,7 +47,7 @@ class Livetext
|
|
98
47
|
@save_location = where # delegate
|
99
48
|
end
|
100
49
|
|
101
|
-
def initialize(output = ::STDOUT)
|
50
|
+
def initialize(output = ::STDOUT) # Livetext
|
102
51
|
@source = nil
|
103
52
|
@_mixins = []
|
104
53
|
@_imports = []
|
@@ -123,8 +72,6 @@ class Livetext
|
|
123
72
|
end
|
124
73
|
call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
|
125
74
|
obj.api.setvars(vars)
|
126
|
-
# puts "------ init: obj = "
|
127
|
-
# p obj
|
128
75
|
obj
|
129
76
|
end
|
130
77
|
|
data/lib/livetext/errors.rb
CHANGED
@@ -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
|
-
|
data/lib/livetext/expansion.rb
CHANGED
data/lib/livetext/formatter.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
|
-
module Formatter
|
1
|
+
module Livetext::Formatter
|
2
2
|
|
3
|
-
|
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,188 +8,195 @@ module Formatter
|
|
16
8
|
s4
|
17
9
|
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
11
|
+
## Hmmm...
|
12
|
+
#
|
13
|
+
# Double: b, i, t, s
|
14
|
+
# Single: bits
|
15
|
+
# Brackt: bits
|
16
|
+
#
|
26
17
|
|
27
|
-
|
28
|
-
if $debug
|
29
|
-
STDERR.printf "%-11s %-7s #{@marker.inspect} \n #{' '*11} state = %-8s str = %-20s buffer = %-20s cdata = %-20s\n",
|
30
|
-
where, self.class, @state, @str.inspect, @buffer.inspect, @cdata.inspect
|
31
|
-
end
|
32
|
-
end
|
18
|
+
end
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
class Livetext::Formatter::Delimited
|
21
|
+
def initialize(str, marker, tag) # Delimited
|
22
|
+
@str, @marker, @tag = str.dup, marker, tag
|
23
|
+
@buffer = ""
|
24
|
+
@cdata = ""
|
25
|
+
@state = :INITIAL
|
26
|
+
end
|
37
27
|
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
def status(where)
|
29
|
+
if $debug
|
30
|
+
STDERR.printf "%-11s %-7s #{@marker.inspect} \n #{' '*11} state = %-8s str = %-20s buffer = %-20s cdata = %-20s\n",
|
31
|
+
where, self.class, @state, @str.inspect, @buffer.inspect, @cdata.inspect
|
41
32
|
end
|
33
|
+
end
|
42
34
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# Don't? what if searching for space_marker?
|
47
|
-
# @buffer << grab
|
48
|
-
end
|
35
|
+
def front
|
36
|
+
@str[0]
|
37
|
+
end
|
49
38
|
|
50
|
-
|
51
|
-
|
52
|
-
|
39
|
+
def grab(n=1)
|
40
|
+
char = @str.slice!(0..(n-1)) # grab n chars
|
41
|
+
char
|
42
|
+
end
|
53
43
|
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
def grab_terminator
|
45
|
+
@state = :LOOPING
|
46
|
+
# goes onto buffer by default
|
47
|
+
# Don't? what if searching for space_marker?
|
48
|
+
# @buffer << grab
|
49
|
+
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
def eol?
|
52
|
+
@str.empty?
|
53
|
+
end
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
def space?
|
56
|
+
front == " "
|
57
|
+
end
|
65
58
|
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
def escape?
|
60
|
+
front == "\\"
|
61
|
+
end
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
def terminated?
|
64
|
+
space? # Will be overridden except in Single
|
65
|
+
end
|
73
66
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
67
|
+
def marker?
|
68
|
+
@str.start_with?(@marker)
|
69
|
+
end
|
70
|
+
|
71
|
+
def space_marker?
|
72
|
+
@str.start_with?(" " + @marker)
|
73
|
+
end
|
74
|
+
|
75
|
+
def wrap(text)
|
76
|
+
if text.empty?
|
77
|
+
result = @marker
|
78
|
+
result = "" if @marker[1] == "["
|
79
|
+
return result
|
81
80
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
81
|
+
"<#{@tag}>#{text}</#{@tag}>"
|
82
|
+
end
|
83
|
+
|
84
|
+
def initial
|
85
|
+
n = @marker.length
|
86
|
+
case
|
87
|
+
when escape?
|
88
|
+
grab # backslash
|
89
|
+
@buffer << grab # char
|
90
|
+
when space_marker?
|
91
|
+
@buffer << grab # append the space
|
92
|
+
grab(n) # eat the marker
|
93
|
+
@state = :CDATA
|
94
|
+
when marker?
|
95
|
+
grab(n) # Eat the marker
|
96
|
+
@state = :CDATA
|
97
|
+
when eol?
|
98
|
+
@state = :FINAL
|
99
|
+
else
|
100
|
+
@state = :BUFFER
|
101
101
|
end
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
def buffer
|
105
|
+
@buffer << grab
|
106
|
+
@state = :LOOPING
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
else
|
114
|
-
@buffer << wrap(@cdata)
|
115
|
-
end
|
116
|
-
@state = :FINAL
|
117
|
-
when terminated?
|
118
|
-
@buffer << wrap(@cdata)
|
119
|
-
grab_terminator # "*a *b" case???
|
120
|
-
@cdata = ""
|
121
|
-
@state = :LOOPING
|
109
|
+
def cdata
|
110
|
+
case
|
111
|
+
when eol?
|
112
|
+
if @cdata.empty?
|
113
|
+
@buffer << @marker unless @marker[1] == "["
|
122
114
|
else
|
123
|
-
@
|
124
|
-
@state = :CDATA
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def looping
|
129
|
-
n = @marker.length
|
130
|
-
case
|
131
|
-
when escape?
|
132
|
-
grab # backslash
|
133
|
-
@buffer << grab # char
|
134
|
-
when space_marker?
|
135
|
-
@buffer << grab # append the space
|
136
|
-
grab(n) # eat the marker
|
137
|
-
@state = :CDATA
|
138
|
-
when eol?
|
139
|
-
@state = :FINAL
|
140
|
-
else # includes marker not preceded by space!
|
141
|
-
@buffer << grab
|
115
|
+
@buffer << wrap(@cdata)
|
142
116
|
end
|
117
|
+
@state = :FINAL
|
118
|
+
when terminated?
|
119
|
+
@buffer << wrap(@cdata)
|
120
|
+
grab_terminator # "*a *b" case???
|
121
|
+
@cdata = ""
|
122
|
+
@state = :LOOPING
|
123
|
+
else
|
124
|
+
@cdata << grab
|
125
|
+
@state = :CDATA
|
143
126
|
end
|
127
|
+
end
|
144
128
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
129
|
+
def looping
|
130
|
+
n = @marker.length
|
131
|
+
case
|
132
|
+
when escape?
|
133
|
+
grab # backslash
|
134
|
+
@buffer << grab # char
|
135
|
+
when space_marker?
|
136
|
+
@buffer << grab # append the space
|
137
|
+
grab(n) # eat the marker
|
138
|
+
@state = :CDATA
|
139
|
+
when eol?
|
140
|
+
@state = :FINAL
|
141
|
+
else # includes marker not preceded by space!
|
142
|
+
@buffer << grab
|
152
143
|
end
|
144
|
+
end
|
153
145
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
si = ital.handle
|
160
|
-
code = self.new(si, "`", "tt")
|
161
|
-
sc = code.handle
|
162
|
-
stri = self.new(sc, "~", "strike")
|
163
|
-
si = stri.handle
|
164
|
-
si
|
146
|
+
def handle
|
147
|
+
loop do
|
148
|
+
break if @state == :FINAL
|
149
|
+
meth = @state.downcase
|
150
|
+
send(meth)
|
165
151
|
end
|
152
|
+
return @buffer
|
166
153
|
end
|
167
154
|
|
168
|
-
|
169
|
-
|
155
|
+
def self.process(str)
|
156
|
+
bold = self.new(str, "*", "b")
|
157
|
+
sb = bold.handle
|
158
|
+
# return sb
|
159
|
+
ital = self.new(sb, "_", "i")
|
160
|
+
si = ital.handle
|
161
|
+
code = self.new(si, "`", "tt")
|
162
|
+
sc = code.handle
|
163
|
+
stri = self.new(sc, "~", "strike")
|
164
|
+
si = stri.handle
|
165
|
+
si
|
170
166
|
end
|
167
|
+
end
|
171
168
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
# Convention: marker is "**", sigil is "*"
|
176
|
-
@marker = sigil + sigil
|
177
|
-
end
|
169
|
+
class Livetext::Formatter::Single < Livetext::Formatter::Delimited
|
170
|
+
# Yeah, this one is that simple
|
171
|
+
end
|
178
172
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
173
|
+
class Livetext::Formatter::Double < Livetext::Formatter::Delimited
|
174
|
+
def initialize(str, sigil, tag) # Double
|
175
|
+
super
|
176
|
+
# Convention: marker is "**", sigil is "*"
|
177
|
+
@marker = sigil + sigil
|
183
178
|
end
|
184
179
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
180
|
+
def terminated?
|
181
|
+
terms = [" ", ".", ","]
|
182
|
+
terms.include?(front)
|
183
|
+
end
|
184
|
+
end
|
191
185
|
|
192
|
-
|
193
|
-
|
194
|
-
|
186
|
+
class Livetext::Formatter::Bracketed < Livetext::Formatter::Delimited
|
187
|
+
def initialize(str, sigil, tag) # Bracketed
|
188
|
+
super
|
189
|
+
# Convention: marker is "*[", sigil is "*"
|
190
|
+
@marker = sigil + "["
|
191
|
+
end
|
195
192
|
|
196
|
-
|
197
|
-
|
198
|
-
grab
|
199
|
-
end
|
193
|
+
def terminated?
|
194
|
+
front == "]" || eol?
|
200
195
|
end
|
201
196
|
|
197
|
+
def grab_terminator
|
198
|
+
@state = :LOOPING
|
199
|
+
grab
|
200
|
+
end
|
202
201
|
end
|
203
202
|
|
data/lib/livetext/functions.rb
CHANGED
@@ -5,11 +5,11 @@ require_relative '../helpers'
|
|
5
5
|
|
6
6
|
class Livetext::Handler::Import
|
7
7
|
include Livetext::Helpers
|
8
|
-
include GlobalHelpers
|
8
|
+
include Livetext::GlobalHelpers
|
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
|
@@ -5,11 +5,11 @@ require_relative '../helpers'
|
|
5
5
|
|
6
6
|
class Livetext::Handler::Mixin
|
7
7
|
include Livetext::Helpers
|
8
|
-
include GlobalHelpers
|
8
|
+
include Livetext::GlobalHelpers
|
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?
|
data/lib/livetext/helpers.rb
CHANGED
@@ -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 Livetext::HTML
|
1
2
|
|
2
|
-
#
|
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/parser/set.rb
CHANGED
data/lib/livetext/paths.rb
CHANGED
data/lib/livetext/processor.rb
CHANGED
@@ -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)
|
@@ -35,7 +35,7 @@ class Processor
|
|
35
35
|
@indentation = @parent.indentation
|
36
36
|
@_mixins = []
|
37
37
|
@_imports = []
|
38
|
-
@html = HTML.new(@parent.api)
|
38
|
+
@html = Livetext::HTML.new(@parent.api)
|
39
39
|
end
|
40
40
|
|
41
41
|
def api
|
@@ -85,6 +85,4 @@ class Processor
|
|
85
85
|
@sources.pop
|
86
86
|
nil
|
87
87
|
end
|
88
|
-
|
89
|
-
|
90
88
|
end
|
data/lib/livetext/skeleton.rb
CHANGED
@@ -3,10 +3,19 @@ require_relative 'parser/string' # FIXME eh, should fix this
|
|
3
3
|
# Class Livetext skeleton (top level).
|
4
4
|
|
5
5
|
class Livetext
|
6
|
+
class Variables
|
7
|
+
end
|
8
|
+
|
6
9
|
module Handler
|
7
10
|
end
|
8
11
|
|
9
|
-
module
|
12
|
+
module Formatter
|
13
|
+
end
|
14
|
+
|
15
|
+
class HTML
|
16
|
+
end
|
17
|
+
|
18
|
+
class ParsingConstants
|
10
19
|
end
|
11
20
|
|
12
21
|
class LineParser < StringParser
|
data/lib/livetext/standard.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'pathname' # For _seek - remove later??
|
3
2
|
|
4
3
|
require_relative 'parser' # nested requires
|
@@ -9,12 +8,9 @@ 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
|
16
|
-
|
17
|
-
# include HTMLHelper
|
18
14
|
include Livetext::Helpers
|
19
15
|
|
20
16
|
TTY = ::File.open("/dev/tty", "w")
|
@@ -74,6 +70,8 @@ module Livetext::Standard
|
|
74
70
|
return true
|
75
71
|
end
|
76
72
|
|
73
|
+
# FIXME - move these to a single universal place in code
|
74
|
+
|
77
75
|
def h1(args = nil, body = nil); api.out html.tag(:h1, cdata: api.data); return true; end
|
78
76
|
def h2(args = nil, body = nil); api.out html.tag(:h2, cdata: api.data); return true; end
|
79
77
|
def h3(args = nil, body = nil); api.out html.tag(:h3, cdata: api.data); return true; end
|
@@ -258,7 +256,7 @@ module Livetext::Standard
|
|
258
256
|
def dot_include(args = nil, body = nil) # dot command
|
259
257
|
file = api.expand_variables(api.args.first) # allows for variables
|
260
258
|
check_file_exists(file)
|
261
|
-
|
259
|
+
checkpoint
|
262
260
|
@parent.process_file(file)
|
263
261
|
api.optional_blank_line
|
264
262
|
end
|
data/lib/livetext/userapi.rb
CHANGED
@@ -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,10 +13,10 @@ 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
|
-
@html = HTML.new(self)
|
19
|
+
@html = Livetext::HTML.new(self)
|
21
20
|
@expander = Livetext::Expansion.new(live)
|
22
21
|
end
|
23
22
|
|
@@ -45,7 +44,7 @@ class Livetext::UserAPI
|
|
45
44
|
# checkpoint "DATA = #{file.inspect}"
|
46
45
|
api.data = file
|
47
46
|
api.args = [file]
|
48
|
-
|
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
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Livetext::Variables # FIXME - split out into file as Livetext::Variables
|
2
|
+
attr_reader :vars
|
3
|
+
|
4
|
+
def initialize(hash = {}) # Livetext::Variables
|
5
|
+
@vars = {}
|
6
|
+
hash.each_pair do |k, v|
|
7
|
+
sym = k.to_sym
|
8
|
+
str = k.to_s
|
9
|
+
@vars[sym] = v
|
10
|
+
@vars[str] = v
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
syms = @vars.keys.select {|x| x.is_a? Symbol }
|
16
|
+
out = "\nVariables:"
|
17
|
+
syms.each do |sym|
|
18
|
+
out << " #{sym}: #{@vars[sym].inspect}\n"
|
19
|
+
end
|
20
|
+
out
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](var)
|
24
|
+
@vars[var.to_sym]
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(var, value)
|
28
|
+
@vars[var.to_sym] = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(var)
|
32
|
+
@vars[var.to_sym] || "[#{var} is undefined]"
|
33
|
+
end
|
34
|
+
|
35
|
+
def set(var, value)
|
36
|
+
@vars[var.to_sym] = value.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def setvars(pairs)
|
40
|
+
pairs = pairs.to_a if pairs.is_a?(Hash)
|
41
|
+
pairs.each do |var, value|
|
42
|
+
api.setvar(var, value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_a
|
47
|
+
@vars.to_a
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/livetext/version.rb
CHANGED
data/lib/livetext.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require_relative 'livetext/
|
4
|
-
require_relative 'livetext/
|
2
|
+
if !defined?(Livetext)
|
3
|
+
require_relative 'livetext/skeleton'
|
4
|
+
require_relative 'livetext/version'
|
5
|
+
require_relative 'livetext/helpers'
|
6
|
+
require_relative 'livetext/variables'
|
7
|
+
require_relative 'livetext/core'
|
8
|
+
require_relative 'livetext/formatter'
|
9
|
+
require_relative 'livetext/paths'
|
5
10
|
|
6
|
-
require_relative 'livetext/reopen'
|
7
|
-
|
8
|
-
require_relative 'livetext/errors'
|
9
|
-
require_relative 'livetext/standard'
|
10
|
-
require_relative 'livetext/functions'
|
11
|
-
require_relative 'livetext/userapi'
|
12
|
-
require_relative 'livetext/formatter'
|
13
|
-
require_relative 'livetext/processor'
|
14
|
-
require_relative 'livetext/helpers'
|
15
|
-
require_relative 'livetext/more'
|
16
|
-
|
17
|
-
require_relative 'livetext/handler'
|
11
|
+
require_relative 'livetext/reopen'
|
18
12
|
|
13
|
+
require_relative 'livetext/errors'
|
14
|
+
require_relative 'livetext/standard'
|
15
|
+
require_relative 'livetext/functions'
|
16
|
+
require_relative 'livetext/userapi'
|
17
|
+
# require_relative 'livetext/formatter'
|
18
|
+
require_relative 'livetext/processor'
|
19
19
|
|
20
|
+
require_relative 'livetext/handler'
|
21
|
+
end
|
data/test/all.rb
CHANGED
data/test/extra/README.txt
CHANGED
@@ -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
|
9
|
-
|
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
|
13
|
-
|
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
data/test/unit/all.rb
CHANGED
data/test/unit/html.rb
CHANGED
@@ -12,7 +12,7 @@ class TestingLivetext < MiniTest::Test
|
|
12
12
|
|
13
13
|
def test_wrapped
|
14
14
|
live = Livetext.new
|
15
|
-
html = HTML.new(live.api)
|
15
|
+
html = Livetext::HTML.new(live.api)
|
16
16
|
str = "nothing much"
|
17
17
|
assert_equal html.tag(:b, cdata: str), "<b>#{str}</b>"
|
18
18
|
assert_equal html.tag(:b, :i, cdata: str), "<b><i>#{str}</i></b>"
|
@@ -23,7 +23,7 @@ class TestingLivetext < MiniTest::Test
|
|
23
23
|
|
24
24
|
def test_wrapped_extra
|
25
25
|
live = Livetext.new
|
26
|
-
html = HTML.new(live.api)
|
26
|
+
html = Livetext::HTML.new(live.api)
|
27
27
|
str = "nothing much"
|
28
28
|
assert_equal html.tag(:td, cdata: str, valign: :top),
|
29
29
|
"<td valign='top'>#{str}</td>"
|
@@ -7,7 +7,6 @@ require 'livetext'
|
|
7
7
|
# Just another testing class. Chill.
|
8
8
|
|
9
9
|
class TestingLivetextSingle < MiniTest::Test
|
10
|
-
|
11
10
|
def setup
|
12
11
|
@live = Livetext.new
|
13
12
|
end
|
@@ -131,11 +130,9 @@ class TestingLivetextSingle < MiniTest::Test
|
|
131
130
|
def test_single_013_escaped_marker_is_ignored
|
132
131
|
# Escaped marker is ignored
|
133
132
|
# No special initialization
|
134
|
-
src = "
|
133
|
+
src = '\\' + "*escaped" # Note single quote
|
135
134
|
exp = "*escaped"
|
136
135
|
actual = @live.api.format(src)
|
137
136
|
check_match(exp, actual)
|
138
137
|
end
|
139
|
-
|
140
|
-
|
141
138
|
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.
|
4
|
+
version: 0.9.48
|
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-
|
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,8 +26,8 @@ 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
|
30
|
+
- lib/livetext/core.rb
|
31
31
|
- lib/livetext/errors.rb
|
32
32
|
- lib/livetext/expansion.rb
|
33
33
|
- lib/livetext/formatter.rb
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- lib/livetext/handler/mixin.rb
|
39
39
|
- lib/livetext/helpers.rb
|
40
40
|
- lib/livetext/html.rb
|
41
|
-
- lib/livetext/more.rb
|
42
41
|
- lib/livetext/parser.rb
|
43
42
|
- lib/livetext/parser/general.rb
|
44
43
|
- lib/livetext/parser/set.rb
|
@@ -50,6 +49,7 @@ files:
|
|
50
49
|
- lib/livetext/skeleton.rb
|
51
50
|
- lib/livetext/standard.rb
|
52
51
|
- lib/livetext/userapi.rb
|
52
|
+
- lib/livetext/variables.rb
|
53
53
|
- lib/livetext/version.rb
|
54
54
|
- livetext.gemspec
|
55
55
|
- plugin/booktool.rb
|
@@ -61,16 +61,11 @@ files:
|
|
61
61
|
- plugin/tutorial.rb
|
62
62
|
- test/all.rb
|
63
63
|
- test/extra/README.txt
|
64
|
-
- test/extra/bracketed.rb
|
65
64
|
- test/extra/bracketed.txt
|
66
|
-
- test/extra/double.rb
|
67
65
|
- test/extra/double.txt
|
68
|
-
- test/extra/functions.rb
|
69
66
|
- test/extra/functions.txt
|
70
|
-
- test/extra/single.rb
|
71
67
|
- test/extra/single.txt
|
72
68
|
- test/extra/testgen.rb
|
73
|
-
- test/extra/variables.rb
|
74
69
|
- test/extra/variables.txt
|
75
70
|
- test/snapshots.rb
|
76
71
|
- test/snapshots/basic_formatting/expected-error.txt
|
@@ -186,11 +181,15 @@ files:
|
|
186
181
|
- test/snapshots/subset.txt
|
187
182
|
- test/snapshots/table_with_heredocs/expected-error.txt
|
188
183
|
- test/snapshots/table_with_heredocs/expected-output.txt
|
184
|
+
- test/snapshots/table_with_heredocs/old-exp-out.txt
|
189
185
|
- test/snapshots/table_with_heredocs/source.lt3
|
190
186
|
- test/snapshots/var_into_func/expected-error.txt
|
191
187
|
- test/snapshots/var_into_func/expected-output.txt
|
192
188
|
- test/snapshots/var_into_func/source.lt3
|
193
189
|
- test/unit/all.rb
|
190
|
+
- test/unit/bracketed.rb
|
191
|
+
- test/unit/double.rb
|
192
|
+
- test/unit/functions.rb
|
194
193
|
- test/unit/html.rb
|
195
194
|
- test/unit/parser.rb
|
196
195
|
- test/unit/parser/all.rb
|
@@ -198,8 +197,10 @@ files:
|
|
198
197
|
- test/unit/parser/mixin.rb
|
199
198
|
- test/unit/parser/set.rb
|
200
199
|
- test/unit/parser/string.rb
|
200
|
+
- test/unit/single.rb
|
201
201
|
- test/unit/standard.rb
|
202
202
|
- test/unit/stringparser.rb
|
203
|
+
- test/unit/variables.rb
|
203
204
|
homepage: https://github.com/Hal9000/livetext
|
204
205
|
licenses:
|
205
206
|
- Ruby
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|