slaw 1.0.0.alpha.1 → 1.0.0.alpha.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: e5c6f9929b92711f0a7c608387b49784c8c0198c
4
- data.tar.gz: 7557e00919085931eae2ce9195bbe55342a50c9c
3
+ metadata.gz: 16495306529339f9897fda3092e402d15a8df8ef
4
+ data.tar.gz: e3536947fd47ad3844fab512041e2b08bf615433
5
5
  SHA512:
6
- metadata.gz: 386d5e7195f18838c00af784a46792f349913ac5fe07f7799e4e3055fd6720da3e1dcb6b2e10b93d14e2519758eecdd4b46fe31ceecf2bf10b707cf51f6e93dd
7
- data.tar.gz: 73aa8a5060a8933a09bec8ebac589aeb835de216a76f7865f9bf5883eb89ab347117c648eda8e806eaa668d4f9c1ce7eefeb4bd9dd678abbcb1a200986d98063
6
+ metadata.gz: 933bfcd5b5f762769d233fe5cb9786eb5f2d5b4e7570cd563ee9d64e787b0a22ad4db60b099d6c334559b61b24d48627b9368757cfb6e3ba169d429bb1884b7a
7
+ data.tar.gz: ae80c3eb1c3d2b7d9b46ec3eea15c294f24c1f58569546548133cc609977f59c0314ef4e0cc7ec8538ebc7d67d1a7b8c2cc2f9cbe8ca4ae919594a5b03a84dd1
@@ -37,62 +37,72 @@ module Slaw
37
37
  end
38
38
 
39
39
  rule body
40
- children:(division / subdivision / chapter / article / section / paragraph / point / litera / block_paragraphs)+ <Body>
40
+ children:(division / subdivision / chapter / article / section / paragraph / point / litera / indents / block_paragraphs)+ <Body>
41
41
  end
42
42
 
43
43
  rule division
44
44
  heading:division_heading
45
- children:(subdivision / chapter / article / section / paragraph / point / litera / block_paragraphs)*
45
+ children:(subdivision / chapter / article / section / paragraph / point / litera / indents / block_paragraphs)*
46
46
  <Division>
47
47
  end
48
48
 
49
49
  rule subdivision
50
50
  heading:subdivision_heading
51
- children:(chapter / article / section / paragraph / point / litera / block_paragraphs)*
51
+ children:(chapter / article / section / paragraph / point / litera / indents / block_paragraphs)*
52
52
  <Subdivision>
53
53
  end
54
54
 
55
55
  rule chapter
56
56
  heading:chapter_heading
57
- children:(article / section / paragraph / point / litera / block_paragraphs)*
57
+ children:(article / section / paragraph / point / litera / indents / block_paragraphs)*
58
58
  <Chapter>
59
59
  end
60
60
 
61
61
  rule article
62
62
  # Art. 55. 1. something
63
63
  article_prefix whitespace
64
- intro:block_element? eol?
65
- children:(section / paragraph / point / litera / block_paragraphs)* <Article>
64
+ intro:block_element?
65
+ children:(section / paragraph / point / litera / indents / block_paragraphs)* <Article>
66
66
  end
67
67
 
68
68
  rule section
69
69
  # § 55. foo
70
70
  section_prefix whitespace
71
- intro:block_element? eol?
72
- children:(paragraph / point / litera / block_paragraphs)* <Section>
71
+ intro:block_element?
72
+ children:(paragraph / point / litera / indents / block_paragraphs)* <Section>
73
73
  end
74
74
 
75
75
  rule paragraph
76
76
  # ustęp:
77
77
  # 34. ...
78
- paragraph_prefix space?
79
- intro:block_element? eol?
80
- children:(point / litera / block_paragraphs)* <Paragraph>
78
+ paragraph_prefix whitespace
79
+ intro:block_element?
80
+ children:(point / litera / indents / block_paragraphs)* <Paragraph>
81
81
  end
82
82
 
83
83
  rule point
84
84
  # 12) aoeuaoeu
85
85
  # 12a) aoeuaoeu
86
86
  point_prefix whitespace
87
- intro:block_element? eol?
88
- children:(litera / block_paragraphs)* <Point>
87
+ intro:block_element?
88
+ children:(litera / indents / block_paragraphs)* <Point>
89
89
  end
90
90
 
91
91
  rule litera
92
92
  # a) aoeuaoeu
93
93
  litera_prefix whitespace
94
- intro:block_element? eol?
95
- children:block_paragraphs* <Litera>
94
+ intro:block_element?
95
+ children:(indents / block_paragraphs)* <Litera>
96
+ end
97
+
98
+ rule indents
99
+ # - foo
100
+ # - bar
101
+ children:indent_item+ <Indents>
102
+ end
103
+
104
+ rule indent_item
105
+ indent_prefix item_content:inline_block_element? eol? <IndentItem>
96
106
  end
97
107
 
98
108
  ##########
@@ -155,29 +165,13 @@ module Slaw
155
165
  end
156
166
 
157
167
  rule block_element
158
- # XXX: blocklist
159
- (table / naked_statement)
168
+ table / naked_statement
160
169
  end
161
170
 
162
171
  # Block elements that don't have to appear at the start of a line.
163
172
  # ie. we don't need to guard against the start of a chapter, section, etc.
164
173
  rule inline_block_element
165
- # XXX: blocklist
166
- (table / inline_statement)
167
- end
168
-
169
- rule blocklist
170
- blocklist_item+ <Blocklist>
171
- end
172
-
173
- rule blocklist_item
174
- # TODO: this whitespace should probably be space, to allow empty blocklist items followed by plain text
175
- space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix clauses:clauses? eol)? eol?
176
- <BlocklistItem>
177
- end
178
-
179
- rule blocklist_item_prefix
180
- ('(' letter_ordinal ')') / dotted_number_3
174
+ table / inline_statement
181
175
  end
182
176
 
183
177
  ##########
@@ -187,7 +181,7 @@ module Slaw
187
181
  # and is ignored. This allows escaping of section headings, etc.
188
182
 
189
183
  rule naked_statement
190
- space? !(division_heading / subdivision_heading / chapter_heading / article_prefix / section_prefix / schedule_title / paragraph_prefix / point_prefix / litera_prefix) '\\'? clauses eol
184
+ space? !(division_heading / subdivision_heading / chapter_heading / article_prefix / section_prefix / schedule_title / paragraph_prefix / point_prefix / litera_prefix / indent_prefix) '\\'? clauses eol
191
185
  <NakedStatement>
192
186
  end
193
187
 
@@ -235,6 +229,10 @@ module Slaw
235
229
  letters:letter+ ')'
236
230
  end
237
231
 
232
+ rule indent_prefix
233
+ '-' space
234
+ end
235
+
238
236
  include Slaw::Grammars::Inlines
239
237
  include Slaw::Grammars::Tables
240
238
  include Slaw::Grammars::Schedules
@@ -339,31 +339,30 @@ module Slaw
339
339
  end
340
340
  end
341
341
 
342
- class Blocklist < Treetop::Runtime::SyntaxNode
343
- # Render a block list to xml. If a block is given,
344
- # yield to it a builder to insert a listIntroduction node
345
- def to_xml(b, idprefix, i=0, &block)
346
- id = idprefix + "list#{i}"
342
+ class Indents < Treetop::Runtime::SyntaxNode
343
+ # Render a list of indent items.
344
+ def to_xml(b, idprefix, i=0)
345
+ id = idprefix + "list-#{i}"
347
346
  idprefix = id + '.'
348
347
 
349
- b.blockList(id: id) { |b|
350
- b.listIntroduction { |b| yield b } if block_given?
351
-
352
- elements.each { |e| e.to_xml(b, idprefix) }
348
+ b.list(id: id) { |b|
349
+ children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
353
350
  }
354
351
  end
355
352
  end
356
353
 
357
- class BlocklistItem < Treetop::Runtime::SyntaxNode
358
- def num
359
- blocklist_item_prefix.text_value
360
- end
354
+ class IndentItem < Treetop::Runtime::SyntaxNode
355
+ def to_xml(b, idprefix, i)
356
+ id = idprefix + "indent-#{i}"
357
+ idprefix = id + '.'
361
358
 
362
- def to_xml(b, idprefix)
363
- b.item(id: idprefix + num.gsub(/[()]/, '')) { |b|
364
- b.num(num)
365
- b.p { |b|
366
- item_content.clauses.to_xml(b, idprefix) if respond_to? :item_content and item_content.respond_to? :clauses
359
+ b.indent(id: id) { |b|
360
+ b.content { |b|
361
+ if not item_content.empty?
362
+ item_content.to_xml(b, idprefix)
363
+ else
364
+ b.p
365
+ end
367
366
  }
368
367
  }
369
368
  end
@@ -47,7 +47,8 @@ module Slaw
47
47
  def scrub(s)
48
48
  # we often get this unicode codepoint in the string, nuke it
49
49
  s.gsub([65532].pack('U*'), '')\
50
- .gsub(/\n* /, '')
50
+ .gsub(/\n* /, '')\
51
+ .gsub(/–/, '-')
51
52
  end
52
53
 
53
54
  # change weird quotes to normal ones
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "1.0.0.alpha.1"
2
+ VERSION = "1.0.0.alpha.2"
3
3
  end
@@ -446,4 +446,119 @@ EOS
446
446
  end
447
447
  end
448
448
 
449
+ #-------------------------------------------------------------------------------
450
+ # Litera
451
+
452
+ describe 'litera' do
453
+
454
+ it 'should handle litera with indents' do
455
+ node = parse :litera, <<EOS
456
+ b) liczby:
457
+ - tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,
458
+ - mieszkań chronionych,
459
+ - lokali mieszkalnych powstających z udziałem gminy albo związku międzygminnego w wyniku realizacji przedsięwzięć, o których mowa w art. 5 ust. 1 i art. 5a ust. 1 ustawy,
460
+ - tymczasowych pomieszczeń,
461
+ - miejsc w noclegowniach, schroniskach dla bezdomnych i ogrzewalniach,
462
+ EOS
463
+ to_xml(node, 'prefix.', 0).should == '<list id="prefix.list-b">
464
+ <num>b)</num>
465
+ <intro>
466
+ <p>liczby:</p>
467
+ </intro>
468
+ <list id="prefix.list-b.list-0">
469
+ <indent id="prefix.list-b.list-0.indent-0">
470
+ <content>
471
+ <p>tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,</p>
472
+ </content>
473
+ </indent>
474
+ <indent id="prefix.list-b.list-0.indent-1">
475
+ <content>
476
+ <p>mieszkań chronionych,</p>
477
+ </content>
478
+ </indent>
479
+ <indent id="prefix.list-b.list-0.indent-2">
480
+ <content>
481
+ <p>lokali mieszkalnych powstających z udziałem gminy albo związku międzygminnego w wyniku realizacji przedsięwzięć, o których mowa w art. 5 ust. 1 i art. 5a ust. 1 ustawy,</p>
482
+ </content>
483
+ </indent>
484
+ <indent id="prefix.list-b.list-0.indent-3">
485
+ <content>
486
+ <p>tymczasowych pomieszczeń,</p>
487
+ </content>
488
+ </indent>
489
+ <indent id="prefix.list-b.list-0.indent-4">
490
+ <content>
491
+ <p>miejsc w noclegowniach, schroniskach dla bezdomnych i ogrzewalniach,</p>
492
+ </content>
493
+ </indent>
494
+ </list>
495
+ </list>'
496
+ end
497
+ end
498
+
499
+ #-------------------------------------------------------------------------------
500
+ # Indent
501
+
502
+ describe 'indent' do
503
+ it 'should handle basic indent' do
504
+ node = parse :indents, <<EOS
505
+ - tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,
506
+ EOS
507
+
508
+ to_xml(node, 'prefix.', 0).should == '<list id="prefix.list-0">
509
+ <indent id="prefix.list-0.indent-0">
510
+ <content>
511
+ <p>tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,</p>
512
+ </content>
513
+ </indent>
514
+ </list>'
515
+ end
516
+
517
+ it 'should handle empty indents' do
518
+ node = parse :indents, <<EOS
519
+ -
520
+ -
521
+ EOS
522
+
523
+ to_xml(node, 'prefix.', 0).should == '<list id="prefix.list-0">
524
+ <indent id="prefix.list-0.indent-0">
525
+ <content>
526
+ <p/>
527
+ </content>
528
+ </indent>
529
+ <indent id="prefix.list-0.indent-1">
530
+ <content>
531
+ <p/>
532
+ </content>
533
+ </indent>
534
+ </list>'
535
+ end
536
+
537
+ it 'should handle multiple indent items' do
538
+ node = parse :indents, <<EOS
539
+ - tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,
540
+ - mieszkań chronionych,
541
+ - lokali mieszkalnych powstających z udziałem gminy albo związku międzygminnego w wyniku realizacji przedsięwzięć, o których mowa w art. 5 ust. 1 i art. 5a ust. 1 ustawy,
542
+ EOS
543
+
544
+ to_xml(node, 'prefix.', 0).should == '<list id="prefix.list-0">
545
+ <indent id="prefix.list-0.indent-0">
546
+ <content>
547
+ <p>tworzonych lokali wchodzących w skład mieszkaniowego zasobu gminy,</p>
548
+ </content>
549
+ </indent>
550
+ <indent id="prefix.list-0.indent-1">
551
+ <content>
552
+ <p>mieszkań chronionych,</p>
553
+ </content>
554
+ </indent>
555
+ <indent id="prefix.list-0.indent-2">
556
+ <content>
557
+ <p>lokali mieszkalnych powstających z udziałem gminy albo związku międzygminnego w wyniku realizacji przedsięwzięć, o których mowa w art. 5 ust. 1 i art. 5a ust. 1 ustawy,</p>
558
+ </content>
559
+ </indent>
560
+ </list>'
561
+ end
562
+ end
563
+
449
564
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.1
4
+ version: 1.0.0.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Kempe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler