livetext 0.9.25 → 0.9.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/imports/bookish.rb +1 -2
- data/lib/livetext/errors.rb +3 -0
- data/lib/livetext/formatline.rb +102 -15
- data/lib/livetext/funcall.rb +86 -2
- data/lib/livetext/global_helpers.rb +5 -0
- data/lib/livetext/handler/import.rb +2 -6
- data/lib/livetext/handler/mixin.rb +2 -6
- data/lib/livetext/helpers.rb +9 -11
- data/lib/livetext/lineparser.rb +441 -0
- data/lib/livetext/more.rb +158 -0
- data/lib/livetext/processor.rb +3 -1
- data/lib/livetext/skeleton.rb +5 -0
- data/lib/livetext/standard.rb +12 -8
- data/lib/livetext/userapi.rb +27 -10
- data/lib/livetext/version.rb +1 -1
- data/lib/livetext.rb +3 -152
- data/test/snapshots/basic_formatting/actual-error.txt +0 -0
- data/test/snapshots/basic_formatting/actual-output.txt +13 -0
- data/test/snapshots/basic_formatting/err-sdiff.txt +1 -0
- data/test/snapshots/basic_formatting/out-sdiff.txt +14 -0
- data/test/snapshots/error_invalid_name/foo +5 -0
- data/test/snapshots/import_bookish/expected-output.txt +4 -4
- data/test/snapshots/more_functions/actual-error.txt +0 -0
- data/test/snapshots/more_functions/actual-output.txt +37 -0
- data/test/snapshots/more_functions/err-sdiff.txt +1 -0
- data/test/snapshots/more_functions/expected-output.txt +1 -1
- data/test/snapshots/more_functions/out-sdiff.txt +38 -0
- data/test/snapshots/more_functions/source.lt3 +1 -1
- data/test/snapshots/simple_vars/actual-error.txt +0 -0
- data/test/snapshots/simple_vars/actual-output.txt +6 -0
- data/test/snapshots/simple_vars/err-sdiff.txt +1 -0
- data/test/snapshots/simple_vars/out-sdiff.txt +7 -0
- data/test/snapshots/subset.txt +2 -0
- data/test/snapshots/var_into_func/actual-error.txt +0 -0
- data/test/snapshots/var_into_func/actual-output.txt +16 -0
- data/test/snapshots/var_into_func/err-sdiff.txt +1 -0
- data/test/snapshots/var_into_func/expected-error.txt +0 -0
- data/test/snapshots/var_into_func/expected-output.txt +16 -0
- data/test/snapshots/var_into_func/out-sdiff.txt +17 -0
- data/test/snapshots/var_into_func/source.lt3 +16 -0
- data/test/unit/all.rb +3 -1
- data/test/unit/formatline.rb +143 -274
- data/test/unit/lineparser.rb +650 -0
- data/test/unit/parser/set.rb +13 -12
- data/test/unit/tokenizer.rb +534 -0
- metadata +26 -5
- data/test/snapshots/error_inc_line_num/OUT +0 -17
- data/test/snapshots/error_no_such_copy/duh +0 -26
- data/test/snapshots/error_no_such_copy/mystery.txt +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1744d4ccec6a1c997c1f37660276d9bbd13bc458b612e00ff90de5f0eab93261
|
4
|
+
data.tar.gz: 0ce2af2ed7e189f8128a94c93468f9044fdef6a044c4e551655ece97b6eaa3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 497f2e381f4ee255dc2b336fb6f287e136858e4d8daf96e6f652c321013d68e13139f41507e532bb1a57dd85b41afd6e8b5b6a35ce8f9cbb2b5b38eb7ccbde51
|
7
|
+
data.tar.gz: c5fcb435da4ee42395872a91f27ed5f2a1f67273f70b7e7bfdafe781b90a3170203bae9536ffd9dfb0e9af14e3cd0fde7a543c17e9aecdea1983fb4be8d74fd9
|
data/imports/bookish.rb
CHANGED
@@ -187,8 +187,7 @@ module Bookish
|
|
187
187
|
cells = line.split(delim)
|
188
188
|
api.out "<tr>"
|
189
189
|
cells.each.with_index do |cell, i|
|
190
|
-
api.out " <td width=#{maxw}% valign=top>"
|
191
|
-
"#{cell}</td>"
|
190
|
+
api.out " <td width=#{maxw[i]}% valign=top>#{cell}</td>"
|
192
191
|
end
|
193
192
|
api.out "</tr>"
|
194
193
|
end
|
data/lib/livetext/errors.rb
CHANGED
data/lib/livetext/formatline.rb
CHANGED
@@ -20,14 +20,21 @@ class Livetext::FormatLine < StringParser
|
|
20
20
|
|
21
21
|
def self.parse!(line)
|
22
22
|
return nil if line.nil?
|
23
|
-
|
23
|
+
line.chomp!
|
24
|
+
x = self.new(line)
|
25
|
+
::Livetext::TTY.puts "\n-- string: #{line.inspect}" if $testme
|
24
26
|
t = x.tokenize
|
25
|
-
|
27
|
+
::Livetext::TTY.puts "\n-- Tokens: #{t.inspect}" if $testme
|
28
|
+
result = x.evaluate
|
29
|
+
::Livetext::TTY.puts "\n-- result: #{result.inspect}\n " if $testme
|
30
|
+
result
|
26
31
|
end
|
27
32
|
|
28
33
|
def tokenize
|
29
34
|
loop do
|
30
|
-
|
35
|
+
ch = peek
|
36
|
+
::Livetext::TTY.puts "\n-- #{__method__}: ch1 = #{ch.inspect}\n " if $testme
|
37
|
+
case ch
|
31
38
|
when Escape; grab; add peek; grab
|
32
39
|
when "$"
|
33
40
|
dollar
|
@@ -41,6 +48,64 @@ class Livetext::FormatLine < StringParser
|
|
41
48
|
else
|
42
49
|
add peek
|
43
50
|
end
|
51
|
+
ch = grab
|
52
|
+
# add ch
|
53
|
+
::Livetext::TTY.puts "\n-- #{__method__}: !!! ch2 = #{ch.inspect}\n " if $testme
|
54
|
+
end
|
55
|
+
add_token(:str)
|
56
|
+
@tokenlist
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_formatting
|
60
|
+
loop do
|
61
|
+
case peek
|
62
|
+
when Escape; grab; add peek; grab
|
63
|
+
when "*", "_", "`", "~"
|
64
|
+
marker peek
|
65
|
+
add peek
|
66
|
+
when LF
|
67
|
+
break if eos?
|
68
|
+
when nil
|
69
|
+
break
|
70
|
+
else
|
71
|
+
add peek
|
72
|
+
end
|
73
|
+
grab
|
74
|
+
end
|
75
|
+
add_token(:str)
|
76
|
+
@tokenlist
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.get_vars
|
80
|
+
grab
|
81
|
+
case peek
|
82
|
+
when LF, " ", nil
|
83
|
+
add "$"
|
84
|
+
add_token :str
|
85
|
+
when "$"; double_dollar
|
86
|
+
# when "."; dollar_dot
|
87
|
+
when /[A-Za-z]/
|
88
|
+
add_token :str
|
89
|
+
var = peek + grab_alpha_dot
|
90
|
+
add_token(:var, var)
|
91
|
+
else
|
92
|
+
add "$" + peek
|
93
|
+
add_token(:str)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.parse_var_func # FIXME Hmm...
|
98
|
+
loop do
|
99
|
+
case peek
|
100
|
+
when "$"
|
101
|
+
dollar
|
102
|
+
when LF
|
103
|
+
break if eos?
|
104
|
+
when nil
|
105
|
+
break
|
106
|
+
else
|
107
|
+
add peek
|
108
|
+
end
|
44
109
|
grab
|
45
110
|
end
|
46
111
|
add_token(:str)
|
@@ -60,7 +125,7 @@ class Livetext::FormatLine < StringParser
|
|
60
125
|
loop do
|
61
126
|
char = self.grab
|
62
127
|
break if char == LF || char == nil
|
63
|
-
self.
|
128
|
+
self.escaped if char == Escape
|
64
129
|
self.dollar if char == "$" # Could be $$
|
65
130
|
self.add char
|
66
131
|
end
|
@@ -76,7 +141,7 @@ class Livetext::FormatLine < StringParser
|
|
76
141
|
loop do
|
77
142
|
char = x.grab
|
78
143
|
break if char == LF || char == nil
|
79
|
-
x.
|
144
|
+
x.escaped if char == Escape
|
80
145
|
x.dollar if char == "$" # Could be $$
|
81
146
|
x.add char
|
82
147
|
end
|
@@ -85,9 +150,20 @@ class Livetext::FormatLine < StringParser
|
|
85
150
|
result
|
86
151
|
end
|
87
152
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
153
|
+
def self.parse_variables(str)
|
154
|
+
return nil if str.nil?
|
155
|
+
x = self.new(str.chomp)
|
156
|
+
char = x.peek
|
157
|
+
loop do
|
158
|
+
char = x.grab
|
159
|
+
break if char == LF || char == nil
|
160
|
+
x.escaped if char == Escape
|
161
|
+
x.dollar if char == "$" # Could be $$
|
162
|
+
x.add char
|
163
|
+
end
|
164
|
+
x.add_token(:str)
|
165
|
+
result = x.evaluate
|
166
|
+
result
|
91
167
|
end
|
92
168
|
|
93
169
|
def embed(sym, str)
|
@@ -151,20 +227,31 @@ class Livetext::FormatLine < StringParser
|
|
151
227
|
end
|
152
228
|
|
153
229
|
def dollar
|
154
|
-
grab
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
230
|
+
ch = grab # "$"
|
231
|
+
::Livetext::TTY.puts "\n-- #{__method__}: ch1 = #{ch.inspect}\n self = #{self.inspect}" if $testme
|
232
|
+
ch = peek
|
233
|
+
::Livetext::TTY.puts "\n-- #{__method__}: ch2 = #{ch.inspect}\n self = #{self.inspect}" if $testme
|
234
|
+
case ch
|
235
|
+
when " "
|
236
|
+
::Livetext::TTY.puts "\n-- #{__method__}: (space)" if $testme
|
237
|
+
add "$ "
|
238
|
+
add_token :str
|
239
|
+
when LF, nil
|
240
|
+
::Livetext::TTY.puts "\n-- #{__method__}: (LF/nil)" if $testme
|
241
|
+
add "$"
|
242
|
+
add_token :str
|
159
243
|
when "$"; double_dollar
|
160
244
|
# when "."; dollar_dot
|
161
245
|
when /[A-Za-z]/
|
246
|
+
::Livetext::TTY.puts "\n-- #{__method__}: (Alpha)" if $testme
|
162
247
|
add_token :str
|
163
248
|
var = peek + grab_alpha_dot
|
164
249
|
add_token(:var, var)
|
165
250
|
else
|
166
|
-
|
167
|
-
|
251
|
+
ch = grab # "$"
|
252
|
+
::Livetext::TTY.puts "\n-- ch3 = #{ch.inspect}\n self = #{self.inspect}" if $testme
|
253
|
+
add "$" + ch
|
254
|
+
add_token(:str)
|
168
255
|
end
|
169
256
|
end
|
170
257
|
|
data/lib/livetext/funcall.rb
CHANGED
@@ -3,6 +3,90 @@ require_relative '../livetext'
|
|
3
3
|
|
4
4
|
# Parse function calls
|
5
5
|
|
6
|
+
module Livetext::LineParser::FunCall
|
7
|
+
|
8
|
+
include Livetext::ParsingConstants
|
9
|
+
|
10
|
+
def param_loop(char)
|
11
|
+
param = ""
|
12
|
+
loop do
|
13
|
+
case peek
|
14
|
+
when Escape
|
15
|
+
param << escaped
|
16
|
+
when char, LF, nil
|
17
|
+
break
|
18
|
+
else
|
19
|
+
param << grab
|
20
|
+
end
|
21
|
+
end
|
22
|
+
param = nil if param.empty?
|
23
|
+
param
|
24
|
+
end
|
25
|
+
|
26
|
+
def grab_colon_param
|
27
|
+
grab # grab :
|
28
|
+
param = param_loop(Space)
|
29
|
+
end
|
30
|
+
|
31
|
+
def grab_bracket_param
|
32
|
+
grab # [
|
33
|
+
param = param_loop("]")
|
34
|
+
grab # "]"
|
35
|
+
param
|
36
|
+
end
|
37
|
+
|
38
|
+
def funcall(name, param)
|
39
|
+
err = "[Error evaluating $$#{name}(#{param})]"
|
40
|
+
result =
|
41
|
+
if self.send?(name, param)
|
42
|
+
# do nothing
|
43
|
+
else
|
44
|
+
fobj = ::Livetext::Functions.new
|
45
|
+
fobj.send(name, param) rescue err
|
46
|
+
end
|
47
|
+
result.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def grab_func_with_param
|
51
|
+
add_token(:str, @token)
|
52
|
+
func = grab_alpha
|
53
|
+
add_token(:func, func)
|
54
|
+
param = grab_func_param # may be null/missing
|
55
|
+
param
|
56
|
+
end
|
57
|
+
|
58
|
+
def double_dollar
|
59
|
+
case peek
|
60
|
+
when Space; add_token :string, "$$ "; grab
|
61
|
+
when LF, nil; add "$$ "; add_token :str
|
62
|
+
when Alpha; param = grab_func_with_param
|
63
|
+
else grab; add_token :str, "$$" + peek
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def grab_func_param
|
68
|
+
case peek
|
69
|
+
when "["
|
70
|
+
param = grab_bracket_param
|
71
|
+
add_token(:brackets, param)
|
72
|
+
when ":"
|
73
|
+
param = grab_colon_param
|
74
|
+
add_token(:colon, param)
|
75
|
+
else # do nothing
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def escaped
|
80
|
+
grab # Eat the backslash
|
81
|
+
ch = grab # Take next char
|
82
|
+
ch
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# FIXME...
|
89
|
+
|
6
90
|
module Livetext::FormatLine::FunCall
|
7
91
|
|
8
92
|
include Livetext::ParsingConstants
|
@@ -10,13 +94,13 @@ module Livetext::FormatLine::FunCall
|
|
10
94
|
def param_loop(char)
|
11
95
|
param = ""
|
12
96
|
loop do
|
13
|
-
case
|
97
|
+
case peek
|
14
98
|
when Escape
|
15
99
|
param << escaped
|
16
100
|
when char, LF, nil
|
17
101
|
break
|
18
102
|
else
|
19
|
-
param <<
|
103
|
+
param << peek
|
20
104
|
grab
|
21
105
|
end
|
22
106
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
module GlobalHelpers
|
3
3
|
|
4
4
|
def check_disallowed(name)
|
5
|
+
api.tty "GLOBAL cdis"
|
5
6
|
raise DisallowedName(name) if disallowed?(name)
|
6
7
|
end
|
7
8
|
|
@@ -34,4 +35,8 @@ module GlobalHelpers
|
|
34
35
|
return nil
|
35
36
|
end
|
36
37
|
|
38
|
+
def cwd_root?
|
39
|
+
File.dirname(File.expand_path(".")) == "/"
|
40
|
+
end
|
41
|
+
|
37
42
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
require_relative '../helpers'
|
3
3
|
|
4
|
+
# Handle a .import
|
5
|
+
|
4
6
|
class Livetext::Handler::Import
|
5
7
|
include Livetext::Helpers
|
6
8
|
include GlobalHelpers
|
@@ -34,11 +36,5 @@ class Livetext::Handler::Import
|
|
34
36
|
newmod # return actual module
|
35
37
|
end
|
36
38
|
|
37
|
-
private
|
38
|
-
|
39
|
-
def cwd_root?
|
40
|
-
File.dirname(File.expand_path(".")) == "/"
|
41
|
-
end
|
42
|
-
|
43
39
|
end
|
44
40
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
require_relative '../helpers'
|
3
3
|
|
4
|
+
# Handle a .mixin
|
5
|
+
|
4
6
|
class Livetext::Handler::Mixin
|
5
7
|
include Livetext::Helpers
|
6
8
|
include GlobalHelpers
|
@@ -27,11 +29,5 @@ class Livetext::Handler::Mixin
|
|
27
29
|
[modname, "module ::#{modname}; #{meths}\nend"]
|
28
30
|
end
|
29
31
|
|
30
|
-
private
|
31
|
-
|
32
|
-
def cwd_root?
|
33
|
-
File.dirname(File.expand_path(".")) == "/"
|
34
|
-
end
|
35
|
-
|
36
32
|
end
|
37
33
|
|
data/lib/livetext/helpers.rb
CHANGED
@@ -55,8 +55,10 @@ module Livetext::Helpers
|
|
55
55
|
base = "#{name}#{ext}"
|
56
56
|
paths.each do |path|
|
57
57
|
file = path + base
|
58
|
+
::Livetext::TTY.puts " Checking: #{file}"
|
58
59
|
return file if File.exist?(file)
|
59
60
|
end
|
61
|
+
::Livetext::TTY.puts " ...oops"
|
60
62
|
return nil
|
61
63
|
end
|
62
64
|
|
@@ -92,12 +94,12 @@ module Livetext::Helpers
|
|
92
94
|
def process_line(line)
|
93
95
|
success = true
|
94
96
|
case line # must apply these in order
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
when Comment
|
98
|
+
success = handle_scomment(line)
|
99
|
+
when DotCmd
|
100
|
+
success = handle_dotcmd(line)
|
101
|
+
when DollarDot
|
102
|
+
success = handle_dollar_dot
|
101
103
|
else
|
102
104
|
api.passthru(line) # must succeed?
|
103
105
|
end
|
@@ -117,14 +119,11 @@ module Livetext::Helpers
|
|
117
119
|
# FIXME Add cmdargs stuff... depends on name, etc.
|
118
120
|
retval = @main.send(name)
|
119
121
|
retval
|
120
|
-
# rescue NoMethodError => err
|
121
|
-
# graceful_error(err)
|
122
122
|
rescue => err
|
123
123
|
graceful_error(err)
|
124
124
|
end
|
125
125
|
|
126
126
|
def handle_dotcmd(line, indent = 0)
|
127
|
-
# TTY.puts ">>> #{__method__} in #{__FILE__}" # if ENV['debug']
|
128
127
|
indent = @indentation.last # top of stack
|
129
128
|
line = line.sub(/# .*$/, "") # FIXME Could be problematic?
|
130
129
|
name = get_name(line)
|
@@ -159,8 +158,7 @@ module Livetext::Helpers
|
|
159
158
|
end
|
160
159
|
|
161
160
|
def check_file_exists(file)
|
162
|
-
|
163
|
-
return File.exist?(file)
|
161
|
+
return File.exist?(file)
|
164
162
|
end
|
165
163
|
|
166
164
|
def set_variables(pairs)
|