udon 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -12,5 +12,5 @@ group :development do
12
12
  gem "rcov", ">= 0"
13
13
  gem "reek", "~> 1.2.8"
14
14
  gem "roodi", "~> 2.1.0"
15
- gem "genmachine", "~> 0.2.1"
15
+ gem "genmachine", "~> 0.2.2"
16
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -3,46 +3,46 @@ $KCODE="U"
3
3
 
4
4
  class Integer
5
5
  def into(v); v << self end
6
+ def into!(v); into(v) end
6
7
  def reset!; :nop end
7
8
  def reset; :nop end
8
9
  end
9
10
 
11
+ class String
12
+ def into(v); into!(v) unless size == 0 end
13
+ def into!(v); v << self.dup; reset! end
14
+ def <<(v)
15
+ begin
16
+ concat([v].pack('U*'))
17
+ rescue
18
+ concat(v)
19
+ end
20
+ end
21
+ def reset!; self.gsub! /./um,'' end
22
+ def reset; d=dup;d.reset!;d end
23
+ end
24
+
25
+
10
26
  module UdonParser
11
27
  def self.parse(str) Parser.new(str).parse end
12
28
  def self.parse_file(fname) Parser.new(IO.read(fname)).parse end
13
29
 
14
30
 
15
31
  class UArray < Array
16
- def into(v)
17
- return if size == 0
18
- v << self
19
- end
32
+ def into(v); into!(v) unless size == 0 end
33
+ def into!(v); v << self end
20
34
  def reset!; self.clear end
21
35
  def reset; d=dup;d.reset!;d end
22
36
  end
23
37
 
24
38
  class UHash < Hash
39
+ def into!(v) v << self end
25
40
  def into(v) v << self end
26
41
  def <<(kv) k,v = kv; self[k] = v end
27
42
  def reset!; self.clear end
28
43
  def reset; d=dup; d.reset!; d end
29
44
  end
30
45
 
31
- class UString < String
32
- def into(v)
33
- return if size == 0
34
- v << self.dup
35
- reset!
36
- end
37
-
38
- def <<(v)
39
- begin; super([v].pack('U*'))
40
- rescue; super(v) end
41
- end
42
- def reset!; self.gsub! /./um,'' end
43
- def reset; d=dup;d.reset!;d end
44
- end
45
-
46
46
  class UNode
47
47
  attr_accessor :name, :m,:a,:c
48
48
  def initialize(params={})
@@ -53,6 +53,7 @@ module UdonParser
53
53
  @c= params.delete(:c) || []
54
54
  @name = params.delete(:name)
55
55
  end
56
+ def into!(val) val << self end
56
57
  def into(val) val << self end
57
58
  def <<(val) @c<<val end
58
59
  def [](key) @c[key] end
@@ -122,12 +123,12 @@ module UdonParser
122
123
  @leading = true; @indent = 0
123
124
  when 0x0a
124
125
  nc = peek(4).unpack('U')[0]
125
- if nc == 0x0d then getch; c = UString.new("\n\r") end
126
+ if nc == 0x0d then getch; c = "\n\r" end
126
127
  @last_is_newline = true; @line += 1; @pos = 1
127
128
  @leading = true; @indent = 0
128
129
  when 0x0d
129
130
  nc = peek(4).unpack('U')[0]
130
- if nc == 0x0a then getch; c = UString.new("\r\n") end
131
+ if nc == 0x0a then getch; c = "\r\n" end
131
132
  @last_is_newline = true; @line += 1; @pos = 1
132
133
  @leading = true; @indent = 0
133
134
  when 0x20,0x09
@@ -158,8 +159,8 @@ module UdonParser
158
159
  def document(p=nil,name='document')
159
160
  __state=':data_or_child'
160
161
  s = UArray.new
161
- a ||= UString.new
162
- b ||= UString.new
162
+ a ||= ''
163
+ b ||= ''
163
164
  loop do
164
165
  __i = nextchar
165
166
  __state = '{eof}' if __i==:eof
@@ -168,12 +169,13 @@ module UdonParser
168
169
  case
169
170
  when nl?; @fwd=true; b.into(a); __state=':data'; next
170
171
  when __i==9,space?; __i.into(b); next
171
- when __i==35,__i==124; @fwd=true; b.reset!; __state=':child'; next
172
+ when __i==35,__i==124; @fwd=true; b.reset!; a.into(s); __state=':child'; next
172
173
  else @fwd=true; b.into(a); __state=':data'; next
173
174
  end
174
175
  when ':child'
175
- if __i==35
176
- a.into(s); __state=comment(':data_or_child',s); next
176
+ case
177
+ when __i==35; __state=comment(':data_or_child',s); next
178
+ when __i==124; __state=node(':data_or_child',s); next
177
179
  end
178
180
  when '{eof}'
179
181
  @fwd=true; b.into(a); a.into(s); return(s)
@@ -183,15 +185,18 @@ module UdonParser
183
185
  else __i.into(a); next
184
186
  end
185
187
  end
188
+ error("Unexpected \"#{[__i].pack("U*")}\"")
189
+ @fwd = true
190
+ return
186
191
  end
187
192
  end
188
193
 
189
- def comment(ns,p=nil,name='comment')
194
+ def comment(retstate,p=nil,name='comment')
190
195
  ibase=@indent+1
191
196
  ipar=@indent
192
197
  __state=':first:ws'
193
198
  s = UNode.new(:name=>name,:sline=>@line,:schr=>@pos)
194
- a ||= UString.new
199
+ a ||= ''
195
200
  loop do
196
201
  __i = nextchar
197
202
  __state = '{eof}' if __i==:eof
@@ -207,11 +212,11 @@ module UdonParser
207
212
  when (@indent>ibase); @fwd=true; __state=':data'; next
208
213
  when __i==9,space?; next
209
214
  when nl?; __i.into(a); a.into(s); next
210
- when (@indent<=ipar); @fwd=true; s.into(p); return(ns)
215
+ when (@indent<=ipar); @fwd=true; s.into(p); return(retstate)
211
216
  else __i.into(a); ibase=@indent; __state=':data'; next
212
217
  end
213
218
  when '{eof}'
214
- @fwd=true; a.into(s); s.into(p); return(ns)
219
+ @fwd=true; a.into(s); s.into(p); return(retstate)
215
220
  when ':data'
216
221
  case
217
222
  when nl?; a.into(s); __state=':nl'; next
@@ -221,5 +226,133 @@ module UdonParser
221
226
  end
222
227
  end
223
228
 
229
+ def node(retstate,p=nil,name='node')
230
+ ipar=@indent
231
+ __state=':ident'
232
+ s = UNode.new(:name=>name,:sline=>@line,:schr=>@pos)
233
+ a ||= ''
234
+ loop do
235
+ __i = nextchar
236
+ case __state
237
+ when ':ident:child:nl'
238
+ if !eof?
239
+ @fwd=true; error('nyi'); return(retstate)
240
+ end
241
+ when ':ident:child'
242
+ case
243
+ when (eof?); @fwd=true; a.into(s); s.into(p); return(retstate)
244
+ when nl?; __i.into(a); a.into(s); __state=':ident:child:nl'; next
245
+ when !eof?; __i.into(a); next
246
+ end
247
+ when ':ident:a_or_c'
248
+ case
249
+ when (eof?); @fwd=true; a.into(s.c.last); s.into(p); return(retstate)
250
+ when __i==58; a.reset!; s.c.pop.into(aname); __state=':ident:attr:val'; next
251
+ when __i==9,space?; __i.into(a); next
252
+ when nl?; __i.into(a); a.into(s.c.last); __state=':ident:nl'; next
253
+ when !eof?; __i.into(a); __state=':ident:child'; next
254
+ end
255
+ when ':ident'
256
+ case
257
+ when (eof?); @fwd=true; error('er1'); return(retstate)
258
+ when __i==9,space?; __state=':ident:nxt'; next
259
+ when nl?; __state=':ident:nl'; next
260
+ when (__i>45&&__i<48),__i==123; @fwd=true; __state=':ident:nxt'; next
261
+ when !eof?; @fwd=true; __state=cstr(':ident:nameret',s); next
262
+ end
263
+ when ':ident:attr:val'
264
+ if !eof?
265
+ @fwd=true; error('nyi'); return(retstate)
266
+ end
267
+ when ':ident:nxt'
268
+ case
269
+ when (eof?); @fwd=true; s.into(p); return(retstate)
270
+ when (__i>45&&__i<48),__i==123; error('nyi'); return(retstate)
271
+ when nl?; __state=':ident:nl'; next
272
+ when __i==9,space?; next
273
+ when !eof?; @fwd=true; __state=cstr(':ident:a_or_c',s); next
274
+ end
275
+ when ':ident:nameret'
276
+ @fwd=true; s.name.reset!; s.c.pop.into(s.name); __state=':ident:nxt'; next
277
+ when ':ident:nl'
278
+ case
279
+ when (eof?); @fwd=true; error('er3'); return(retstate)
280
+ when __i==9,space?; next
281
+ when nl?; next
282
+ when (@indent<=ipar); @fwd=true; s.into(p); return(retstate)
283
+ when !eof?; @fwd=true; ibase=@indent; __state=':ident:nxt'; next
284
+ end
285
+ end
286
+ error("Unexpected \"#{[__i].pack("U*")}\"")
287
+ @fwd = true
288
+ return
289
+ end
290
+ end
291
+
292
+ def cstr(retstate,p=nil,name='cstr')
293
+ __state=':first'
294
+ s = UArray.new
295
+ a ||= ''
296
+ b ||= ''
297
+ loop do
298
+ __i = nextchar
299
+ case __state
300
+ when ':bt-dat'
301
+ case
302
+ when __i==96; a.into!(p); return(retstate)
303
+ when !eof?; __i.into(a); next
304
+ end
305
+ when ':first'
306
+ case
307
+ when (eof?); @fwd=true; a.into!(p); return(retstate)
308
+ when __i==34; __state=':dq-dat'; next
309
+ when __i==39; __state=':sq-dat'; next
310
+ when __i==96; __state=':bt-dat'; next
311
+ when nl?,(__i>8&&__i<11),space?; @fwd=true; a.into!(p); return(retstate)
312
+ when !eof?; __i.into(a); __state=':dat'; next
313
+ end
314
+ when ':dq-dat:esc'
315
+ case
316
+ when __i==116; "\t".into(a); __state=':dq-dat'; next
317
+ when __i==110; "\n".into(a); __state=':dq-dat'; next
318
+ when __i==114; "\r".into(a); __state=':dq-dat'; next
319
+ when __i==102; "\f".into(a); __state=':dq-dat'; next
320
+ when __i==98; "\b".into(a); __state=':dq-dat'; next
321
+ when __i==97; "\a".into(a); __state=':dq-dat'; next
322
+ when __i==101; "\e".into(a); __state=':dq-dat'; next
323
+ when __i==115; "\s".into(a); __state=':dq-dat'; next
324
+ when !eof?; __i.into(a); __state=':dq-dat'; next
325
+ end
326
+ when ':sq-dat'
327
+ case
328
+ when __i==92; __state=':sq-dat:esc'; next
329
+ when __i==39; a.into!(p); return(retstate)
330
+ when !eof?; __i.into(a); next
331
+ end
332
+ when ':dq-dat'
333
+ case
334
+ when __i==92; __state=':dq-dat:esc'; next
335
+ when __i==34; a.into!(p); return(retstate)
336
+ when !eof?; __i.into(a); next
337
+ end
338
+ when ':sq-dat:esc'
339
+ case
340
+ when __i==92; __i.into(a); __state=':sq-dat'; next
341
+ when __i==39; __i.into(a); __state=':sq-dat'; next
342
+ when !eof?; __i.into(b); '\\'.into(a); b.into(a); __state=':sq-dat'; next
343
+ end
344
+ when ':dat'
345
+ case
346
+ when (eof?); @fwd=true; a.into!(p); return(retstate)
347
+ when nl?,(__i>8&&__i<11),space?; @fwd=true; a.into!(p); return(retstate)
348
+ when !eof?; __i.into(a); next
349
+ end
350
+ end
351
+ error("Unexpected \"#{[__i].pack("U*")}\"")
352
+ @fwd = true
353
+ return
354
+ end
355
+ end
356
+
224
357
  end
225
358
  end
@@ -4,20 +4,21 @@
4
4
  +-----------------+-----------------+-----+-----------------+------------------------+
5
5
  | :data_or_child | [\n] | | b>>a | :data |
6
6
  | :data_or_child | [ \t] | >>b | | :data_or_child |
7
- | :data_or_child | [#|] | | b>> | :child |
7
+ | :data_or_child | [#|] | | b>> ; a>>s | :child |
8
8
  | :data_or_child | . | | b>>a | :data |
9
9
  +-----------------+-----------------+-----+----------------+-------------------------+
10
10
  | :data | [\n] | >>a | a>>s | :data_or_child |
11
11
  | :data | . | >>a | | :data |
12
12
  +-----------------+-----------------+-----+----------------+-------------------------+
13
- | :child | [#] | >> | a>>s | comment(:data_or_child) |
13
+ | :child | [#] | >> | | comment(:data_or_child) |
14
+ | :child | [|] | >> | | node(:data_or_child) |
14
15
  | {eof} | | | b>>a; a>>s | <done> |
15
16
  +-----------------+-----------------+-----+----------------+-------------------------+
16
17
  # TODO: lots more children
17
18
 
18
19
  Block comments
19
20
  +-----------------+-----------------+-----+-----------------+------------------------+
20
- | comment(ns)::U | | | ibase=$indent+1 | :first:ws |
21
+ | comment(retstate)::U | | | ibase=$indent+1 | :first:ws |
21
22
  : : : : ipar=$indent : :
22
23
  +-----------------+-----------------+-----+-----------------+------------------------+
23
24
  | :first:ws | [ \t] | >> | ibase += 1 | :first:ws |
@@ -30,8 +31,91 @@
30
31
  | :nl | {$indent>ibase} | | | :data |
31
32
  | :nl | [ \t] | >> | | :nl |
32
33
  | :nl | [\n] | >>a | a>>s | :nl |
33
- | :nl | {$indent<=ipar} | | s>>p | <ns> |
34
+ | :nl | {$indent<=ipar} | | s>>p | <retstate> |
34
35
  | :nl | . | >>a | ibase=$indent | :data |
35
36
  +-----------------+-----------------+-----+----------------+-------------------------+
36
- | {eof} | | | a>>s; s>>p | <ns> |
37
+ | {eof} | | | a>>s; s>>p | <retstate> |
38
+ +-----------------+-----------------+-----+-----------------+------------------------+
39
+
40
+ Nodes
41
+ +-----------------+-----------------+-----+-----------------+------------------------+
42
+ | node(retstate)::U | | | ipar=$indent | :ident |
43
+ : : : : : :
44
+ +-----------------+-----------------+-----+-----------------+------------------------+
45
+ | :ident | {eof?} | | error('er1') | <retstate> |
46
+ | :ident | [ \t] | >> | | :ident:nxt |
47
+ | :ident | [\n] | >> | | :ident:nl |
48
+ | :ident | [./{] | | | :ident:nxt |
49
+ | :ident | . | | | cstr(:ident:nameret) |
50
+ | :ident:nameret | | | s.name>> | :ident:nxt |
51
+ : : : : s.c.pop>>s.name : :
52
+ +-----------------+-----------------+-----+-----------------+------------------------+
53
+ | :ident:nxt | {eof?} | | s>>p | <retstate> |
54
+ | :ident:nxt | [./{] | >> | error('nyi') | <retstate> |
55
+ | :ident:nxt | [\n] | >> | | :ident:nl |
56
+ | :ident:nxt | [ \t] | >> | | :ident:nxt |
57
+ | :ident:nxt | . | | | cstr(:ident:a_or_c) |
58
+ +-----------------+-----------------+-----+-----------------+------------------------+
59
+ | :ident:nl | {eof?} | | error('er3') | <retstate> |
60
+ | :ident:nl | [ \t] | >> | | :ident:nl |
61
+ | :ident:nl | [\n] | >> | | :ident:nl |
62
+ | :ident:nl | {$indent<=ipar} | | s>>p | <retstate> |
63
+ | :ident:nl | . | | ibase=$indent | :ident:nxt |
64
+ +-----------------+-----------------+-----+-----------------+------------------------+
65
+ | :ident:a_or_c | {eof?} | | a>>s.c.last | <retstate> |
66
+ : : : : s>>p : :
67
+ | :ident:a_or_c | [:] | >> | a>> | :ident:attr:val |
68
+ : : : : s.c.pop>>aname : :
69
+ | :ident:a_or_c | [ \t] | >>a | | :ident:a_or_c |
70
+ | :ident:a_or_c | [\n] | >>a | a>>s.c.last | :ident:nl | # was child
71
+ | :ident:a_or_c | . | >>a | | :ident:child |
72
+ +-----------------+-----------------+-----+-----------------+------------------------+
73
+ | :ident:child | {eof?} | | a>>s | <retstate> |
74
+ : : : : s>>p : :
75
+ | :ident:child | [\n] | >>a | a>>s | :ident:child:nl |
76
+ | :ident:child | . | >>a | | :ident:child |
77
+ +-----------------+-----------------+-----+-----------------+------------------------+
78
+ | :ident:child:nl | . | | error('nyi') | <retstate> |
79
+ | :ident:attr:val | . | | error('nyi') | <retstate> |
80
+ +-----------------+-----------------+-----+-----------------+------------------------+
81
+
82
+ Basic Control Strings
83
+ +-----------------+-----------------+-----+-----------------+------------------------+
84
+ | cstr(retstate) | | | | :first |
85
+ | :first | {eof?} | | a>>>p | <retstate> |
86
+ | :first | ["] | >> | | :dq-dat |
87
+ | :first | ['] | >> | | :sq-dat |
88
+ | :first | [`] | >> | | :bt-dat |
89
+ | :first | [ \t\n] | | a>>>p | <retstate> |
90
+ | :first | . | >>a | | :dat |
91
+ +-----------------+-----------------+-----+-----------------+------------------------+
92
+ | :dat | {eof?} | | a>>>p | <retstate> |
93
+ | :dat | [ \t\n] | | a>>>p | <retstate> |
94
+ | :dat | . | >>a | | :dat |
95
+ +-----------------+-----------------+-----+-----------------+------------------------+
96
+ | :dq-dat | [\\] | >> | | :dq-dat:esc |
97
+ | :dq-dat | ["] | >> | a>>>p | <retstate> |
98
+ | :dq-dat | . | >>a | | :dq-dat |
99
+ +-----------------+-----------------+-----+-----------------+------------------------+
100
+ # TODO: move these to a separate metachar function?
101
+ | :dq-dat:esc | [t] | >> | "\t">>a | :dq-dat |
102
+ | :dq-dat:esc | [n] | >> | "\n">>a | :dq-dat |
103
+ | :dq-dat:esc | [r] | >> | "\r">>a | :dq-dat |
104
+ | :dq-dat:esc | [f] | >> | "\f">>a | :dq-dat |
105
+ | :dq-dat:esc | [b] | >> | "\b">>a | :dq-dat |
106
+ | :dq-dat:esc | [a] | >> | "\a">>a | :dq-dat |
107
+ | :dq-dat:esc | [e] | >> | "\e">>a | :dq-dat |
108
+ | :dq-dat:esc | [s] | >> | "\s">>a | :dq-dat |
109
+ | :dq-dat:esc | . | >>a | | :dq-dat |
110
+ +-----------------+-----------------+-----+-----------------+------------------------+
111
+ | :sq-dat | [\\] | >> | | :sq-dat:esc |
112
+ | :sq-dat | ['] | >> | a>>>p | <retstate> |
113
+ | :sq-dat | . | >>a | | :sq-dat |
114
+ +-----------------+-----------------+-----+-----------------+------------------------+
115
+ | :sq-dat:esc | [\\] | >>a | | :sq-dat |
116
+ | :sq-dat:esc | ['] | >>a | | :sq-dat |
117
+ | :sq-dat:esc | . | >>b | '\\'>>a; b>>a | :sq-dat |
118
+ +-----------------+-----------------+-----+-----------------+------------------------+
119
+ | :bt-dat | [`] | >> | a>>>p | <retstate> |
120
+ | :bt-dat | . | >>a | | :bt-dat |
37
121
  +-----------------+-----------------+-----+-----------------+------------------------+
data/test/helper.rb CHANGED
@@ -39,7 +39,15 @@ def gaussian(mean, stddev)
39
39
  end
40
40
  end
41
41
 
42
- def randstr(avg_length, char_dists = [[0.1,' '],[0.1,('A'..'Z')],[0.8,('a'..'z')]])
42
+ def randstr(avg_length, char_dists = nil)
43
+ char_dists ||= [[0.10, " \t"],
44
+ [0.05, "\n\r"],
45
+ [0.40, ('a'..'z')],
46
+ [0.15, ('A'..'Z')],
47
+ [0.15, ('0'..'9')],
48
+ [0.075, (32..126)],
49
+ [0.05, (0..255)],
50
+ [0.025, (0..0xffff)]]
43
51
  ret = ''
44
52
  char_dists = char_dists.scan /./umn if char_dists.is_a?(String)
45
53
  chrs = char_dists.sort_by{|n|n[0]}
data/test/test_udon.rb CHANGED
@@ -2,45 +2,145 @@ require 'helper'
2
2
  $KCODE='U'
3
3
 
4
4
  class TestUdon < MiniTest::Unit::TestCase
5
+ TRIGGER_UDON = /(^\s*(#|\||<).*$|<\||<:)/u
6
+ WHITESPACE = " \t\n\r"
7
+
5
8
  def test_blank_documents
6
- assert_equal(''.udon,[])
9
+ ##############
10
+ assert_equal [], ''.udon
11
+ ##############
7
12
  (0..3).each do
8
- s = randstr(200," \t\n\r")
9
- assert_equal(s,s.udon.join(''))
13
+ s = randstr(200,WHITESPACE)
14
+ ##############
15
+ assert_equal s, s.udon.join('')
16
+ ##############
10
17
  end
11
18
  end
12
19
 
13
- def test_passthrough_documents
14
- chars = [[0.10, " \t"],
15
- [0.05, "\n\r"],
16
- [0.40, ('a'..'z')],
17
- [0.15, ('A'..'Z')],
18
- [0.15, ('0'..'9')],
19
- [0.075, (32..126)],
20
- [0.05, (0..255)],
21
- [0.025, (0..0xffff)]]
20
+ def test_passthru_documents
22
21
  (0..3).each do
23
- s = randstr(100,chars)
24
- s.gsub! /^\s*(<\||#|\|)/u, '' # Remove stuff that triggers udon mode
25
- assert_equal(s,s.udon.join(''))
22
+ s = randstr(100).gsub(TRIGGER_UDON,'')
23
+ ##############
24
+ assert_equal s, s.udon.join('')
25
+ ##############
26
26
  end
27
27
  end
28
28
 
29
- def test_block_comment_indent_level
30
- leading = randstr(200," \t\n\r") + "\n"
29
+ def test_only_block_comment
30
+ ##############
31
+ assert_equal '#hi'.udon[0].name, 'comment'
32
+ assert_equal '#hi'.udon[0].c[0], 'hi'
33
+ assert_equal '# hi'.udon[0].c[0], 'hi'
34
+ ##############
35
+ end
36
+
37
+ def test_block_comment_indent_level_with_leading
38
+ leading = randstr(200,WHITESPACE) + "\n"
39
+ following = randstr(200,WHITESPACE)
31
40
  comment = <<-COMMENT
32
- # line 1
33
- line 2
34
- line 3
41
+ # line 0
42
+ line 1
43
+ line 2
44
+
35
45
  line 4
46
+
47
+ # comment 2
36
48
  COMMENT
37
- following = randstr(200," \t\n\r")
38
- s = (leading + comment + following)
39
- r = s.udon
40
- assert_instance_of(UdonParser::UNode, r.last)
41
- assert_equal('line 1', r.last.c[0])
42
- assert_equal('line 2', r.last.c[1])
43
- assert_equal('line 3', r.last.c[2])
44
- assert_equal('line 4', r.last.c[3])
49
+ r = (leading + comment + following).udon
50
+ lines = r[-2].c
51
+ ##############
52
+ assert_instance_of UdonParser::UNode, r[-2]
53
+ assert_equal 'comment', r[-2].name
54
+ assert_equal 'line 0', lines[0]
55
+ assert_equal 'line 1', lines[1]
56
+ assert_equal 'line 2', lines[2]
57
+ assert_equal "\n", lines[3]
58
+ assert_equal 'line 4', lines[4]
59
+ assert_instance_of UdonParser::UNode, r[-1]
60
+ assert_equal 'comment', r[-1].name
61
+ ##############
62
+ end
63
+
64
+ def test_block_comment_in_passthru
65
+ leading = randstr(200).gsub(TRIGGER_UDON,'') + "\n"
66
+ following = randstr(200).gsub(TRIGGER_UDON,'')
67
+ comment = <<-COMMENT
68
+ # the-comment
69
+ and back to normal
70
+ COMMENT
71
+ r = (leading + comment + following).udon
72
+ # Find the comment
73
+ found_i = nil
74
+ r.each_with_index{|c,i| if c.is_a?(UdonParser::UNode) then found_i=i; break end}
75
+ ##############
76
+ refute_nil found_i
77
+ assert found_i < r.size
78
+ assert found_i > 0
79
+ assert_equal 'comment', r[found_i].name
80
+ assert_equal leading, r[0..(found_i-1)].join('')
81
+ assert_equal following, r[(found_i+2)..-1].join('')
82
+ ##############
83
+ end
84
+
85
+ def test_simple_node
86
+ r = "asdf\n|the-node\nasdf".udon
87
+ ##############
88
+ assert_instance_of UdonParser::UNode, r[1]
89
+ assert_equal 'the-node', r[1].name
90
+ assert_equal "asdf\n", r[0]
91
+ assert_equal "asdf", r[2]
92
+ ##############
93
+ end
94
+
95
+ def test_node_name
96
+ ##############
97
+ assert_equal 'hello-there!', '|hello-there!'.udon[0].name
98
+ assert_equal "hello there!\t", '|"hello there!\t"'.udon[0].name
99
+ assert_equal 'hello there!\t', "|'hello there!\\t'".udon[0].name
100
+ assert_equal 'hello there!\t', '|`hello there!\t`'.udon[0].name
101
+ ##############
102
+ end
103
+
104
+ def test_node_name_with_inline_children
105
+ ##############
106
+ assert_equal 'hello-there!', '|hello-there! c'.udon[0].name
107
+ assert_equal "hello there!\t", '|"hello there!\t" c'.udon[0].name
108
+ assert_equal 'hello there!\t', "|'hello there!\\t' c".udon[0].name
109
+ assert_equal 'hello there!\t', '|`hello there!\t` c'.udon[0].name
110
+ ##############
45
111
  end
112
+
113
+ def test_node_name_with_nextline_children
114
+ ##############
115
+ assert_equal 'hello-there!', "|hello-there!\nc".udon[0].name
116
+ assert_equal "hello there!\t", "|\"hello there!\\t\"\nc".udon[0].name
117
+ assert_equal 'hello there!\t', "|'hello there!\\t'\nc".udon[0].name
118
+ assert_equal 'hello there!\t', "|`hello there!\\t`\nc".udon[0].name
119
+ ##############
120
+ end
121
+
122
+ SCRATCH=<<-SCRATCH
123
+
124
+ |one # Sets ipar
125
+ a:b # no base
126
+ c:d # no base
127
+ e:f # no base
128
+ g h i # sets base to indent
129
+
130
+ |one blah # Sets ipar to indent
131
+ asdf # sets base to indent
132
+
133
+ # SO: first non-ident non-inline child sets base (or its own ipar)
134
+
135
+
136
+
137
+ |asdf
138
+ `howdy fejw ioafj weifj <:oawj:> fa weoi`: kvjjfejiwo
139
+ `howdy fejw ioafj weifj <:oawj:> fa weoi` kvjjfejiwo
140
+
141
+
142
+
143
+
144
+ SCRATCH
145
+
46
146
  end
data/udon.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{udon}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joseph Wecker"]
12
- s.date = %q{2011-08-19}
12
+ s.date = %q{2011-08-20}
13
13
  s.description = %q{Parse and generate udon, inspired by zml, haml, json, and more.}
14
14
  s.email = %q{joseph.wecker@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.add_development_dependency(%q<rcov>, [">= 0"])
48
48
  s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
49
49
  s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
50
- s.add_development_dependency(%q<genmachine>, ["~> 0.2.1"])
50
+ s.add_development_dependency(%q<genmachine>, ["~> 0.2.2"])
51
51
  else
52
52
  s.add_dependency(%q<minitest>, [">= 0"])
53
53
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
55
55
  s.add_dependency(%q<rcov>, [">= 0"])
56
56
  s.add_dependency(%q<reek>, ["~> 1.2.8"])
57
57
  s.add_dependency(%q<roodi>, ["~> 2.1.0"])
58
- s.add_dependency(%q<genmachine>, ["~> 0.2.1"])
58
+ s.add_dependency(%q<genmachine>, ["~> 0.2.2"])
59
59
  end
60
60
  else
61
61
  s.add_dependency(%q<minitest>, [">= 0"])
@@ -64,7 +64,7 @@ Gem::Specification.new do |s|
64
64
  s.add_dependency(%q<rcov>, [">= 0"])
65
65
  s.add_dependency(%q<reek>, ["~> 1.2.8"])
66
66
  s.add_dependency(%q<roodi>, ["~> 2.1.0"])
67
- s.add_dependency(%q<genmachine>, ["~> 0.2.1"])
67
+ s.add_dependency(%q<genmachine>, ["~> 0.2.2"])
68
68
  end
69
69
  end
70
70
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joseph Wecker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-19 00:00:00 -07:00
18
+ date: 2011-08-20 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,12 +116,12 @@ dependencies:
116
116
  requirements:
117
117
  - - ~>
118
118
  - !ruby/object:Gem::Version
119
- hash: 21
119
+ hash: 19
120
120
  segments:
121
121
  - 0
122
122
  - 2
123
- - 1
124
- version: 0.2.1
123
+ - 2
124
+ version: 0.2.2
125
125
  name: genmachine
126
126
  version_requirements: *id007
127
127
  prerelease: false