livetext 0.9.21 → 0.9.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/imports/bookish.rb +8 -10
  3. data/imports/pyggish.rb +2 -34
  4. data/imports/tutorial.rb +2 -2
  5. data/lib/cmdargs.rb +2 -3
  6. data/lib/formatline.rb +101 -73
  7. data/lib/functions.rb +16 -1
  8. data/lib/handler/{icanhaz.rb → import.rb} +1 -1
  9. data/lib/handler.rb +1 -1
  10. data/lib/helpers.rb +10 -10
  11. data/lib/livetext.rb +12 -5
  12. data/lib/parser/set.rb +1 -3
  13. data/lib/parser/string.rb +2 -2
  14. data/lib/processor.rb +6 -2
  15. data/lib/standard.rb +15 -15
  16. data/lib/userapi.rb +4 -2
  17. data/plugin/bookish.rb +4 -5
  18. data/plugin/pyggish.rb +45 -77
  19. data/plugin/tutorial.rb +0 -1
  20. data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
  21. data/test/snapshots/error_inc_line_num/actual-output.txt +7 -0
  22. data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
  23. data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
  24. data/test/snapshots/{icanhaz2/expected-error.txt → error_invalid_name/actual-output.txt} +0 -0
  25. data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
  26. data/test/snapshots/error_missing_end/actual-error.txt +10 -0
  27. data/test/snapshots/error_missing_end/actual-output.txt +0 -0
  28. data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
  29. data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
  30. data/test/snapshots/error_no_such_copy/actual-output.txt +0 -0
  31. data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
  32. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  33. data/test/snapshots/error_no_such_mixin/actual-error.txt +13 -0
  34. data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
  35. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
  36. data/test/snapshots/import/actual-error.txt +13 -0
  37. data/test/snapshots/import/actual-output.txt +0 -0
  38. data/test/snapshots/{icanhaz → import}/expected-output.txt +0 -0
  39. data/test/snapshots/{icanhaz → import}/match-error.txt +0 -0
  40. data/test/snapshots/import/out-sdiff.txt +6 -0
  41. data/test/snapshots/{icanhaz → import}/simple_import.rb +0 -0
  42. data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
  43. data/test/snapshots/import2/expected-error.txt +0 -0
  44. data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
  45. data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +0 -0
  46. data/test/snapshots/import2/source.lt3 +8 -0
  47. data/test/snapshots/more_functions/expected-error.txt +0 -0
  48. data/test/snapshots/more_functions/expected-output.txt +37 -0
  49. data/test/snapshots/more_functions/source.lt3 +40 -0
  50. data/test/snapshots/simple_import/expected-output.txt +2 -0
  51. data/test/snapshots/simple_import/source.lt3 +3 -1
  52. data/test/snapshots/subset.txt +11 -12
  53. data/test/snapshots/wtf_bookish/expected-error.txt +0 -0
  54. data/test/snapshots/wtf_bookish/expected-output.txt +10 -0
  55. data/test/snapshots/wtf_bookish/source.lt3 +7 -0
  56. data/test/snapshots/wtf_bookish/toc.tmp +0 -0
  57. data/test/snapshots.rb +6 -7
  58. data/test/unit/formatline.rb +252 -135
  59. data/test/unit/parser/set.rb +6 -10
  60. data/test/unit/parser/string.rb +5 -5
  61. data/test/unit/standard.rb +0 -1
  62. metadata +37 -13
  63. data/lib/livetext/importable.rb +0 -2
  64. data/lib/parser/import.rb +0 -15
  65. data/test/snapshots/icanhaz2/source.lt3 +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90efd2fa7302e61cfe5ed140c8f954afd2b7c699ec705d8ff0c1d36bd6641fa4
4
- data.tar.gz: b551f8a5dc4eda7435fe73b4680604c8468a59417286c01194672d319bdaf411
3
+ metadata.gz: 3d2ff056cfc390401ec0517a7a74bb0eadf9128fff5eaff5c60a548775bdde9f
4
+ data.tar.gz: c76d7b425e3c19b0c44c752ff5705757415f60ee1d2647b538cfb9e6eb263ec3
5
5
  SHA512:
6
- metadata.gz: 213f8d126a548e54a34ce1c4f551d9f4ab208df618bb4e1d069ee5c6f430d03daeef6054c71e205dc1431b1bea6c6bb05d9362985c8be280ed982781b139b047
7
- data.tar.gz: ef50d633131bf82ac06c7807ea53edbc11ba032e0ea3db7eade09afed2e5e954656515872ead7fb38a798c7079fb0d73e742a18b4b258d29baab13de6b8e28d5
6
+ metadata.gz: bc98e86fdc72cbe0441ad2b80cbff64d3afbf4cae68eaba12e6e84ba5dd51913e6cdc9c687678782db61f64796347a2cf5d149e2eb74c4ed436634efa0c8b9fb
7
+ data.tar.gz: e6359fd712953b1579bb36d56b5dfd9546963064e4a5f08165ccf4a61dcc1de0a52374a15d7f038e63fe9ff00f25a5d3c0febdac501fea067399bf3c682075eb
data/imports/bookish.rb CHANGED
@@ -33,10 +33,6 @@ module Bookish
33
33
  _out "</table>"
34
34
  end
35
35
 
36
- # def comment
37
- # _body { } # ignore body
38
- # end
39
-
40
36
  def _errout(*args)
41
37
  ::STDERR.puts *args
42
38
  end
@@ -46,13 +42,15 @@ module Bookish
46
42
  end
47
43
 
48
44
  def _slug(str)
49
- s2 = str.chomp.strip.gsub(/[?:,()'"\/]/,"").gsub(/ /, "-").downcase
50
- # _errout "SLUG: #{str} => #{s2}"
51
- s2
45
+ str2 = str.chomp.strip
46
+ str2 = str2.gsub(/[?:,()'"\/]/,"")
47
+ str2 = str2.gsub(/ /, "-")
48
+ str2.downcase!
49
+ str2
52
50
  end
53
51
 
54
-
55
52
  # FIXME duplicated?
53
+
56
54
  def image(args = nil, body = nil)
57
55
  name = @_args[0]
58
56
  _out "<img src='#{name}'></img>"
@@ -109,7 +107,7 @@ module Bookish
109
107
  next_output
110
108
  _out "<h3>#@section #{title}</h3>\n"
111
109
  rescue => err
112
- STDERR.puts "#{err}\n#{err.backtrace}"
110
+ ::STDERR.puts "#{err}\n#{err.backtrace}"
113
111
  exit
114
112
  end
115
113
 
@@ -276,7 +274,7 @@ module Bookish
276
274
  _body {|line| _out line }
277
275
  _out "</blockquote>"
278
276
  rescue => err
279
- STDERR.puts "#{err}\n#{err.backtrace}"
277
+ ::STDERR.puts "#{err}\n#{err.backtrace}"
280
278
  exit
281
279
  end
282
280
 
data/imports/pyggish.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rouge'
2
2
 
3
+ # FIXME This file has suboptimal juju. See plugin/pyggish.rb also
4
+
3
5
  module Pyggish
4
6
  def self.pyg_change(code, klass, style)
5
7
  color = style[0..6]
@@ -29,7 +31,6 @@ module Pyggish
29
31
 
30
32
  def self.pyg_finalize(code, lexer=:elixir)
31
33
  Styles.each_pair {|klass, style| pyg_change(code, klass, style) }
32
- File.open("debug-pf1", "w") {|f| f.puts code }
33
34
  code.sub!(/<pre>/, "<pre>\n")
34
35
  code.gsub!(/<span class="[np]">/, "")
35
36
  code.gsub!(/<\/span>/, "")
@@ -37,9 +38,7 @@ File.open("debug-pf1", "w") {|f| f.puts code }
37
38
  code.sub!(/<td class="linenos"/, "<td width=2%></td><td width=5% bgcolor=#{color}")
38
39
  code.gsub!(/<td/, "<td valign=top ")
39
40
  code.gsub!(/ class="[^"]*?"/, "") # Get rid of remaining Pygments CSS
40
- File.open("debug-pf2", "w") {|f| f.puts code }
41
41
  lines = code.split("\n")
42
- # lines.each {|line| line << "\n" }
43
42
  n1 = lines.index {|x| x =~ /<pre>/ }
44
43
  n2 = lines.index {|x| x =~ /<\/pre>/ }
45
44
  # FIXME ?
@@ -48,12 +47,10 @@ File.open("debug-pf2", "w") {|f| f.puts code }
48
47
  lines[n1].sub!(/ 1$/, " 1 ")
49
48
  (n1+1).upto(n2) {|n| lines[n].replace(" " + lines[n] + " ") }
50
49
  code = lines.join("\n")
51
- File.open("debug-pf3", "w") {|f| f.puts code }
52
50
  code
53
51
  end
54
52
 
55
53
  def _process_code(text)
56
- File.open("debug-pc1", "w") {|f| f.puts text }
57
54
  lines = text.split("\n")
58
55
  lines = lines.select {|x| x !~ /##~ omit/ }
59
56
  @refs = {}
@@ -66,7 +63,6 @@ File.open("debug-pf3", "w") {|f| f.puts code }
66
63
  end
67
64
  lines.map! {|line| " " + line }
68
65
  text2 = lines.join("\n")
69
- File.open("debug-pc2", "w") {|f| f.puts text2 }
70
66
  text.replace(text2)
71
67
  end
72
68
 
@@ -86,34 +82,6 @@ File.open("debug-pf3", "w") {|f| f.puts code }
86
82
  result
87
83
  end
88
84
 
89
- def OLD_ruby
90
- file = @_args.first
91
- if file.nil?
92
- code = "# Ruby code\n"
93
- _body {|line| code << line + "\n" }
94
- else
95
- code = "# Ruby code\n\n" + ::File.read(file)
96
- end
97
-
98
- _process_code(code)
99
- html = _colorize(code, :ruby)
100
- _out "\n#{html}\n "
101
- end
102
-
103
- def OLD_elixir
104
- file = @_args.first
105
- if file.nil?
106
- code = ""
107
- _body {|line| code << line + "\n" }
108
- else
109
- code = ::File.read(file)
110
- end
111
-
112
- _process_code(code)
113
- html = _colorize(code, :elixir)
114
- _out "\n#{html}\n "
115
- end
116
-
117
85
  def fragment
118
86
  lang = @_args.empty? ? :elixir : @_args.first.to_sym # ruby or elixir
119
87
  @_args = []
data/imports/tutorial.rb CHANGED
@@ -1,7 +1,7 @@
1
- # require 'cgi'
2
-
3
1
  require 'helpers'
4
2
 
3
+ # Created as an "ad hoc" lib for generating the README
4
+
5
5
  module Tutorial
6
6
  include Helpers
7
7
 
data/lib/cmdargs.rb CHANGED
@@ -65,14 +65,13 @@ class Livetext::CmdData
65
65
  # body: true => this command has a body + .end
66
66
  # how raw is raw?
67
67
  # remove comment - always/sometimes/never?
68
- # var_func_parse - always/sometimes/never?
69
- # var_func_parse inside body??
68
+ # interpolate - always/sometimes/never?
69
+ # interpolate inside body??
70
70
  @data = data.dup # comment? vars? funcs?
71
71
  @raw = data.dup # comment? vars? funcs?
72
72
  @args = data.split # simple array
73
73
  @nargs = nargs # not really "needed"
74
74
  check_num_args(nargs)
75
-
76
75
  # @varfunc = Livetext.interpolate(data.dup)
77
76
  end
78
77
 
data/lib/formatline.rb CHANGED
@@ -7,6 +7,8 @@ class FormatLine < StringParser
7
7
  SimpleFormats[:i] = %w[<i> </i>]
8
8
  SimpleFormats[:t] = ["<font size=+1><tt>", "</tt></font>"]
9
9
  SimpleFormats[:s] = %w[<strike> </strike>]
10
+
11
+ BITS = SimpleFormats.keys
10
12
 
11
13
  Null = ""
12
14
  Space = " "
@@ -45,7 +47,7 @@ class FormatLine < StringParser
45
47
  # add grab
46
48
  loop do
47
49
  case peek
48
- when Escape; grab; add peek; grab; add peek
50
+ when Escape; grab; add peek; grab; # add peek # <-- last is an error??
49
51
  when "$"
50
52
  dollar
51
53
  when "*", "_", "`", "~"
@@ -107,22 +109,10 @@ class FormatLine < StringParser
107
109
  break if token.nil?
108
110
  sym, val = *token
109
111
  case sym
110
- when :str
111
- @out << val unless val == "\n" # BUG
112
- when :var
113
- @out << varsub(val)
114
- when :func
115
- param = nil
116
- arg = gen.peek
117
- if [:colon, :brackets].include? arg[0]
118
- arg = gen.next # for real
119
- param = arg[1]
120
- param = Livetext.interpolate(param)
121
- end
122
- @out << funcall(val, param)
123
- when :b, :i, :t, :s
124
- val = Livetext.interpolate(val)
125
- @out << embed(sym, val)
112
+ when :str; eval_str(val)
113
+ when :var; eval_var(val)
114
+ when :func; eval_func(val, gen)
115
+ when *BITS; eval_bits(sym, val)
126
116
  else
127
117
  add_token :str
128
118
  end
@@ -131,46 +121,16 @@ class FormatLine < StringParser
131
121
  @out
132
122
  end
133
123
 
134
- def grab_colon_param
135
- grab # grab :
136
- param = ""
137
- loop do
138
- case next!
139
- when Escape
140
- grab
141
- param << next!
142
- grab
143
- when Space, LF, nil; break
144
- else
145
- param << next!
146
- grab
147
- end
148
- end
149
-
150
- param = nil if param.empty?
151
- param
152
- end
153
-
154
124
  def grab_func_param
155
- grab # [
156
- param = ""
157
- loop do
158
- case next!
159
- when Escape
160
- grab
161
- param << next!
162
- grab
163
- when "]", LF, nil; break
164
- else
165
- param << next!
166
- grab
167
- end
125
+ case lookahead
126
+ when "["
127
+ param = grab_bracket_param
128
+ add_token(:brackets, param)
129
+ when ":"
130
+ param = grab_colon_param
131
+ add_token(:colon, param)
132
+ else # do nothing
168
133
  end
169
-
170
- add peek
171
- grab
172
- param = nil if param.empty?
173
- param
174
134
  end
175
135
 
176
136
  def add(str)
@@ -189,7 +149,7 @@ class FormatLine < StringParser
189
149
  loop do
190
150
  break if eos?
191
151
  str << peek
192
- break if terminate?(NoAlpha, next!)
152
+ break if terminate?(NoAlpha, lookahead)
193
153
  grab
194
154
  end
195
155
  str
@@ -201,7 +161,7 @@ class FormatLine < StringParser
201
161
  loop do
202
162
  break if peek.nil? # eos?
203
163
  str << peek
204
- break if terminate?(NoAlphaDot, next!)
164
+ break if terminate?(NoAlphaDot, lookahead)
205
165
  grab
206
166
  end
207
167
  str
@@ -216,7 +176,7 @@ class FormatLine < StringParser
216
176
  when "$"; double_dollar
217
177
  # when "."; dollar_dot
218
178
  when /[A-Za-z]/
219
- add_token :str
179
+ add_token :str
220
180
  var = peek + grab_alpha_dot
221
181
  add_token(:var, var)
222
182
  else
@@ -226,17 +186,14 @@ class FormatLine < StringParser
226
186
  end
227
187
 
228
188
  def double_dollar
229
- case next!
189
+ case lookahead
230
190
  when Space; add_token :string, "$$ "; grab; return
231
191
  when LF, nil; add "$$"; add_token :str
232
192
  when Alpha
233
193
  add_token(:str, @token)
234
194
  func = grab_alpha
235
195
  add_token(:func, func)
236
- case next!
237
- when ":"; param = grab_colon_param; add_token(:colon, param)
238
- when "["; param = grab_func_param; add_token(:brackets, param)
239
- end
196
+ param = grab_func_param # may be null/missing
240
197
  else
241
198
  grab; add_token :str, "$$" + peek; return
242
199
  end
@@ -276,7 +233,7 @@ class FormatLine < StringParser
276
233
  def double_marker(char)
277
234
  sym = Syms[char]
278
235
  kind = sym
279
- case next! # first char after **
236
+ case lookahead # first char after **
280
237
  when Space, LF, nil
281
238
  pre, post = SimpleFormats[sym]
282
239
  add_token kind
@@ -317,13 +274,12 @@ class FormatLine < StringParser
317
274
  add str
318
275
  str
319
276
  rescue => err
320
- STDERR.puts "ERR = #{err}\n#{err.backtrace}"
321
- STDERR.puts "=== str = #{str.inspect}"
277
+ ::STDERR.puts "ERR = #{err}\n#{err.backtrace}"
322
278
  end
323
279
 
324
280
  def escaped
325
- grab
326
- ch = grab
281
+ grab # Eat the backslash
282
+ ch = grab # Take next char
327
283
  ch
328
284
  end
329
285
 
@@ -350,20 +306,20 @@ class FormatLine < StringParser
350
306
  add str
351
307
  str
352
308
  rescue => err
353
- STDERR.puts "ERR = #{err}\n#{err.backtrace}"
354
- STDERR.puts "=== str = #{str.inspect}"
309
+ ::STDERR.puts "ERR = #{err}\n#{err.backtrace}"
355
310
  end
356
311
 
357
312
  def funcall(name, param)
358
313
  err = "[Error evaluating $$#{name}(#{param})]"
314
+ func_name = name # "func_" + name.to_s
359
315
  result =
360
- if self.respond_to?("func_" + name.to_s)
361
- self.send("func_" + name.to_s, param)
316
+ if self.send?(func_name, param) # self.respond_to?(func_name)
317
+ # do nothing
362
318
  else
363
319
  fobj = ::Livetext::Functions.new
364
320
  fobj.send(name, param) rescue err
365
321
  end
366
- result
322
+ result.to_s
367
323
  end
368
324
 
369
325
  def varsub(name)
@@ -374,4 +330,76 @@ class FormatLine < StringParser
374
330
  def embedded?
375
331
  ! (['"', "'", " ", nil].include? prev)
376
332
  end
333
+
334
+ private
335
+
336
+ def grab_colon_param
337
+ grab # grab :
338
+ param = ""
339
+ loop do
340
+ case lookahead
341
+ when Escape
342
+ grab
343
+ param << lookahead
344
+ grab
345
+ when Space, LF, nil; break
346
+ else
347
+ param << lookahead
348
+ grab
349
+ end
350
+ end
351
+
352
+ param = nil if param.empty?
353
+ param
354
+ end
355
+
356
+ def grab_bracket_param
357
+ grab # [
358
+ param = ""
359
+ loop do
360
+ case lookahead
361
+ when Escape
362
+ grab
363
+ param << lookahead
364
+ grab
365
+ when "]", LF, nil
366
+ break
367
+ else
368
+ param << lookahead
369
+ grab
370
+ end
371
+ end
372
+ add peek
373
+ grab
374
+ param = nil if param.empty?
375
+ param
376
+ end
377
+
378
+ def eval_bits(sym, val)
379
+ val = Livetext.interpolate(val)
380
+ @out << embed(sym, val)
381
+ end
382
+
383
+ def eval_func(val, gen)
384
+ param = nil
385
+ arg = gen.peek rescue :bogus
386
+ unless arg == :bogus
387
+ if [:colon, :brackets].include? arg[0]
388
+ arg = gen.next # for real
389
+ param = arg[1]
390
+ # FIXME - unsure - interpolate again??
391
+ # param = Livetext.interpolate(param)
392
+ end
393
+ end
394
+ @out << funcall(val, param)
395
+ end
396
+
397
+ def eval_var(val)
398
+ @out << varsub(val)
399
+ end
400
+
401
+ def eval_str(val)
402
+ @out << val unless val == "\n" # BUG
403
+ end
404
+
377
405
  end
data/lib/functions.rb CHANGED
@@ -13,6 +13,21 @@ class Livetext::Functions
13
13
  attr_accessor :param # kill this?
14
14
  end
15
15
 
16
+ # FIXME Function parameters need to be fixed...
17
+
18
+ def isqrt(param = nil) # "integer square root" - Just for testing
19
+ arg = num = param # Takes any number
20
+ if num.nil? || num.empty?
21
+ arg = "NO PARAM" # Just for error text
22
+ end
23
+ # Integer()/Float() can raise error
24
+ num = num.include?(".") ? Float(num) : Integer(num)
25
+ # Returns truncated integer
26
+ Math.sqrt(num).to_i # user need not do to_s
27
+ rescue => err # Malformed number? negative?
28
+ "[Error evaluating $$isqrt(#{arg})]"
29
+ end
30
+
16
31
  def date(param=nil)
17
32
  Time.now.strftime("%F")
18
33
  end
@@ -40,7 +55,7 @@ class Livetext::Functions
40
55
  "<br>"*n
41
56
  end
42
57
 
43
- def yt(param)
58
+ def yt(param) # FIXME uh, this is crap
44
59
  param = self.class.param
45
60
  "https://www.youtube.com/watch?v=#{param}"
46
61
  end
@@ -1,5 +1,5 @@
1
1
 
2
- class Livetext::Handler::ICanHaz
2
+ class Livetext::Handler::Import
3
3
  include Helpers
4
4
 
5
5
  attr_reader :file
data/lib/handler.rb CHANGED
@@ -1 +1 @@
1
- require_relative 'handler/icanhaz'
1
+ require_relative 'handler/import'
data/lib/helpers.rb CHANGED
@@ -55,12 +55,12 @@ module Helpers
55
55
  @backtrace = btrace
56
56
  @main.source(enum, fname, 0)
57
57
  line = nil
58
- loop do
58
+ loop do
59
59
  line = @main.nextline
60
60
  break if line.nil?
61
61
  process_line(line)
62
62
  end
63
- val = @main.finalize if @main.respond_to? :finalize
63
+ val = @main.finalize rescue nil
64
64
  @body
65
65
  end
66
66
 
@@ -95,21 +95,21 @@ module Helpers
95
95
  result = @main.send(name)
96
96
 
97
97
  # NOTE: The above line is where the magic happens!
98
- # A name like 'foobar' results in an invocation of
98
+ # A name like 'foobar' results in an invocation of
99
99
  # @main.foobar (where @main is a Processor, and any
100
100
  # new methods (e.g. from a mixin) are added to @main
101
- #
101
+ #
102
102
  # So all the functionality from _args and _raw_args
103
103
  # and _data (among others?) will be encapsulated in
104
- # 'some' kind of PORO which handles access to all
104
+ # 'some' kind of PORO which handles access to all
105
105
  # these things as well as the 'body' between the
106
106
  # command and its corresponding .end
107
- #
107
+ #
108
108
  # The 'body' functionality is so commonly used, I plan
109
109
  # to pass it in separately as needed (even though the
110
110
  # args object should make it available also).
111
- #
112
- # Every method corresponding to a dot commmand will
111
+ #
112
+ # Every method corresponding to a dot commmand will
113
113
  # get args and body passed in as needed. Every one of
114
114
  # the signatures already has (args = nil, body = nil)
115
115
  # but nothing is being passed in that way yet.
@@ -169,10 +169,10 @@ module Helpers
169
169
  value = path if File.exist?(path)
170
170
  break if value
171
171
  end
172
- STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
172
+ ::STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
173
173
  return value
174
174
  rescue
175
- STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
175
+ ::STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
176
176
  return nil
177
177
  end
178
178
 
data/lib/livetext.rb CHANGED
@@ -1,17 +1,25 @@
1
1
  # Class Livetext skeleton (top level).
2
2
 
3
3
  class Livetext
4
- VERSION = "0.9.21"
4
+ VERSION = "0.9.22"
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
 
7
7
  module Handler
8
8
  end
9
9
  end
10
10
 
11
- # $LOAD_PATH << Livetext::Path
12
-
13
11
  require 'fileutils'
14
12
 
13
+ class Object
14
+ def send?(meth, *args)
15
+ if self.respond_to?(meth)
16
+ self.send(meth, *args)
17
+ else
18
+ return nil
19
+ end
20
+ end
21
+ end
22
+
15
23
  require_relative 'errors'
16
24
  require_relative 'functions'
17
25
  require_relative 'userapi'
@@ -62,8 +70,7 @@ class Livetext
62
70
  def customize(mix: [], call: [], vars: {})
63
71
  mix = Array(mix)
64
72
  call = Array(call)
65
- # FIXME HF won't this break??
66
- mix.each {|lib| mixin(lib) }
73
+ mix.each {|lib| mixin(lib) } # FIXME HF won't this break??
67
74
  call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
68
75
  vars.each_pair {|var, val| setvar(var, val.to_s) }
69
76
  self
data/lib/parser/set.rb CHANGED
@@ -107,7 +107,6 @@ class Livetext::ParseSet < StringParser
107
107
  char = grab
108
108
  break if eos?
109
109
  break if char == quote
110
- # break if char.nil?
111
110
  char = escaped if char == "\\"
112
111
  value << char
113
112
  end
@@ -123,8 +122,7 @@ class Livetext::ParseSet < StringParser
123
122
  value = ""
124
123
  loop do
125
124
  char = peek
126
- break if eos? # FIXME oops???
127
- # break if char.nil?
125
+ break if eos?
128
126
  break if char == " " || char == ","
129
127
  value << char
130
128
  char = grab
data/lib/parser/string.rb CHANGED
@@ -24,7 +24,7 @@ class StringParser
24
24
  check_eos
25
25
  end
26
26
 
27
- def next!
27
+ def lookahead
28
28
  @line[@i + 1]
29
29
  end
30
30
 
@@ -62,7 +62,7 @@ end
62
62
 
63
63
  =begin
64
64
  skip
65
- next! skip! peek!(?)
65
+ lookahead skip! peek!(?)
66
66
  expect_alpha
67
67
  expect_number
68
68
  skip_spaces
data/lib/processor.rb CHANGED
@@ -46,10 +46,14 @@ class Livetext
46
46
  @output = io
47
47
  end
48
48
 
49
+ def error(*args)
50
+ ::STDERR.puts *args
51
+ end
52
+
49
53
  def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
50
54
  where = @sources.last || @save_location
51
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
52
- STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
55
+ error "Error: #{err} (at #{where[1]} line #{where[2]})"
56
+ error(err.backtrace) rescue nil
53
57
  raise GenericError.new("Error: #{err}") if raise_error
54
58
  end
55
59