livetext 0.8.79 → 0.8.80

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b10afcc4cb31c7ee535b019ad71dceb81642288b
4
- data.tar.gz: 31071b49e22b3a45638588cfc626364e47a1c205
2
+ SHA256:
3
+ metadata.gz: 326f2e6a0599793edfe3db620a0e00a68516422615962fbb6cb0b814ceff04da
4
+ data.tar.gz: 2d58bd744f5756c4b844d1127e29c079a6e35cb1ae9999f79bce2dc2aac14062
5
5
  SHA512:
6
- metadata.gz: 6174fa5fd3f5c0b4169adf59f89fe8aa438d324819ddb382210cf6e1ef3a4f26a2120f69d9c3fd8d85dcd709a081cdfb6ba35a68ae1be2c94958c95751718678
7
- data.tar.gz: 2ff43baa577625b28d82b7ba2dcfaee894216124de6ed60c4252369dd28f158dc94141954d7b92243acd57469eee9f6e6af319bf691900bc3c82a705c916496c
6
+ metadata.gz: a6662f81750092b1c51388c98f2ed72c282a7f295ad1a6d9e26f11536567515e15776b1b760ed7134783ed63f3eaa8754a871b05a8cd1e76b71522377973ff95
7
+ data.tar.gz: e0d711da1a52bb922fc2a07f9e1aee454bf759cb2d48eb49763f896001a6a95e5a18b1ddabaebd4709dbc8a582286f41075800856d47963d5349e303af36c955
@@ -40,7 +40,7 @@ class FormatLine
40
40
  def self.parse!(line, context = nil)
41
41
  return nil if line.nil?
42
42
  x = self.new(line.chomp, context)
43
- t = x.tokenize(line)
43
+ t = x.tokenize(line)
44
44
  x.evaluate # (context)
45
45
  end
46
46
 
@@ -79,8 +79,6 @@ t = x.tokenize(line)
79
79
  break if token.nil?
80
80
  sym, val = *token
81
81
  case sym
82
- when :ddot
83
- return [@out, val]
84
82
  when :str
85
83
  @out << val unless val == "\n" # BUG
86
84
  when :var
@@ -100,7 +98,7 @@ t = x.tokenize(line)
100
98
  end
101
99
  token = gen.next
102
100
  end
103
- [@out, nil]
101
+ @out
104
102
  end
105
103
 
106
104
  def curr
@@ -191,7 +189,7 @@ t = x.tokenize(line)
191
189
  when " "; add "$ "; add_token :str
192
190
  when nil; add "$"; add_token :str
193
191
  when "$"; double_dollar
194
- when "."; dollar_dot
192
+ # when "."; dollar_dot
195
193
  when /[A-Za-z]/
196
194
  add_token :str
197
195
  var = curr + grab_alpha
@@ -220,9 +218,9 @@ t = x.tokenize(line)
220
218
  end
221
219
  end
222
220
 
223
- def dollar_dot
224
- add_token :ddot, @line[@i..-1]
225
- end
221
+ # def dollar_dot
222
+ # add_token :ddot, @line[@i..-1]
223
+ # end
226
224
 
227
225
  def marker(char)
228
226
  add_token :str
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.8.79"
2
+ VERSION = "0.8.80"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -22,7 +22,7 @@ class Livetext
22
22
 
23
23
  attr_reader :main, :context
24
24
  attr_accessor :no_puts
25
- attr_accessor :body
25
+ attr_accessor :body, :indentation
26
26
 
27
27
  # FIXME - phase out stupid 'parameters' method
28
28
 
@@ -41,6 +41,7 @@ class Livetext
41
41
  @no_puts = output.nil?
42
42
  @body = ""
43
43
  @main = Processor.new(self, output)
44
+ @indentation = [0]
44
45
  end
45
46
 
46
47
  def process_line(line, context=nil)
@@ -48,15 +49,22 @@ class Livetext
48
49
  @context = context
49
50
  nomarkup = true
50
51
  # FIXME inefficient
51
- scomment = rx(Sigil, Livetext::Space) # apply these in order
52
- sname = rx(Sigil)
53
- if line =~ scomment
54
- handle_scomment(line)
55
- elsif line =~ sname
56
- handle_dotcmd(line)
52
+ comment = rx(Sigil, Livetext::Space) # apply these in order
53
+ dotcmd = rx(Sigil)
54
+ ddotcmd = /^ *\$\.[A-Za-z]/
55
+ case line
56
+ when comment
57
+ handle_scomment(line)
58
+ when dotcmd
59
+ handle_dotcmd(line)
60
+ when ddotcmd
61
+ indent = line.index("$") + 1
62
+ @indentation.push(indent)
63
+ line.sub!(/^ *\$/, "")
64
+ handle_dotcmd(line)
65
+ indentation.pop
57
66
  else
58
67
  @main._passthru(line, context)
59
- # Can output extra line(s) in $. scenario
60
68
  end
61
69
  end
62
70
 
@@ -161,7 +169,8 @@ class Livetext
161
169
  name = _check_name(name)
162
170
  end
163
171
 
164
- def handle_dotcmd(line)
172
+ def handle_dotcmd(line, indent = 0)
173
+ indent = @indentation.last # top of stack
165
174
  name = _get_name(line)
166
175
  result = nil
167
176
  if @main.respond_to?(name)
@@ -24,6 +24,7 @@ class Livetext
24
24
  # Meh?
25
25
  @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
26
26
  @sources = []
27
+ @indentation = @parent.indentation
27
28
  end
28
29
 
29
30
  def output=(io)
@@ -34,7 +35,7 @@ class Livetext
34
35
  where = @sources.last || @save_location
35
36
  puts @parent.body
36
37
  STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
37
- STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
38
+ # STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
38
39
  exit if abort
39
40
  end
40
41
 
@@ -165,11 +165,22 @@ module Livetext::Standard
165
165
 
166
166
  def heredoc
167
167
  var = @_args[0]
168
- # STDERR.puts "var = #{var.inspect}"
169
168
  str = _body_text
170
- # STDERR.puts "str = #{str.inspect}"
171
- Livetext::Vars[var] = str
172
- # STDERR.puts "vars = #{Livetext::Vars.inspect}"
169
+ indent = @parent.indentation.last
170
+ indented = " " * indent
171
+ # s2 = ""
172
+ # str.each_line do |line|
173
+ # if line.start_with?(indented)
174
+ # line.replace(line[indent..-1])
175
+ # else
176
+ # STDERR.puts "Error? heredoc not indented?"
177
+ # return
178
+ # end
179
+ # s2 << line
180
+ # end
181
+ s2 = str
182
+ Livetext::Vars[var.to_sym] = s2
183
+ Livetext::Vars[var] = s2 # FIXME
173
184
  _optional_blank_line
174
185
  end
175
186
 
@@ -200,7 +211,6 @@ module Livetext::Standard
200
211
  meths = grab_file(file)
201
212
  modname = name.gsub("/","_").capitalize
202
213
  string = "module ::#{modname}\n#{meths}\nend"
203
- # puts string # .inspect
204
214
  eval(string)
205
215
  newmod = Object.const_get("::" + modname)
206
216
  self.extend(newmod)
@@ -37,8 +37,11 @@ module Livetext::UserAPI
37
37
  end
38
38
 
39
39
  def _end?(str)
40
+ indent = ""
41
+ indent = " " * (@parent.indentation.last - 1)
42
+ indent << "$" unless indent.empty?
40
43
  return false if str.nil?
41
- cmd = Livetext::Sigil + "end"
44
+ cmd = indent + Livetext::Sigil + "end"
42
45
  return false if str.index(cmd) != 0
43
46
  return false unless _trailing?(str[5])
44
47
  return true
@@ -80,8 +83,8 @@ module Livetext::UserAPI
80
83
  lines
81
84
  end
82
85
  rescue => err
83
- p err.inspect
84
- puts err.backtrace
86
+ p err.inspect
87
+ puts err.backtrace
85
88
  _error!("Expecting .end, found end of file")
86
89
  end
87
90
 
@@ -102,32 +105,17 @@ puts err.backtrace
102
105
  end
103
106
 
104
107
  def _format(line, context = nil)
105
- return ["", nil] if line == "\n"
106
- l2 = FormatLine.parse!(line, context)
107
- line1, line2 = *l2
108
- line.replace(line1) unless line.nil?
108
+ return "" if line == "\n"
109
+ line2 = FormatLine.parse!(line, context)
110
+ line.replace(line2) unless line.nil?
109
111
  line
110
112
  end
111
113
 
112
- def _format!(line, context = nil)
113
- return ["", nil] if line == "\n"
114
- l2 = FormatLine.parse!(line, context)
115
- # maybe move fix back toward parse! ?
116
- line1, line2 = *l2
117
- line2 = line2.dup
118
- line.replace(line1) unless line.nil?
119
- line2 = @parent.handle_dotcmd(line2) unless line2.nil?
120
- [line, line2]
121
- end
122
-
123
114
  def _passthru(line, context = nil)
124
115
  return if @_nopass
125
116
  _out "<p>" if line == "\n" and ! @_nopara
126
- line, line2 = *_format!(line, context)
127
- p line
128
- p line2
117
+ line = _format(line, context)
129
118
  _out line
130
- _out line2
131
119
  end
132
120
 
133
121
  def _out(str = "")
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.79
4
+ version: 0.8.80
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-04-28 00:00:00.000000000 Z
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.4.6
153
+ rubygems_version: 2.7.7
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A smart processor for text