pseudohikiparser 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7908f80b410e064b7380cee7982c351257e578cd
4
- data.tar.gz: 193bb4b76c97e2936a87f1f6da83cbc42ee788db
3
+ metadata.gz: b6aeacee81ab200ae29767f62343c2c8c3b6383b
4
+ data.tar.gz: 29c8d6ef7d5546530c0836173b503346c1270f97
5
5
  SHA512:
6
- metadata.gz: 02659c1d1e708819e9b1ed50cf65a89c348ff2c92a840daee52bb8e32d70dd0c6b4af2ab8a090ecce06557811274a9f763fec897da174193603421de3e736ff8
7
- data.tar.gz: 24e068590d29996d995de41bac263451a4eb994d1241a61d27626934914ad59de3286466b0c135ac7cf634ac220c984800574efa59124d712a7beb4f9bbf717d
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
- head_pats, leaf_types = [], [:entire_matched_part]
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
- head_pats.push "(#{escaped_head})"
312
- leaf_types.push leaf
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
- return Regexp.new('\\A(?:'+head_pats.join('|')+')'), leaf_types, leaf_types.length - 1
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
- LEAF_HEAD_PAT, NOT_PARAGRAPH_LEAF_TYPES, NUMBER_OF_NOT_PARAGRAPH_LEAF_TYPES = assign_head_re
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 = LEAF_HEAD_PAT.match(line)
333
- return ParagraphLeaf unless matched
334
- 1.upto(NUMBER_OF_NOT_PARAGRAPH_LEAF_TYPES) {|i| return NOT_PARAGRAPH_LEAF_TYPES[i] if matched[i] }
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)
@@ -1,3 +1,3 @@
1
1
  module PseudoHiki
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki