livetext 0.6.5 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.ltx +5 -5
  3. data/bin/livetext +1 -1
  4. data/lib/livetext.rb +71 -58
  5. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f706dc4d367cb931a999a1ba4918fbb46981a57
4
- data.tar.gz: 5c0d148218f148c2f8e99877b8d331e3385bbfef
3
+ metadata.gz: 13347ab8dd844db4d4bd6b65038c3d8a57b6c102
4
+ data.tar.gz: 146caebefc11e7c98604ed238c135b084c0e35ff
5
5
  SHA512:
6
- metadata.gz: c0e6c42f2b8a91c4d2fce8e03e0bba6f1ad60afd82edb0323566b45b48088b11b381655213c2ff969e8b6f2c73e2d16951d0429f410aee712e6bd09a016ce415
7
- data.tar.gz: 6d9e96b0d091dfbc94bcdea217305aff01bc230c43c44f0b2e1cbd509b00b83a130dd97d7f36b30907af0be2b871a441260c1060a8b475e43f68e8e30126550c
6
+ metadata.gz: 21b01a30d65224433e06f456354882169298f96f822aa92f556303d596393bfa9244525884cd2ebc53a2d8cda777f920d4cd04e059267d3457110fa8e20a011c
7
+ data.tar.gz: d57ad1df788529d5e0748eee9b01482f9c509ca246254f672ff9315eb3b441e426e0c5e8977df2e776d9f033edc6915f301b5fb2df28dcccc77ec3fdc1d1c681
data/README.ltx CHANGED
@@ -1,4 +1,4 @@
1
- .mixin lib/tutorial
1
+ .mixin dsl/tutorial
2
2
  .title Livetext: A smart processor for text
3
3
 
4
4
  .p Livetext is simply a tool for transforming text from one format into another. The source file
@@ -59,8 +59,8 @@ in commented form.
59
59
  a block of lines rather than just a few parameters. (A text block is like a here-document.)
60
60
  There is no method name corresponding to the `.end command.
61
61
 
62
- .p The file extension I've chosen is `.lt (though this may change). *Note: The source for this
63
- README is a `.lt file which uses its own little _(ad hoc) library (called `(readme.rb)). Refer to
62
+ .p The file extension I've chosen is `.ltx (though this may change). *Note: The source for this
63
+ README is a `.ltx file which uses its own little _(ad hoc) library (called `(readme.rb)). Refer to
64
64
  the repo to see these.
65
65
 
66
66
  .section Syntax, comments, and more
@@ -117,7 +117,7 @@ Here is the current list:
117
117
  .dlist
118
118
  `comment ~~ Start a comment block
119
119
  `errout ~~ Write an error message to STDERR
120
- `sigil ~~ Change the default sigil from `. to some other character
120
+ `sigil ~~ Change the default sigil from `. to some other character (*(removed for now))
121
121
  `_def ~~ Define a new method inline
122
122
  `set ~~ Assign values to variables for later interpolation
123
123
  `include ~~ Include an outside text file (to be interpreted as Livetext)
@@ -259,7 +259,7 @@ def alpha
259
259
  end
260
260
  .end
261
261
 
262
- .p Now the `.lt file can be written this way:
262
+ .p Now the `.ltx file can be written this way:
263
263
 
264
264
  .code
265
265
  .mixin mylib
data/bin/livetext CHANGED
@@ -5,7 +5,7 @@ require_relative '../lib/livetext'
5
5
  def handle_ltx(src)
6
6
  abort "Unknown file extension" unless src =~ /.ltx$/
7
7
 
8
- Livetext.handle_file(src)
8
+ Livetext.process_file(src)
9
9
  end
10
10
 
11
11
  # Main
data/lib/livetext.rb CHANGED
@@ -15,7 +15,7 @@ class Enumerator
15
15
  end
16
16
 
17
17
  class Livetext
18
- VERSION = "0.6.5"
18
+ VERSION = "0.6.7"
19
19
 
20
20
  Space = " "
21
21
 
@@ -37,6 +37,7 @@ class Livetext
37
37
  end
38
38
 
39
39
  def self.handle_line(line)
40
+ # ::TTY.puts "---- hline - #{line.inspect}"
40
41
  nomarkup = true
41
42
  sigil = "."
42
43
  scomment = rx(sigil, Livetext::Space) # apply these in order
@@ -48,6 +49,41 @@ class Livetext
48
49
  end
49
50
  end
50
51
 
52
+ def self.peek_nextline
53
+ @sources.last[0].peek
54
+ rescue StopIteration
55
+ # @sources.pop # FIXME??
56
+ nil
57
+ end
58
+
59
+ def self.nextline
60
+ return nil if @sources.empty?
61
+ line = @sources.last[0].next
62
+ @sources.last[2] += 1
63
+ line
64
+ rescue StopIteration
65
+ # @sources.pop # FIXME??
66
+ # retry
67
+ end
68
+
69
+ def self.process_file(fname, &block)
70
+ block ||= proc {|line| handle_line(line) }
71
+ @sources ||= []
72
+ enum = File.readlines(fname).each
73
+ @main ||= Livetext::System.new(enum)
74
+ @sources.push [enum, fname, 0]
75
+ loop do
76
+ line = nextline
77
+ break if line.nil?
78
+ block.call(line) # handle_line(line)
79
+ end
80
+ # @sources.pop # FIXME ?
81
+ end
82
+
83
+ def self.grab_file(fname)
84
+ File.read(fname)
85
+ end
86
+
51
87
  def self.handle_file(file)
52
88
  fname = "<<none>>"
53
89
  if file.is_a? String
@@ -56,13 +92,12 @@ class Livetext
56
92
  end
57
93
  source = file.each_line
58
94
  @main = Livetext::System.new(source)
59
- # @main._switch_file(fname)
60
95
  @main.file = fname
61
96
  @main.lnum = 0
62
97
 
63
98
  loop do
64
- line = @main._next_line
65
- handle_line(line)
99
+ line = ::Livetext.nextline
100
+ ::Livetext.handle_line(line)
66
101
  end
67
102
 
68
103
  val = @main.finalize if @main.respond_to?(:finalize)
@@ -71,7 +106,6 @@ class Livetext
71
106
  STDERR.puts "handle_file: #{err}"
72
107
  end
73
108
 
74
-
75
109
  def self.rx(str, space=nil)
76
110
  Regexp.compile("^" + Regexp.escape(str) + "#{space}")
77
111
  end
@@ -84,7 +118,7 @@ class Livetext
84
118
  end
85
119
 
86
120
  def self._get_name(sigil, line)
87
- blank = line.index(" ") || line.index("\n")
121
+ blank = line.index(" ") || -1 # line.index("\n")
88
122
  name = line[1..(blank-1)]
89
123
  abort "#{@main.where}: Name '#{name}' is not permitted" if _disallowed?(name)
90
124
  @main._data = line[(blank+1)..-1]
@@ -106,9 +140,9 @@ class Livetext
106
140
  rescue => err
107
141
  STDERR.puts "ERROR on #{@main.file} line #{@main.lnum} : #{err}"
108
142
  # STDERR.puts " self = #{self.inspect} @main = #{@main.inspect}"
109
- STDERR.puts " sources = #{@main.source_files.inspect}"
143
+ # STDERR.puts " sources = #{@main.source_files.inspect}"
110
144
  STDERR.puts err.backtrace
111
- STDERR.puts "--- Methods = #{(@main.methods - Object.methods).sort}\n "
145
+ # STDERR.puts "--- Methods = #{(@main.methods - Object.methods).sort}\n "
112
146
  end
113
147
 
114
148
  end
@@ -157,7 +191,7 @@ module Livetext::Helpers
157
191
  end
158
192
 
159
193
  def _optional_blank_line
160
- @line = _next_line if _peek_next_line =~ /^ *$/
194
+ @line = ::Livetext.nextline if ::Livetext.peek_nextline =~ /^ *$/
161
195
  end
162
196
 
163
197
  def _comment?(str, sigil=".")
@@ -181,7 +215,7 @@ module Livetext::Helpers
181
215
  def _raw_body(tag = "__EOF__", sigil = ".")
182
216
  lines = []
183
217
  loop do
184
- @line = _next_line
218
+ @line = ::Livetext.nextline
185
219
  break if @line.chomp.strip == tag
186
220
  lines << @line
187
221
  end
@@ -196,7 +230,7 @@ module Livetext::Helpers
196
230
  def _body(sigil=".")
197
231
  lines = []
198
232
  loop do
199
- @line = _next_line # no chomp needed
233
+ @line = ::Livetext.nextline # no chomp needed
200
234
  break if _end?(@line, sigil)
201
235
  next if _comment?(@line, sigil)
202
236
  lines << @line # _formatting(line) # FIXME ??
@@ -304,16 +338,21 @@ module Livetext::Helpers
304
338
  @output.print *args
305
339
  end
306
340
 
307
- def _peek_next_line
308
- @input.peek
309
- end
341
+ # def peek_next_line
342
+ # @sources.last[0].peek
343
+ # rescue StopIteration
344
+ # @sources.pop
345
+ # nil
346
+ # end
310
347
 
311
- def _next_line
312
- @line = @input.next
313
- @lnum += 1
314
- _debug "Line: #@lnum: #@line"
315
- @line
316
- end
348
+ # def _next_line
349
+ # @line = @sources.last[0].next
350
+ # @sources.last[2] += 1
351
+ # _debug "Line: #@lnum: #@line"
352
+ # @line
353
+ # rescue StopIteration
354
+ # nil
355
+ # end
317
356
 
318
357
  def _debug=(val)
319
358
  @_debug = val
@@ -457,35 +496,15 @@ module Livetext::Standard
457
496
  _optional_blank_line
458
497
  end
459
498
 
460
- def _switch_file(fname)
461
- ::STDERR.puts " switching to #{fname}, pushing #@file"
462
- @source_files ||= []
463
- @source_files.push(@file)
464
- @file = fname
465
- ::STDERR.puts " sources = #{@source_files.inspect}"
466
- @file
467
- end
468
-
469
- def _popfile
470
- @file = @source_files.pop
471
- end
472
-
473
499
  def _include
474
500
  file = _args.first
475
- lines = ::File.readlines(file)
476
- _switch_file(file)
477
- # STDERR.puts "_include: ****** Set @file = #@file"
478
- lines.each {|line| _debug " inc: #{line}" }
479
- rem = @input.remaining
480
- array = lines + rem
481
- @input = array.each # FIXME .with_index
501
+ ::Livetext.process_file(file) # {|line| ::Livetext.handle_line(line) }
482
502
  _optional_blank_line
483
- _popfile
484
503
  end
485
504
 
486
- def include!
505
+ def include! # FIXME huh?
487
506
  file = _args.first
488
- _switch_file(file)
507
+ # _switch_file(file)
489
508
  existing = File.exist?(file)
490
509
  return if not existing
491
510
  lines = ::File.readlines(file)
@@ -495,27 +514,25 @@ module Livetext::Standard
495
514
  array = lines + rem
496
515
  @input = array.each # FIXME .with_index
497
516
  _optional_blank_line
498
- _popfile
499
517
  end
500
518
 
501
519
  def mixin
502
520
  name = _args.first # Expect a module name
503
521
  file = "#{Plugins}/" + name.downcase + ".rb"
504
- return if @_mixins.include?(file)
522
+ return if @_mixins.include?(name)
505
523
  file = "./#{name}.rb" unless File.exist?(file)
506
524
  _check_existence(file)
507
525
 
508
- @_mixins << file
509
- _switch_file(file)
510
- modname = name.capitalize
511
- string = "module ::#{modname}\n" + File.read(file) + "\nend"
526
+ @_mixins << name
527
+ meths = ::Livetext.grab_file(file)
528
+ modname = name.gsub("/","_").capitalize
529
+ string = "module ::#{modname}\n#{meths}\nend"
512
530
  eval(string)
513
531
  newmod = Object.const_get("::" + modname)
514
- Livetext.main.extend(newmod) # CRAP
532
+ Livetext.main.extend(newmod)
515
533
  init = "init_#{name}"
516
534
  self.send(init) if self.respond_to? init
517
535
  _optional_blank_line
518
- _popfile
519
536
  end
520
537
 
521
538
  def old_mixin
@@ -526,7 +543,7 @@ module Livetext::Standard
526
543
  raise "No such file: #{name}.rb found" unless File.exist?(file)
527
544
 
528
545
  @_mixins << file
529
- _switch_file(file)
546
+ # process_file(file)
530
547
  main = Livetext.main
531
548
  m0 = main.methods.reject {|x| x.to_s[0] == "_" }
532
549
  self.class.class_eval(::File.read(file))
@@ -535,16 +552,12 @@ module Livetext::Standard
535
552
  init = "init_#{name}"
536
553
  self.send(init) if self.respond_to? init
537
554
  _optional_blank_line
538
- _popfile
539
555
  end
540
556
 
541
557
  def copy
542
558
  file = _args.first
543
- _switch_file(file)
544
- text = ::File.readlines(file)
545
- @output.puts text
559
+ @output.puts ::Livetext.grab_file(file)
546
560
  _optional_blank_line
547
- _popfile
548
561
  end
549
562
 
550
563
  def r
@@ -644,6 +657,6 @@ class Livetext::System # < BasicObject
644
657
  end
645
658
 
646
659
  if $0 == __FILE__
647
- Livetext.handle_file(ARGV[0] || STDIN)
660
+ Livetext.process_file(ARGV[0] || STDIN) # {|line| Livetext.handle_line(line) }
648
661
  end
649
662
 
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.6.5
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -102,8 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.2
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: A smart processor for text
109
109
  test_files: []
110
+ has_rdoc: