pseudohikiparser 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pseudohiki/blockparser.rb +15 -12
- data/lib/pseudohiki/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6aeacee81ab200ae29767f62343c2c8c3b6383b
|
4
|
+
data.tar.gz: 29c8d6ef7d5546530c0836173b503346c1270f97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e0df31b3ca4d2e347f9ef841f0c86c13bb8398f477f2d2b85fc6185ab9ce54c7ba0420bfa09ebb7e30d12baa26da76f3d8557e90c0df2fda7ed62114efd53c
|
7
|
+
data.tar.gz: abf97289e38d87b669af8ee08a7076fd72f684bab2115be9aef9dbf7512b076fe90c95d0392408cf255c3e1482abe08bc952b8d6ce7af96da21fc4557e97dc23
|
@@ -293,28 +293,30 @@ module PseudoHiki
|
|
293
293
|
|
294
294
|
def self.assign_head_re
|
295
295
|
irregular_leafs = [BlockNodeEnd, VerbatimLeaf, HrLeaf]
|
296
|
-
|
296
|
+
irregular_head_pats, regular_leaf_types, head_to_leaf = [], [], {}
|
297
297
|
[['\r?\n?$', BlockNodeEnd],
|
298
|
-
[':', DescLeaf],
|
299
298
|
['\s', VerbatimLeaf],
|
299
|
+
['*', ListLeaf],
|
300
|
+
['#', EnumLeaf],
|
301
|
+
[':', DescLeaf],
|
302
|
+
['!', HeadingLeaf],
|
300
303
|
['""', QuoteLeaf],
|
301
304
|
['||', TableLeaf],
|
302
305
|
['//', CommentOutLeaf],
|
303
|
-
['!', HeadingLeaf],
|
304
|
-
['*', ListLeaf],
|
305
|
-
['#', EnumLeaf],
|
306
306
|
['----\s*$', HrLeaf]
|
307
307
|
].each do |head, leaf|
|
308
308
|
escaped_head = irregular_leafs.include?(leaf) ? head : Regexp.escape(head)
|
309
309
|
head_pat = leaf.with_depth? ? "#{escaped_head}+" : "#{escaped_head}"
|
310
310
|
leaf.head_re = Regexp.new('\\A'+head_pat)
|
311
|
-
|
312
|
-
|
311
|
+
head_to_leaf[head] = leaf
|
312
|
+
irregular_head_pats.push "(#{escaped_head})" if irregular_leafs.include?(leaf)
|
313
|
+
regular_leaf_types.push head unless irregular_leafs.include?(leaf)
|
313
314
|
end
|
314
|
-
|
315
|
+
irregular_leaf_types = [:entire_matched_part].concat(irregular_leafs)
|
316
|
+
return Regexp.new('\\A(?:'+irregular_head_pats.join('|')+')'), regular_leaf_types, head_to_leaf, irregular_leaf_types, irregular_leafs.length
|
315
317
|
end
|
316
318
|
|
317
|
-
|
319
|
+
IRREGULAR_HEAD_PAT, REGULAR_LEAF_TYPES, HEAD_TO_LEAF, IRREGULAR_LEAF_TYPES, NUMBER_OF_IRREGULAR_LEAF_TYPES = assign_head_re
|
318
320
|
|
319
321
|
def initialize
|
320
322
|
root_node = BlockNode.new
|
@@ -329,9 +331,10 @@ module PseudoHiki
|
|
329
331
|
end
|
330
332
|
|
331
333
|
def select_leaf_type(line)
|
332
|
-
matched =
|
333
|
-
return
|
334
|
-
|
334
|
+
matched = IRREGULAR_HEAD_PAT.match(line)
|
335
|
+
1.upto(NUMBER_OF_IRREGULAR_LEAF_TYPES) {|i| return IRREGULAR_LEAF_TYPES[i] if matched[i] } if matched
|
336
|
+
REGULAR_LEAF_TYPES.each {|head| return HEAD_TO_LEAF[head] if line.start_with?(head) }
|
337
|
+
ParagraphLeaf
|
335
338
|
end
|
336
339
|
|
337
340
|
def read_lines(lines)
|
data/lib/pseudohiki/version.rb
CHANGED