@@ -23,13 +23,16 @@ for (const filename of filenames) {
23
23
{
24
24
// Is it an algorithm definition?
25
25
const matches = line . match ( / ^ ( [ a - z 0 - 9 A - Z ] + ) ( \s * ) \( ( [ ^ ) ] * ) \) ( \s * ) : ( \s * ) $ / ) ;
26
+ const grammarMatches =
27
+ filename === "Section 2 -- Language.md" &&
28
+ line . match ( / ^ ( [ A - Z a - z 0 - 9 ] + ) : \s + ( ( \S ) .* ) $ / ) ;
26
29
if ( matches ) {
27
30
const [ , algorithmName , ns1 , _args , ns2 , ns3 ] = matches ;
28
31
if ( ns1 || ns2 || ns3 ) {
29
32
console . log (
30
33
`Bad whitespace in definition of ${ algorithmName } in '${ filename } ':`
31
34
) ;
32
- console . log ( line ) ;
35
+ console . dir ( line ) ;
33
36
console . log ( ) ;
34
37
process . exitCode = 1 ;
35
38
}
@@ -47,7 +50,7 @@ for (const filename of filenames) {
47
50
console . log (
48
51
`Bad algorithm ${ algorithmName } step in '${ filename } ':`
49
52
) ;
50
- console . log ( step ) ;
53
+ console . dir ( step ) ;
51
54
console . log ( ) ;
52
55
process . exitCode = 1 ;
53
56
}
@@ -57,15 +60,15 @@ for (const filename of filenames) {
57
60
console . log (
58
61
`Bad formatting for '${ algorithmName } ' step (does not end in '.' or ':') in '${ filename } ':`
59
62
) ;
60
- console . log ( step ) ;
63
+ console . dir ( step ) ;
61
64
console . log ( ) ;
62
65
process . exitCode = 1 ;
63
66
}
64
67
if ( step . match ( / ^ \s * ( - | [ 0 - 9 ] \. ) \s + [ a - z ] / ) ) {
65
68
console . log (
66
69
`Bad formatting of '${ algorithmName } ' step (should start with a capital) in '${ filename } ':`
67
70
) ;
68
- console . log ( step ) ;
71
+ console . dir ( step ) ;
69
72
console . log ( ) ;
70
73
process . exitCode = 1 ;
71
74
}
@@ -79,7 +82,67 @@ for (const filename of filenames) {
79
82
console . log (
80
83
`Potential bad formatting of '${ algorithmName } ' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${ filename } ':`
81
84
) ;
82
- console . log ( step ) ;
85
+ console . dir ( step ) ;
86
+ console . log ( ) ;
87
+ process . exitCode = 1 ;
88
+ }
89
+ }
90
+ } else if ( grammarMatches ) {
91
+ // This is super loosey-goosey
92
+ const [ , grammarName , rest ] = grammarMatches ;
93
+ if ( rest . trim ( ) === "one of" ) {
94
+ // Still grammar, not algorithm
95
+ continue ;
96
+ }
97
+ if ( rest . trim ( ) === "" && lines [ i + 1 ] !== "" ) {
98
+ console . log (
99
+ `No empty space after grammar ${ grammarName } header in '${ filename } '`
100
+ ) ;
101
+ console . log ( ) ;
102
+ process . exitCode = 1 ;
103
+ }
104
+ if ( ! lines [ i + 2 ] . startsWith ( "- " ) ) {
105
+ // Not an algorithm; probably more grammar
106
+ continue ;
107
+ }
108
+ for ( let j = i + 2 ; j < l ; j ++ ) {
109
+ const step = lines [ j ] ;
110
+ if ( ! step . match ( / ^ \s * ( - | [ 0 - 9 ] + \. ) / ) ) {
111
+ if ( step !== "" ) {
112
+ console . log ( `Bad grammar ${ grammarName } step in '${ filename } ':` ) ;
113
+ console . dir ( step ) ;
114
+ console . log ( ) ;
115
+ process . exitCode = 1 ;
116
+ }
117
+ break ;
118
+ }
119
+ if ( ! step . match ( / [ . : ] $ / ) ) {
120
+ console . log (
121
+ `Bad formatting for '${ grammarName } ' step (does not end in '.' or ':') in '${ filename } ':`
122
+ ) ;
123
+ console . dir ( step ) ;
124
+ console . log ( ) ;
125
+ process . exitCode = 1 ;
126
+ }
127
+ if ( step . match ( / ^ \s * ( - | [ 0 - 9 ] \. ) \s + [ a - z ] / ) ) {
128
+ console . log (
129
+ `Bad formatting of '${ grammarName } ' step (should start with a capital) in '${ filename } ':`
130
+ ) ;
131
+ console . dir ( step ) ;
132
+ console . log ( ) ;
133
+ process . exitCode = 1 ;
134
+ }
135
+ const trimmedInnerLine = step . replace ( / \s + / g, " " ) ;
136
+ if (
137
+ trimmedInnerLine . match (
138
+ / (?: [ r R ] e t u r n | i s (?: n o t ) ? ) ( t r u e | f a l s e | n u l l ) \b /
139
+ ) &&
140
+ ! trimmedInnerLine . match ( / n u l l o r e m p t y / )
141
+ ) {
142
+ console . log (
143
+ `Potential bad formatting of '${ grammarName } ' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${ filename } ':`
144
+ ) ;
145
+ console . dir ( step ) ;
83
146
console . log ( ) ;
84
147
process . exitCode = 1 ;
85
148
}
0 commit comments