flor 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +14 -1
  3. data/CREDITS.md +1 -0
  4. data/LICENSE.txt +1 -1
  5. data/Makefile +6 -2
  6. data/README.md +2 -1
  7. data/flor.gemspec +12 -2
  8. data/lib/flor.rb +3 -3
  9. data/lib/flor/colours.rb +1 -1
  10. data/lib/flor/conf.rb +3 -4
  11. data/lib/flor/core/executor.rb +31 -61
  12. data/lib/flor/core/node.rb +213 -96
  13. data/lib/flor/core/procedure.rb +194 -75
  14. data/lib/flor/core/texecutor.rb +6 -7
  15. data/lib/flor/djan.rb +41 -22
  16. data/lib/flor/flor.rb +137 -42
  17. data/lib/flor/id.rb +77 -59
  18. data/lib/flor/log.rb +43 -22
  19. data/lib/flor/migrations/0001_tables.rb +7 -7
  20. data/lib/flor/parser.rb +271 -74
  21. data/lib/flor/pcore/_apply.rb +108 -0
  22. data/lib/flor/pcore/_atom.rb +2 -4
  23. data/lib/flor/pcore/_att.rb +54 -37
  24. data/lib/flor/pcore/_dmute.rb +18 -0
  25. data/lib/flor/pcore/_dol.rb +17 -0
  26. data/lib/flor/pcore/_dqs.rb +35 -0
  27. data/lib/flor/pcore/_head.rb +25 -0
  28. data/lib/flor/pcore/_obj.rb +1 -3
  29. data/lib/flor/pcore/_pat_guard.rb +1 -1
  30. data/lib/flor/pcore/_pat_obj.rb +11 -3
  31. data/lib/flor/pcore/_pat_regex.rb +16 -2
  32. data/lib/flor/pcore/_ref.rb +51 -0
  33. data/lib/flor/pcore/_rxs.rb +27 -0
  34. data/lib/flor/pcore/_val.rb +11 -6
  35. data/lib/flor/pcore/{logo.rb → andor.rb} +4 -6
  36. data/lib/flor/pcore/apply.rb +72 -2
  37. data/lib/flor/pcore/arith.rb +16 -4
  38. data/lib/flor/pcore/array_qmark.rb +100 -0
  39. data/lib/flor/pcore/break.rb +1 -2
  40. data/lib/flor/pcore/case.rb +1 -1
  41. data/lib/flor/pcore/cmp.rb +3 -2
  42. data/lib/flor/pcore/collect.rb +2 -2
  43. data/lib/flor/pcore/cond.rb +19 -1
  44. data/lib/flor/pcore/cursor.rb +12 -11
  45. data/lib/flor/pcore/define.rb +30 -4
  46. data/lib/flor/pcore/do_return.rb +3 -0
  47. data/lib/flor/pcore/flatten.rb +39 -0
  48. data/lib/flor/pcore/if.rb +15 -5
  49. data/lib/flor/pcore/includes.rb +5 -2
  50. data/lib/flor/pcore/inject.rb +1 -1
  51. data/lib/flor/pcore/iterator.rb +28 -18
  52. data/lib/flor/pcore/keys.rb +2 -2
  53. data/lib/flor/pcore/map.rb +19 -1
  54. data/lib/flor/pcore/match.rb +2 -2
  55. data/lib/flor/pcore/matchr.rb +18 -5
  56. data/lib/flor/pcore/max.rb +51 -0
  57. data/lib/flor/pcore/merge.rb +134 -0
  58. data/lib/flor/pcore/move.rb +1 -1
  59. data/lib/flor/pcore/noret.rb +1 -1
  60. data/lib/flor/pcore/not.rb +15 -1
  61. data/lib/flor/pcore/on.rb +11 -0
  62. data/lib/flor/pcore/on_cancel.rb +5 -1
  63. data/lib/flor/pcore/on_error.rb +69 -4
  64. data/lib/flor/pcore/push.rb +4 -9
  65. data/lib/flor/pcore/range.rb +5 -5
  66. data/lib/flor/pcore/reduce.rb +5 -18
  67. data/lib/flor/pcore/return.rb +26 -0
  68. data/lib/flor/pcore/reverse.rb +4 -0
  69. data/lib/flor/pcore/sequence.rb +8 -1
  70. data/lib/flor/pcore/set.rb +74 -15
  71. data/lib/flor/pcore/shuffle.rb +71 -0
  72. data/lib/flor/pcore/slice.rb +137 -0
  73. data/lib/flor/pcore/sort.rb +244 -0
  74. data/lib/flor/pcore/sort_by.rb +67 -0
  75. data/lib/flor/pcore/split.rb +39 -0
  76. data/lib/flor/pcore/stall.rb +1 -1
  77. data/lib/flor/pcore/strings.rb +123 -0
  78. data/lib/flor/pcore/timestamp.rb +34 -0
  79. data/lib/flor/pcore/to_array.rb +2 -3
  80. data/lib/flor/pcore/twig.rb +1 -1
  81. data/lib/flor/pcore/type_of.rb +37 -0
  82. data/lib/flor/pcore/until.rb +3 -3
  83. data/lib/flor/punit/cancel.rb +3 -3
  84. data/lib/flor/punit/ccollect.rb +29 -0
  85. data/lib/flor/punit/cmap.rb +76 -20
  86. data/lib/flor/punit/concurrence.rb +440 -33
  87. data/lib/flor/punit/cron.rb +1 -1
  88. data/lib/flor/punit/every.rb +1 -1
  89. data/lib/flor/punit/graft.rb +2 -3
  90. data/lib/flor/punit/on_timeout.rb +5 -1
  91. data/lib/flor/punit/part.rb +63 -0
  92. data/lib/flor/punit/schedule.rb +1 -1
  93. data/lib/flor/punit/task.rb +52 -10
  94. data/lib/flor/punit/trap.rb +4 -5
  95. data/lib/flor/tools/shell.rb +37 -18
  96. data/lib/flor/unit/caller.rb +23 -11
  97. data/lib/flor/unit/executor.rb +33 -12
  98. data/lib/flor/unit/ganger.rb +10 -1
  99. data/lib/flor/unit/hook.rb +2 -1
  100. data/lib/flor/unit/hooker.rb +13 -2
  101. data/lib/flor/unit/loader.rb +7 -7
  102. data/lib/flor/unit/logger.rb +15 -17
  103. data/lib/flor/unit/models.rb +4 -2
  104. data/lib/flor/unit/models/execution.rb +83 -38
  105. data/lib/flor/unit/models/message.rb +16 -0
  106. data/lib/flor/unit/models/pointer.rb +24 -0
  107. data/lib/flor/unit/models/timer.rb +25 -4
  108. data/lib/flor/unit/models/trace.rb +14 -0
  109. data/lib/flor/unit/models/trap.rb +39 -14
  110. data/lib/flor/unit/scheduler.rb +11 -7
  111. data/lib/flor/unit/storage.rb +55 -39
  112. data/lib/flor/unit/taskers.rb +17 -14
  113. data/lib/flor/unit/waiter.rb +4 -3
  114. metadata +40 -10
  115. data/lib/flor/changes.rb +0 -26
  116. data/lib/flor/dollar.rb +0 -224
  117. data/lib/flor/unit/hooks.rb +0 -37
@@ -41,7 +41,7 @@ module Flor
41
41
  a << " #{_c.lg}#{fla}#{_c.dg}" if fla
42
42
 
43
43
  st = nd && nd['status'].last
44
- a << " #{_c.dim}#{_c.lg}#{st['status']}:#{st['flavour']}#{_c.rs}#{_c.dg}" \
44
+ a << " #{_c.dim}#{_c.lg}#{st['status']}:#{st['flavour']}#{_c.rs}#{_c.dg}"\
45
45
  if st && st['status']
46
46
 
47
47
  t = m['tree']
@@ -56,7 +56,7 @@ module Flor
56
56
  ''
57
57
  end
58
58
 
59
- a << m['on_error'] ? " #{_c.rd}on_error" : ''
59
+ a << (m['on_error'] ? " #{_c.rd}on_error" : '')
60
60
 
61
61
  tmi = m['timer_id']
62
62
  tmi = tmi ? " #{_c.dg}tmi:#{tmi}" : ''
@@ -71,7 +71,7 @@ module Flor
71
71
  a << cn
72
72
 
73
73
  hp = nd && nd['heap']
74
- hp = hp && (hp != (t || [])[0]) ? " #{_c.dg}hp:#{nd['heap']}" : ''
74
+ hp = (hp && (hp != (t || [])[0])) ? " #{_c.dg}hp:#{nd['heap']}" : ''
75
75
  a << hp
76
76
 
77
77
  msr = " #{_c.dg}m#{m['m']}s#{m['sm'] || '_'}"
@@ -155,11 +155,14 @@ module Flor
155
155
  c = t1.is_a?(Array) ? '' : " #{_c.yl}#{t1}"
156
156
  l = " #{_c.dg}L#{t2}"
157
157
 
158
- o.puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" if headers && nid == '0'
158
+ o.puts "#{ind}#{_c.dg}+--- #{opts[:title]}#{_c.rs}" \
159
+ if headers && nid == '0'
159
160
  o.puts "#{ind}#{_c.dg}| #{nid} #{h}#{c}#{l}#{_c.rs}"
160
161
  t1.each_with_index { |ct, i|
161
- o.puts tree_to_s(ct, Flor.child_nid(nid, i), opts) } if t1.is_a?(Array)
162
- o.puts "#{ind}#{_c.dg}.#{_c.rs}" if headers && nid == '0'
162
+ o.puts tree_to_s(ct, Flor.child_nid(nid, i), opts) } \
163
+ if t1.is_a?(Array)
164
+ o.puts "#{ind}#{_c.dg}.#{_c.rs}" \
165
+ if headers && nid == '0'
163
166
 
164
167
  o.string
165
168
  end
@@ -184,6 +187,9 @@ module Flor
184
187
 
185
188
  def to_compact_tree_s(tree, nid='0', opts={})
186
189
 
190
+ close = opts[:close]
191
+ opts.merge!(close: false)
192
+
187
193
  o = StringIO.new
188
194
  _c = colours(opts)
189
195
 
@@ -213,8 +219,7 @@ module Flor
213
219
  o << "\n" << to_compact_tree_s(ct, "#{nid}_#{i}", opts)
214
220
  end
215
221
 
216
- #o << "\n" << ind << _c.dg << '\---' if is_root && opts[:close]
217
- o << "\n" << ind << _c.dg << '\---' if opts[:close]
222
+ o << "\n" << ind << _c.dg << '\---' if close
218
223
 
219
224
  o << _c.rs
220
225
 
@@ -225,9 +230,23 @@ module Flor
225
230
 
226
231
  def ret_to_s(executor, m, c)
227
232
 
228
- ret = (m['payload'] || {})['ret']
229
- s = Flor.to_d(ret, compact: true)
230
- Flor.truncate_string(s, 35, Proc.new { |x| "#{c.dg}... (L#{x})#{c.rs}" })
233
+ case pl = m['payload']
234
+ when NilClass, Hash
235
+ ret = (pl || {})['ret']
236
+ Flor.truncate_string(
237
+ Flor.to_d(ret, compact: true),
238
+ 35,
239
+ Proc.new { |x| "#{c.dg}... (ln#{x})#{c.rs}" })
240
+ else
241
+ s =
242
+ "#{c.rd}(/!\\ payload is an instance of #{pl.class}: " +
243
+ Flor.truncate_string(
244
+ Flor.to_d(pl, compact: true, color: false),
245
+ 35,
246
+ Proc.new { |x| "... (ln#{x})" }) +
247
+ ")#{c.rs}"
248
+ s
249
+ end
231
250
  end
232
251
 
233
252
  def nod_to_s(executor, n, opts, here=false)
@@ -235,16 +254,19 @@ module Flor
235
254
  _c = colours(opts)
236
255
 
237
256
  t = n['tree'] || Node.new(executor, n, nil).lookup_tree(n['nid'])
238
- t = Flor.to_d(t, compact: true) if t
239
- t = Flor.truncate_string(t, 42);
240
-
241
- h = {}
242
- %w[ parent cnid noreply dbg ].each do |k|
243
- h[k] = n[k] if n.has_key?(k)
257
+ if t
258
+ t = Flor.to_d(t, compact: true)
259
+ t = Flor.truncate_string(t, 42)
244
260
  end
245
261
 
246
- dbg = n['dbg'] ? "dbg:#{n['dbg']}" : nil
247
- nr = n.has_key?('noreply') ? "nr:#{n['noreply']}" : nil
262
+ h =
263
+ n.select { |k, _| [
264
+ 'parent' 'cnid' 'dbg' 'replyto',
265
+ 'noreply' # "for backward compatibility
266
+ ].include?(k) }
267
+
268
+ #dbg = n['dbg'] ? "dbg:#{n['dbg']}" : nil
269
+ #nr = n.has_key?('noreply') ? "nr:#{n['noreply']}" : nil
248
270
  h = h.collect { |k, v| "#{k}:#{v}" }.join(' ')
249
271
 
250
272
  vs = n['vars']
@@ -280,9 +302,8 @@ module Flor
280
302
  nodes = nodes.inject({}) { |h, n| h[n['nid']] = [ n, [] ]; h }
281
303
  nodes.values.each { |ncn|
282
304
  pa = ncn.first['parent']; next unless pa
283
- pan, pacn = nodes[pa]
284
- pacn << ncn if pacn
285
- }
305
+ _, pacn = nodes[pa]
306
+ pacn << ncn if pacn }
286
307
 
287
308
  sio = StringIO.new
288
309
  seen = []
@@ -5,7 +5,7 @@ Sequel.migration do
5
5
 
6
6
  create_table :flor_messages do
7
7
 
8
- primary_key :id, type: :Bignum
8
+ primary_key :id, type: :Integer
9
9
  String :domain, null: false
10
10
  String :exid, null: false
11
11
  String :point, null: false # 'execute', 'task', 'receive', 'schedule', ...
@@ -19,7 +19,7 @@ Sequel.migration do
19
19
 
20
20
  create_table :flor_executions do
21
21
 
22
- primary_key :id, type: :Bignum
22
+ primary_key :id, type: :Integer
23
23
  String :domain, null: false
24
24
  String :exid, null: false
25
25
  File :content # JSON
@@ -32,7 +32,7 @@ Sequel.migration do
32
32
 
33
33
  create_table :flor_timers do
34
34
 
35
- primary_key :id, type: :Bignum
35
+ primary_key :id, type: :Integer
36
36
  String :domain, null: false
37
37
  String :exid, null: false
38
38
  String :nid, null: false
@@ -40,7 +40,7 @@ Sequel.migration do
40
40
  String :schedule, null: false # '20141128.103239' or '00 23 * * *'
41
41
  String :ntime # next time
42
42
  File :content # JSON msg to trigger
43
- Bignum :count, null: false
43
+ Integer :count, null: false
44
44
  String :status, null: false
45
45
  String :ctime, null: false
46
46
  String :mtime, null: false
@@ -51,7 +51,7 @@ Sequel.migration do
51
51
 
52
52
  create_table :flor_traps do
53
53
 
54
- primary_key :id, type: :Bignum
54
+ primary_key :id, type: :Integer
55
55
  String :domain, null: false
56
56
  String :exid, null: false
57
57
  String :onid, null: false
@@ -76,7 +76,7 @@ Sequel.migration do
76
76
 
77
77
  create_table :flor_pointers do
78
78
 
79
- primary_key :id, type: :Bignum
79
+ primary_key :id, type: :Integer
80
80
  String :domain, null: false
81
81
  String :exid, null: false
82
82
  String :nid, null: false
@@ -97,7 +97,7 @@ Sequel.migration do
97
97
 
98
98
  create_table :flor_traces do
99
99
 
100
- primary_key :id, type: :Bignum
100
+ primary_key :id, type: :Integer
101
101
  String :domain, null: false
102
102
  String :exid, null: false
103
103
  String :nid, null: true
@@ -3,11 +3,10 @@ module Flor
3
3
 
4
4
  def self.parse(input, fname=nil, opts={})
5
5
 
6
+ #Raabro.pp(Flor::Parser.parse(input, debug: 2), colours: true)
7
+ #Raabro.pp(Flor::Parser.parse(input, debug: 3), colours: true)
6
8
  opts = fname if fname.is_a?(Hash) && opts.empty?
7
9
 
8
- #Raabro.pp(Flor::Parser.parse(input, debug: 2), colours: true)
9
- #Raabro.pp(Flor::Parser.parse(input, debug: 3), colours: true)
10
-
11
10
  if r = Flor::Parser.parse(input, opts)
12
11
  r << fname if fname
13
12
  r
@@ -23,10 +22,7 @@ module Flor
23
22
 
24
23
  def initialize(error_array, fname)
25
24
 
26
- #puts "-" * 80
27
- #p error_array
28
- #puts error_array.last
29
- #puts "-" * 80
25
+ #puts "-" * 80; p error_array; puts error_array.last; puts "-" * 80
30
26
  @line, @column, @offset, @msg, @visual = error_array
31
27
  @fname = fname
32
28
 
@@ -38,11 +34,17 @@ module Flor
38
34
 
39
35
  # parsing
40
36
 
41
- def ws_star(i); rex(nil, i, /[ \t]*/); end
37
+ def wstar(i); rex(nil, i, /[ \t]*/); end
38
+
42
39
  def retnew(i); rex(nil, i, /[\r\n]*/); end
43
40
  def dot(i); str(nil, i, '.'); end
44
41
  def colon(i); str(nil, i, ':'); end
42
+ def semicolon(i); str(nil, i, ';'); end
45
43
  def comma(i); str(nil, i, ','); end
44
+ def dquote(i); str(nil, i, '"'); end
45
+ def slash(i); str(nil, i, '/'); end
46
+ def dollar(i); str(nil, i, '$'); end
47
+ def pipepipe(i); str(nil, i, '||'); end
46
48
 
47
49
  def pstart(i); str(nil, i, '('); end
48
50
  def pend(i); str(nil, i, ')'); end
@@ -61,57 +63,112 @@ module Flor
61
63
  def fls(i); str(nil, i, 'false'); end
62
64
  def boolean(i); alt(:boolean, i, :tru, :fls); end
63
65
 
64
- def rf_sq_symbol(i); rex(nil, i, /[^.| \b\f\n\r\t"'()\[\]{}#\\]+/); end
65
- def rf_sq_index(i); alt(nil, i, :rf_sq_symbol, :dqstring, :sqstring); end
66
- def rf_square(i); seq(nil, i, :sbstart, :rf_sq_index, :sbend); end
67
- def rf_symbol(i); rex(nil, i, /[^.:;| \b\f\n\r\t"',()\[\]{}#\\]+/); end
68
- def rf_dot(i); seq(nil, i, :dot, :rf_symbol); end
69
- def rf_index(i); alt(nil, i, :rf_dot, :rf_square); end
66
+ def colon_eol(i); seq(:colo, i, :colon, :eol); end
67
+ def semicolon_eol(i); seq(nil, i, :semicolon, :eol); end
68
+ #
69
+ def rf_slice(i)
70
+ seq(:refsl, i, :exp, :comma_qmark_eol, :exp)
71
+ end
72
+ def colon_exp(i)
73
+ seq(nil, i, :colon_eol, :exp_qmark)
74
+ end
75
+ def rf_steps(i)
76
+ seq(:refst, i, :exp_qmark, :colon_exp, :colon_exp, '?')
77
+ end
78
+ def rf_sqa_index(i)
79
+ alt(nil, i, :rf_slice, :rf_steps, :exp)
80
+ end
81
+ def rf_sqa_semico_index(i)
82
+ seq(nil, i, :semicolon_eol, :rf_sqa_index)
83
+ end
84
+ def rf_sqa_idx(i)
85
+ seq(:refsq, i, :sbstart, :rf_sqa_index, :rf_sqa_semico_index, '*', :sbend)
86
+ end
87
+ def rf_dot_idx(i)
88
+ seq(nil, i, :dot, :rf_symbol)
89
+ end
90
+ def rf_index(i); alt(nil, i, :rf_dot_idx, :rf_sqa_idx); end
91
+ def rf_symbol(i); rex(:refsym, i, /[^.:;| \b\f\n\r\t"',()\[\]{}#\\]+/); end
92
+ #
70
93
  def reference(i); seq(:ref, i, :rf_symbol, :rf_index, '*'); end
71
94
 
72
- def dqstring(i)
73
-
74
- rex(:dqstring, i, %r{
75
- "(
95
+ def dqsc(i)
96
+ rex(:dqsc, i, %r{
97
+ (
76
98
  \\["\\\/bfnrt] |
77
99
  \\u[0-9a-fA-F]{4} |
78
- [^"\\\b\f\n\r\t]
79
- )*"
100
+ \$(?!\() |
101
+ [^\$"\\\b\f\n\r\t]
102
+ )+
80
103
  }x)
81
104
  end
82
105
 
83
- def sqstring(i)
106
+ def rxoc(i); rex(:rxoc, i, /[imxouesn]/); end
84
107
 
85
- rex(:sqstring, i, %r{
86
- '(
87
- \\['\\\/bfnrt] |
108
+ def rxsc(i)
109
+ rex(:rxsc, i, %r{
110
+ (
111
+ \\[\/bfnrt] |
88
112
  \\u[0-9a-fA-F]{4} |
89
- [^'\\\b\f\n\r\t]
90
- )*'
113
+ \$(?!\() |
114
+ [^\$/\b\f\n\r\t]
115
+ )+
91
116
  }x)
92
117
  end
93
118
 
119
+ def dor_lines(i)
120
+ seq(:dpar_lines, i, :pipepipe, :eol_wstar, :line, '+')
121
+ end
122
+ def dpar_lines(i)
123
+ seq(:dpar_lines, i, :eol_wstar, :line, '+')
124
+ end
125
+
126
+ def dpar(i)
127
+ seq(
128
+ :dpar, i,
129
+ :dollar, :pstart, :dpar_lines, :dor_lines, '?', :eol_wstar, :pend)
130
+ end
131
+
132
+ def dpar_or_rxoc(i); alt(nil, i, :dpar, :rxoc); end
133
+
134
+ def rxopts(i); rep(:rxopts, i, :dpar_or_rxoc, 0); end
135
+
136
+ def dpar_or_dqsc(i); alt(nil, i, :dpar, :dqsc); end
137
+ def dpar_or_rxsc(i); alt(nil, i, :dpar, :rxsc); end
138
+
139
+ def dqstring(i)
140
+ seq(:dqstring, i, :dquote, :dpar_or_dqsc, '*', :dquote)
141
+ end
142
+
143
+ def rxr(i) # used to break ambiguity against / (infix division)
144
+ rex(nil, i, /(regex|rex|rx|re|r)/)
145
+ end
146
+
94
147
  def rxstring(i)
148
+ seq(:rxstring, i, :rxr, '?', :slash, :dpar_or_rxsc, '*', :slash, :rxopts)
149
+ end
95
150
 
96
- rex(:rxstring, i, %r{
97
- /(
98
- \\[\/bfnrt] |
151
+ def sqstring(i)
152
+ rex(:sqstring, i, %r{
153
+ '(
154
+ \\['\\\/bfnrt] |
99
155
  \\u[0-9a-fA-F]{4} |
100
- [^/\b\f\n\r\t]
101
- )*/[a-z]*
156
+ [^'\\\b\f\n\r\t]
157
+ )*'
102
158
  }x)
103
159
  end
104
160
 
105
161
  def comment(i); rex(nil, i, /#[^\r\n]*/); end
106
162
 
107
- def eol(i); seq(nil, i, :ws_star, :comment, '?', :retnew); end
163
+ def eol(i); seq(nil, i, :wstar, :comment, '?', :retnew); end
164
+ def eol_wstar(i); seq(nil, i, :wstar, :comment, '?', :retnew, :wstar); end
108
165
  def postval(i); rep(nil, i, :eol, 0); end
109
166
 
110
- def comma_eol(i); seq(nil, i, :comma, :eol, :ws_star); end
111
- def sep(i); alt(nil, i, :comma_eol, :ws_star); end
167
+ def comma_eol(i); seq(nil, i, :comma, :eol, :wstar); end
168
+ def sep(i); alt(nil, i, :comma_eol, :wstar); end
112
169
 
113
170
  def comma_qmark_eol(i); seq(nil, i, :comma, '?', :eol); end
114
- def coll_sep(i); alt(nil, i, :comma_qmark_eol, :ws_star); end
171
+ def coll_sep(i); alt(nil, i, :comma_qmark_eol, :wstar); end
115
172
 
116
173
  def ent(i)
117
174
  seq(:ent, i, :key, :postval, :colon, :postval, :exp, :postval)
@@ -125,7 +182,9 @@ module Flor
125
182
  def obj(i); eseq(:obj, i, :pbstart, :ent_qmark, :coll_sep, :pbend); end
126
183
  def arr(i); eseq(:arr, i, :sbstart, :exp_qmark, :coll_sep, :sbend); end
127
184
 
128
- def par(i); seq(:par, i, :pstart, :eol, :ws_star, :node, :eol, :pend); end
185
+ def par(i)
186
+ seq(:par, i, :pstart, :eol_wstar, :node, :eol_wstar, :pend)
187
+ end
129
188
 
130
189
  def val(i)
131
190
  altg(:val, i,
@@ -134,7 +193,7 @@ module Flor
134
193
  :arr, :obj,
135
194
  :number, :boolean, :null)
136
195
  end
137
- def val_ws(i); seq(nil, i, :val, :ws_star); end
196
+ def val_ws(i); seq(nil, i, :val, :wstar); end
138
197
 
139
198
  # precedence
140
199
  # %w[ or or ], %w[ and and ],
@@ -167,23 +226,27 @@ module Flor
167
226
  alias exp eor
168
227
 
169
228
  def key(i); seq(:key, i, :exp); end
170
- def keycol(i); seq(nil, i, :key, :ws_star, :colon, :eol, :ws_star); end
229
+ def keycol(i); seq(nil, i, :key, :wstar, :colon, :eol_wstar); end
171
230
 
172
231
  def att(i); seq(:att, i, :sep, :keycol, '?', :exp); end
232
+ def riou(i); rex(:iou, i, /(if|unless)/); end
233
+ def iou(i); seq(nil, i, :sep, :riou); end
234
+ def natt(i); alt(nil, i, :iou, :att); end
235
+
173
236
  def head(i); seq(:head, i, :exp); end
174
237
  def indent(i); rex(:indent, i, /[ \t]*/); end
175
- def node(i); seq(:node, i, :indent, :head, :att, '*'); end
238
+ def node(i); seq(:node, i, :indent, :head, :natt, '*'); end
176
239
 
177
- def linjoin(i); rex(nil, i, /[ \t]*[\\|;][ \t]*/); end
240
+ def linjoin(i); rex(nil, i, /[ \t]*(\\|\|(?!\|)|;)[ \t]*/); end
178
241
  def outjnl(i); seq(nil, i, :linjoin, :comment, '?', :retnew); end
179
- def outnlj(i); seq(nil, i, :ws_star, :comment, '?', :retnew, :linjoin); end
242
+ def outnlj(i); seq(nil, i, :wstar, :comment, '?', :retnew, :linjoin); end
180
243
  def outdent(i); alt(:outdent, i, :outjnl, :outnlj, :eol); end
181
244
 
182
245
  def line(i)
183
246
  seq(:line, i, :node, '?', :outdent)
184
247
  end
185
248
  def panode(i)
186
- seq(:panode, i, :pstart, :eol, :ws_star, :line, '*', :eol, :pend)
249
+ seq(:panode, i, :pstart, :eol_wstar, :line, '*', :eol, :pend)
187
250
  end
188
251
 
189
252
  def flor(i); rep(:flor, i, :line, 0); end
@@ -201,7 +264,76 @@ module Flor
201
264
  Nod.new(t.lookup(:node), nil).to_a
202
265
  end
203
266
 
204
- def rewrite_ref(t); [ t.string, [], ln(t) ]; end
267
+ def rewrite_node(t)
268
+
269
+ Nod.new(t, nil).to_a
270
+ end
271
+
272
+ def rewrite_ref(t)
273
+
274
+ tts = t.subgather(nil)
275
+
276
+ if tts.length == 1
277
+ tt = tts.first
278
+ [ tt.string, [], ln(tt) ]
279
+ else
280
+ [ '_ref', tts.collect { |ct| rewrite(ct) }, ln(t) ]
281
+ end
282
+ end
283
+
284
+ def rewrite_refsym(t)
285
+
286
+ s = t.string
287
+
288
+ if s.match(/\A\d+\z/)
289
+ [ '_num', s.to_i, ln(t) ]
290
+ else
291
+ [ '_sqs', s, ln(t) ]
292
+ end
293
+ end
294
+
295
+ def rewrite_refsq(t)
296
+
297
+ tts = t.subgather(nil)
298
+
299
+ if tts.length == 1
300
+ rewrite(tts.first)
301
+ else
302
+ [ '_arr', tts.collect { |tt| rewrite(tt) }, ln(t) ]
303
+ end
304
+ end
305
+
306
+ def rewrite_refsl(t)
307
+
308
+ st, co = t.subgather(nil)
309
+
310
+ [ '_obj', [
311
+ [ '_sqs', 'start', ln(st) ], rewrite(st),
312
+ [ '_sqs', 'count', ln(co) ], rewrite(co),
313
+ ], ln(t) ]
314
+ end
315
+
316
+ def rewrite_refst(t)
317
+
318
+ #puts "-" * 80
319
+ #Raabro.pp(t, colours: true)
320
+ ts = t.subgather(nil).collect { |tt| tt.name == :colo ? ':' : tt }
321
+ ts.unshift(0) if ts.first == ':' # begin
322
+ ts.push(':') if ts.count { |ct| ct == ':' } < 2 #
323
+ ts.push(1) if ts.last == ':' # step
324
+ ts.insert(2, -1) if ts[2] == ':' # end
325
+
326
+ be, _, en, _, st = ts
327
+ be = be.is_a?(Integer) ? [ '_num', be, ln(t) ] : rewrite(be)
328
+ en = en.is_a?(Integer) ? [ '_num', en, ln(t) ] : rewrite(en)
329
+ st = st.is_a?(Integer) ? [ '_num', st, ln(t) ] : rewrite(st)
330
+
331
+ [ '_obj', [
332
+ [ '_sqs', 'start', be[2] ], be,
333
+ [ '_sqs', 'end', en[2] ], en,
334
+ [ '_sqs', 'step', st[2] ], st,
335
+ ], ln(t) ]
336
+ end
205
337
 
206
338
  UNESCAPE = {
207
339
  "'" => "'", '"' => '"', '\\' => '\\', '/' => '/',
@@ -215,10 +347,52 @@ module Flor
215
347
  }
216
348
  end
217
349
 
218
- def rewrite_dqstring(t); [ '_dqs', restring(t.string[1..-2]), ln(t) ]; end
219
- def rewrite_sqstring(t); [ '_sqs', restring(t.string[1..-2]), ln(t) ]; end
220
- def rewrite_rxstring(t); [ '_rxs', t.string, ln(t) ]; end
350
+ def rewrite_dqsc(t); [ '_sqs', restring(t.string), ln(t) ]; end
351
+ alias rewrite_rxsc rewrite_dqsc
352
+
353
+ def rewrite_dpar_lines(t)
354
+
355
+ #Raabro.pp(t, colours: true); p t.string
356
+ [ '_dmute', t.subgather(:node).collect { |ct| rewrite(ct) }, ln(t) ]
357
+ end
358
+
359
+ def rewrite_dpar(t)
360
+
361
+ [ '_dol', t.subgather(nil).collect { |ct| rewrite(ct) }, ln(t) ]
362
+ end
363
+
364
+ def rewrite_dqstring(t)
365
+
366
+ cn = t.subgather(nil).collect { |tt| rewrite(tt) }
367
+
368
+ if cn.size == 1 && cn[0][0] == '_sqs'
369
+ cn[0]
370
+ elsif cn.size == 0
371
+ [ '_sqs', '', ln(t) ]
372
+ else
373
+ [ '_dqs', cn, ln(t) ]
374
+ end
375
+ end
221
376
 
377
+ alias rewrite_rxopts rewrite_dqstring
378
+
379
+ def rewrite_rxoc(t); [ '_sqs', t.string, ln(t) ]; end
380
+
381
+ def rewrite_rxstring(t)
382
+
383
+ l = ln(t)
384
+ cts = t.subgather(nil)
385
+ rot = cts.pop
386
+
387
+ cn = cts.collect(&method(:rewrite))
388
+
389
+ cn.unshift([ '_att', [ [ 'rxopts', [], l ], rewrite(rot) ], l ]) \
390
+ if rot.length > 0
391
+
392
+ [ '_rxs', cn, l ]
393
+ end
394
+
395
+ def rewrite_sqstring(t); [ '_sqs', restring(t.string[1..-2]), ln(t) ]; end
222
396
  def rewrite_boolean(t); [ '_boo', t.string == 'true', line_number(t) ]; end
223
397
  def rewrite_null(t); [ '_nul', nil, line_number(t) ]; end
224
398
 
@@ -276,9 +450,14 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
276
450
 
277
451
  def rewrite_exp(t)
278
452
 
453
+ #puts "-" * 80
454
+ #puts caller[0, 7]
455
+ #Raabro.pp(t, colours: true)
279
456
  return rewrite(t.c0) if t.children.size == 1
280
-
457
+ #puts "-" * 80
458
+ #puts caller[0, 7]
281
459
  #Raabro.pp(t, colours: true)
460
+
282
461
  cn = t.children.collect { |ct| ct.lookup(nil) }
283
462
 
284
463
  operation = cn.find { |ct| ct.name == :sop }.string
@@ -349,8 +528,14 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
349
528
 
350
529
  as.each do |c|
351
530
 
352
- c1 = c[1]; c10 = c1.size == 1 && c1[0]
353
- suff = [] if c10 && c10[1] == [] && %w[ if unless ].include?(c10[0])
531
+ if %w[ if unless ].include?(c[1])
532
+ suff = []
533
+ elsif suff && c[1].length > 1
534
+ iou = suff.shift; iou[1] = [ [ iou[1], [], iou[2] ] ]
535
+ atts << iou
536
+ atts.concat(suff)
537
+ suff = nil
538
+ end
354
539
 
355
540
  (suff || atts) << c
356
541
  end
@@ -363,13 +548,19 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
363
548
 
364
549
  return core unless suff
365
550
 
366
- iou = suff.shift[1][0][0]
367
-
368
- [ iou, [ suff.first[1].first, core ], @line ]
551
+ ta_rework_suff(core, suff)
369
552
  end
370
553
 
371
554
  protected
372
555
 
556
+ def ta_rework_suff(core, suff)
557
+
558
+ cond = suff[1][1][0]
559
+ suff[2..-1].each { |ct| cond[1] << ct }
560
+
561
+ [ '_' + suff.shift[1], [ cond, core ], @line ]
562
+ end
563
+
373
564
  def ta_rework_arr_or_obj(atts, non_atts)
374
565
 
375
566
  return [ atts, non_atts ] unless (
@@ -385,23 +576,22 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
385
576
 
386
577
  def ta_rework_core(core)
387
578
 
388
- dig = Digest::SHA256.hexdigest(JSON.dump(core))[0, 7]
389
- tsp = Flor.tamp.gsub(/\./, '_')
390
- h = "_head_#{dig}_#{tsp}"
579
+ hd, cn, ln = core
580
+ s = @tree.lookup(:head).string.strip
391
581
 
392
- l = core[2]
393
-
394
- [ 'sequence', [
395
- [ 'set', [
396
- [ h, [], l ],
397
- core[0]
398
- ], l ],
399
- [ h, core[1], l ]
400
- ], l ]
582
+ [ '_head', [
583
+ [ '_sqs', s, ln ],
584
+ hd,
585
+ [ '__head', cn, ln ]
586
+ ], ln ]
401
587
  end
402
588
 
403
589
  def read(tree)
404
590
 
591
+ @tree = tree
592
+ #puts "-" * 80
593
+ #Raabro.pp(tree, colours: true)
594
+
405
595
  @indent = tree.lookup(:indent).string.length
406
596
 
407
597
  ht = tree.lookup(:head)
@@ -413,17 +603,24 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
413
603
  atts = tree.children[2..-1]
414
604
  .inject([]) { |as, ct|
415
605
 
416
- kt = ct.children.size == 3 ? ct.children[1].lookup(:key) : nil
417
- v = Flor::Parser.rewrite(ct.clast)
606
+ ct = ct.lookup(nil)
607
+
608
+ if ct.name == :iou
609
+
610
+ as.push([ '_att', ct.string, @line ])
418
611
 
419
- if kt
420
- k = Flor::Parser.rewrite(kt.c0)
421
- as << [ '_att', [ k, v ], k[2] ]
422
612
  else
423
- as << [ '_att', [ v ], v[2] ]
424
- end
425
613
 
426
- as }
614
+ kt = ct.children.size == 3 ? ct.children[1].lookup(:key) : nil
615
+ v = Flor::Parser.rewrite(ct.clast)
616
+
617
+ if kt
618
+ k = Flor::Parser.rewrite(kt.c0)
619
+ as.push([ '_att', [ k, v ], k[2] ])
620
+ else
621
+ as.push([ '_att', [ v ], v[2] ])
622
+ end
623
+ end }
427
624
 
428
625
  @children.concat(atts)
429
626
 
@@ -452,7 +649,7 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
452
649
 
453
650
  def rework_addition
454
651
 
455
- katts, atts, cn = @children
652
+ katts, atts, children = @children
456
653
  .inject([ [], [], [] ]) { |cn, ct|
457
654
  if ct[0] == '_att'
458
655
  cn[ct[1].size == 2 ? 0 : 1] << ct
@@ -462,7 +659,7 @@ fail "don't know how to invert #{operation.inspect}" # FIXME
462
659
  cn }
463
660
 
464
661
  @children =
465
- katts + atts.collect { |ct| ct[1].first } + cn
662
+ katts + atts.collect { |ct| ct[1].first } + children
466
663
  end
467
664
  end
468
665