@@ -79,7 +79,7 @@ export class Optional extends Parser {
79
79
export class Repeat extends Parser {
80
80
_create ( value_parser , separator_parser , { trailing = false } = { } ) {
81
81
this . value_parser = adapt_parser ( value_parser ) ;
82
- this . separator_parser = adapt_parser ( separator_parser ) ;
82
+ this . separator_parser = separator_parser ? adapt_parser ( separator_parser ) : null ;
83
83
this . trailing = trailing ;
84
84
}
85
85
@@ -99,22 +99,23 @@ export class Repeat extends Parser {
99
99
// Repeatedly parse <separator> <value>
100
100
for ( ; ; ) {
101
101
// Separator
102
- if ( ! this . separator_parser )
103
- continue ;
104
-
105
- const separatorResult = this . separator_parser . parse ( subStream ) ;
106
- if ( separatorResult . status === UNRECOGNIZED )
107
- break ;
108
- if ( separatorResult . status === INVALID )
109
- return { status : INVALID , value : separatorResult } ;
110
- stream . join ( subStream ) ;
111
- if ( ! separatorResult . $discard ) results . push ( separatorResult ) ;
102
+ let parsed_separator = false ;
103
+ if ( this . separator_parser ) {
104
+ const separatorResult = this . separator_parser . parse ( subStream ) ;
105
+ if ( separatorResult . status === UNRECOGNIZED )
106
+ break ;
107
+ if ( separatorResult . status === INVALID )
108
+ return { status : INVALID , value : separatorResult } ;
109
+ stream . join ( subStream ) ;
110
+ if ( ! separatorResult . $discard ) results . push ( separatorResult ) ;
111
+ parsed_separator = true ;
112
+ }
112
113
113
114
// Value
114
115
const result = this . value_parser . parse ( subStream ) ;
115
116
if ( result . status === UNRECOGNIZED ) {
116
117
// If we failed to parse a value, we have a trailing separator
117
- if ( this . trailing === false )
118
+ if ( parsed_separator && this . trailing === false )
118
119
return { status : INVALID , value : result } ;
119
120
break ;
120
121
}
0 commit comments