@@ -122,6 +122,12 @@ impl Parser<'_> {
122
122
}
123
123
124
124
fn parse_production ( & mut self , category : & str , path : & Path ) -> Result < Production > {
125
+ let mut comments = Vec :: new ( ) ;
126
+ while let Ok ( comment) = self . parse_comment ( ) {
127
+ self . expect ( "\n " , "expected newline" ) ?;
128
+ comments. push ( Expression :: new_kind ( comment) ) ;
129
+ comments. push ( Expression :: new_kind ( ExpressionKind :: Break ( 0 ) ) ) ;
130
+ }
125
131
let is_root = self . parse_is_root ( ) ;
126
132
self . space0 ( ) ;
127
133
let name = self
@@ -133,6 +139,7 @@ impl Parser<'_> {
133
139
} ;
134
140
Ok ( Production {
135
141
name,
142
+ comments,
136
143
category : category. to_string ( ) ,
137
144
expression,
138
145
path : path. to_owned ( ) ,
@@ -218,6 +225,8 @@ impl Parser<'_> {
218
225
bail ! ( self , "expected indentation on next line" ) ;
219
226
}
220
227
ExpressionKind :: Break ( space. len ( ) )
228
+ } else if next == b'/' {
229
+ self . parse_comment ( ) ?
221
230
} else if next == b'`' {
222
231
self . parse_terminal ( ) ?
223
232
} else if next == b'[' {
@@ -269,6 +278,13 @@ impl Parser<'_> {
269
278
Ok ( term)
270
279
}
271
280
281
+ /// Parse e.g. `// Single line comment.`.
282
+ fn parse_comment ( & mut self ) -> Result < ExpressionKind > {
283
+ self . expect ( "//" , "expected `//`" ) ?;
284
+ let text = self . take_while ( & |x| x != '\n' ) . to_string ( ) ;
285
+ Ok ( ExpressionKind :: Comment ( text) )
286
+ }
287
+
272
288
fn parse_charset ( & mut self ) -> Result < ExpressionKind > {
273
289
self . expect ( "[" , "expected opening [" ) ?;
274
290
let mut characters = Vec :: new ( ) ;
0 commit comments