livetext 0.8.80 → 0.8.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/formatline.rb +30 -1
- data/lib/livetext.rb +1 -1
- data/lib/processor.rb +3 -1
- data/lib/standard.rb +18 -8
- data/lib/userapi.rb +19 -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: ef8d4d20d509f85b02f3bec9fd06a3e9d6f54968b634b386bea7baa1c84eeb47
|
4
|
+
data.tar.gz: 926e1b7cf4f8e0aa1b9ee13bea39a31d59a79a606bcd13d5dcb3135d02a23c6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b95158a230fba31c2d0226e8bec2d778ae9a569c9cb9fd0af97b6b5788dcb6618adcf52777d383d1a4cab1d140dafe5f3a257693c48fe6c51ca9050a7d9cd3
|
7
|
+
data.tar.gz: 9d27ab12a8166ca694fd9248a3c7e37b62dec3642a00090f3ae71718785bb4f1ab74f1113afc9c89aaf44cade6c7084a63abce9f2bded440b5723cd33d958e78
|
data/lib/formatline.rb
CHANGED
@@ -27,6 +27,7 @@ class FormatLine
|
|
27
27
|
end
|
28
28
|
|
29
29
|
attr_reader :out
|
30
|
+
attr_reader :tokenlist
|
30
31
|
|
31
32
|
def initialize(line, context=nil)
|
32
33
|
context ||= binding
|
@@ -54,7 +55,10 @@ class FormatLine
|
|
54
55
|
when "*", "_", "`", "~"
|
55
56
|
marker curr
|
56
57
|
add curr
|
57
|
-
|
58
|
+
# grab
|
59
|
+
when LF
|
60
|
+
break if @i >= line.size - 1
|
61
|
+
when nil
|
58
62
|
break
|
59
63
|
else
|
60
64
|
add curr
|
@@ -65,6 +69,29 @@ class FormatLine
|
|
65
69
|
@tokenlist
|
66
70
|
end
|
67
71
|
|
72
|
+
def self.var_func_parse(str, context = nil)
|
73
|
+
return nil if str.nil?
|
74
|
+
x = self.new(str.chomp, context)
|
75
|
+
# t = x.tokenize(line)
|
76
|
+
x.grab
|
77
|
+
loop do
|
78
|
+
case x.curr
|
79
|
+
when Escape; x.go; x.add x.curr; x.grab
|
80
|
+
when "$"
|
81
|
+
x.dollar
|
82
|
+
when LF, nil
|
83
|
+
break
|
84
|
+
else
|
85
|
+
x.add x.curr
|
86
|
+
end
|
87
|
+
x.grab
|
88
|
+
end
|
89
|
+
x.add_token(:str)
|
90
|
+
# built tokenlist
|
91
|
+
# x.tokenlist.each {|pair| puts " #{pair.inspect}" }
|
92
|
+
x.evaluate # (context)
|
93
|
+
end
|
94
|
+
|
68
95
|
def embed(sym, str)
|
69
96
|
pre, post = SimpleFormats[sym]
|
70
97
|
pre + str + post
|
@@ -89,9 +116,11 @@ class FormatLine
|
|
89
116
|
if [:colon, :brackets].include? arg[0]
|
90
117
|
arg = gen.next # for real
|
91
118
|
param = arg[1]
|
119
|
+
param = FormatLine.var_func_parse(param)
|
92
120
|
end
|
93
121
|
@out << funcall(val, param)
|
94
122
|
when :b, :i, :t, :s
|
123
|
+
val = FormatLine.var_func_parse(val)
|
95
124
|
@out << embed(sym, val)
|
96
125
|
else
|
97
126
|
add_token :str
|
data/lib/livetext.rb
CHANGED
data/lib/processor.rb
CHANGED
data/lib/standard.rb
CHANGED
@@ -67,9 +67,9 @@ module Livetext::Standard
|
|
67
67
|
def banner
|
68
68
|
str = _format(@_data)
|
69
69
|
n = str.length - 1
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
puts "-"*n
|
71
|
+
puts str
|
72
|
+
puts "-"*n
|
73
73
|
end
|
74
74
|
|
75
75
|
def quit
|
@@ -143,7 +143,7 @@ module Livetext::Standard
|
|
143
143
|
str = "def #{name}\n"
|
144
144
|
raise "Illegal name '#{name}'" if _disallowed?(name)
|
145
145
|
str += _body_text(true)
|
146
|
-
str += "
|
146
|
+
str += "\nend\n"
|
147
147
|
eval str
|
148
148
|
rescue => err
|
149
149
|
_error!(err)
|
@@ -153,10 +153,14 @@ module Livetext::Standard
|
|
153
153
|
def set
|
154
154
|
assigns = @_data.chomp.split(/, */)
|
155
155
|
# Do a better way?
|
156
|
+
# FIXME *Must* allow for vars/functions
|
156
157
|
assigns.each do |a|
|
157
158
|
var, val = a.split("=")
|
158
|
-
|
159
|
-
val
|
159
|
+
var.strip!
|
160
|
+
val.strip!
|
161
|
+
val = val[1..-2] if val[0] == ?" && val[-1] == ?"
|
162
|
+
val = val[1..-2] if val[0] == ?' && val[-1] == ?'
|
163
|
+
val = FormatLine.var_func_parse(val)
|
160
164
|
Livetext::Vars[var.to_sym] = val
|
161
165
|
Livetext::Vars[var] = val # FIXME
|
162
166
|
end
|
@@ -166,6 +170,10 @@ module Livetext::Standard
|
|
166
170
|
def heredoc
|
167
171
|
var = @_args[0]
|
168
172
|
str = _body_text
|
173
|
+
s2 = ""
|
174
|
+
str.each_line do |s|
|
175
|
+
s2 << s.chomp + "<br>"
|
176
|
+
end
|
169
177
|
indent = @parent.indentation.last
|
170
178
|
indented = " " * indent
|
171
179
|
# s2 = ""
|
@@ -178,9 +186,8 @@ module Livetext::Standard
|
|
178
186
|
# end
|
179
187
|
# s2 << line
|
180
188
|
# end
|
181
|
-
s2 = str
|
182
189
|
Livetext::Vars[var.to_sym] = s2
|
183
|
-
Livetext::Vars[var] = s2
|
190
|
+
Livetext::Vars[var] = s2.chomp # FIXME?
|
184
191
|
_optional_blank_line
|
185
192
|
end
|
186
193
|
|
@@ -211,6 +218,9 @@ module Livetext::Standard
|
|
211
218
|
meths = grab_file(file)
|
212
219
|
modname = name.gsub("/","_").capitalize
|
213
220
|
string = "module ::#{modname}\n#{meths}\nend"
|
221
|
+
# puts "==========="
|
222
|
+
# string.each_line.with_index {|line, i| puts "#{'%3d' % (i+1)} : #{line}" }
|
223
|
+
# puts "==========="
|
214
224
|
eval(string)
|
215
225
|
newmod = Object.const_get("::" + modname)
|
216
226
|
self.extend(newmod)
|
data/lib/userapi.rb
CHANGED
@@ -21,7 +21,9 @@ module Livetext::UserAPI
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def _optional_blank_line
|
24
|
-
|
24
|
+
peek = peek_nextline
|
25
|
+
return if peek.nil?
|
26
|
+
@line = nextline if peek =~ /^ *$/
|
25
27
|
end
|
26
28
|
|
27
29
|
def _comment?(str)
|
@@ -38,8 +40,10 @@ module Livetext::UserAPI
|
|
38
40
|
|
39
41
|
def _end?(str)
|
40
42
|
indent = ""
|
41
|
-
|
42
|
-
|
43
|
+
# n = @parent.indentation.last - 1
|
44
|
+
# n = 0 if n < 0 # Gahhh FIXM
|
45
|
+
# indent = " " * n
|
46
|
+
# indent << "$" unless indent.empty?
|
43
47
|
return false if str.nil?
|
44
48
|
cmd = indent + Livetext::Sigil + "end"
|
45
49
|
return false if str.index(cmd) != 0
|
@@ -67,15 +71,22 @@ module Livetext::UserAPI
|
|
67
71
|
def _body(raw=false)
|
68
72
|
lines = []
|
69
73
|
@save_location = @sources.last
|
74
|
+
end_found = false
|
70
75
|
loop do
|
71
76
|
@line = nextline
|
72
|
-
|
73
|
-
break if
|
77
|
+
# puts "--- loop: @line = #{@line.inspect}"
|
78
|
+
break if @line.nil?
|
79
|
+
@line.chomp!
|
80
|
+
if _end?(@line)
|
81
|
+
end_found = true
|
82
|
+
break
|
83
|
+
end
|
74
84
|
next if _comment?(@line)
|
75
85
|
# FIXME Will cause problem with $. ?
|
76
86
|
@line = _format(@line) unless raw
|
77
87
|
lines << @line
|
78
88
|
end
|
89
|
+
raise unless end_found
|
79
90
|
_optional_blank_line
|
80
91
|
if block_given?
|
81
92
|
lines.each {|line| yield line } # FIXME what about $. ?
|
@@ -83,13 +94,13 @@ module Livetext::UserAPI
|
|
83
94
|
lines
|
84
95
|
end
|
85
96
|
rescue => err
|
86
|
-
|
87
|
-
|
97
|
+
# p err.inspect
|
98
|
+
# puts err.backtrace
|
88
99
|
_error!("Expecting .end, found end of file")
|
89
100
|
end
|
90
101
|
|
91
102
|
def _body_text(raw=false)
|
92
|
-
_body(Livetext::Sigil).join("")
|
103
|
+
_body(Livetext::Sigil).join("\n")
|
93
104
|
end
|
94
105
|
|
95
106
|
def _raw_body!
|
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.81
|
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-
|
11
|
+
date: 2019-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A smart text processor extensible in Ruby
|
14
14
|
email: rubyhacker@gmail.com
|