@@ -122,6 +122,12 @@ impl Parser<'_> {
122122 }
123123
124124 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+ }
125131 let is_root = self . parse_is_root ( ) ;
126132 self . space0 ( ) ;
127133 let name = self
@@ -133,6 +139,7 @@ impl Parser<'_> {
133139 } ;
134140 Ok ( Production {
135141 name,
142+ comments,
136143 category : category. to_string ( ) ,
137144 expression,
138145 path : path. to_owned ( ) ,
@@ -218,6 +225,8 @@ impl Parser<'_> {
218225 bail ! ( self , "expected indentation on next line" ) ;
219226 }
220227 ExpressionKind :: Break ( space. len ( ) )
228+ } else if next == b'/' {
229+ self . parse_comment ( ) ?
221230 } else if next == b'`' {
222231 self . parse_terminal ( ) ?
223232 } else if next == b'[' {
@@ -269,6 +278,13 @@ impl Parser<'_> {
269278 Ok ( term)
270279 }
271280
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+
272288 fn parse_charset ( & mut self ) -> Result < ExpressionKind > {
273289 self . expect ( "[" , "expected opening [" ) ?;
274290 let mut characters = Vec :: new ( ) ;
0 commit comments