@@ -51,15 +51,14 @@ def sort_and_check(arr, label)
51
51
52
52
File . open ( "index.md" ) do |f |
53
53
state = :header
54
- libraries = [ ]
55
- software = [ ]
56
- non_believers = [ ]
54
+ groups = { :libraries => [ ] , :software => [ ] , :non_believers => [ ] }
57
55
lc = 0
58
56
fails = false
59
57
60
58
while f && !f . eof?
61
59
line = f . gets
62
60
lc += 1
61
+ descr = nil
63
62
64
63
case state
65
64
when :header , :header_2 , :header_3
@@ -70,43 +69,50 @@ def sort_and_check(arr, label)
70
69
if line . match ( /^\{ : rules/ )
71
70
state = next_state ( state )
72
71
else
72
+ parts = [ ]
73
+ if m = line . match ( /^\| (.+) \| $/ )
74
+ parts = m [ 1 ] . split ( / \| / ) . flatten
75
+ end
76
+
73
77
if state == :non_believers
74
- if ! line . match ( /^ \| [^ \| ]+ \| [^ \| ]+ \| $/ )
78
+ if parts . count != 2
75
79
puts "Line #{ lc } does not match format | |" , line
76
80
fails = true
77
81
end
78
82
elsif state == :libraries
79
- if !line . match ( /^\| [^\| ]+ \| [^\| ]+ \| [^\| ]+ \| [^\| ]+ \| $/ )
83
+ if parts . count == 4
84
+ descr = parts [ 2 ]
85
+ else
80
86
puts "Line #{ lc } does not match format | | | |" , line
81
87
fails = true
82
88
end
83
- else
84
- if !line . match ( /^\| [^\| ]+ \| [^\| ]+ \| [^\| ]+ \| $/ )
89
+ elsif state == :software
90
+ if parts . count == 3
91
+ descr = parts [ 1 ]
92
+ else
85
93
puts "Line #{ lc } does not match format | | |" , line
86
94
fails = true
87
95
end
96
+ else
97
+ raise "invalid state #{ state } "
88
98
end
89
99
90
- case state
91
- when :libraries
92
- libraries . push line
93
- when :software
94
- software . push line
95
- when :non_believers
96
- non_believers . push line
97
- else
98
- raise "bogus state?"
100
+ if descr . to_s . match ( /[.!]$/ )
101
+ puts "Line #{ lc } description has trailing punctuation" , line
102
+ fails = true
99
103
end
104
+
105
+ groups [ state ] . push line
100
106
end
101
107
when :trailer
102
108
puts "Trailing junk at the end of the file on line #{ lc } : #{ line . inspect } "
103
109
fails = true
104
110
end
105
111
end
106
112
107
- fails |= !sort_and_check ( libraries , "Library" )
108
- fails |= !sort_and_check ( software , "Software" )
109
- fails |= !sort_and_check ( non_believers , "Non-supporting software" )
113
+ fails |= !sort_and_check ( groups [ : libraries] , "Library" )
114
+ fails |= !sort_and_check ( groups [ : software] , "Software" )
115
+ fails |= !sort_and_check ( groups [ : non_believers] , "Non-supporting software" )
110
116
111
117
if fails
112
118
exit 1
0 commit comments