Skip to content

Commit 9b4d16f

Browse files
committed
fix(parsely): Make Repeat parser work when no separator is given
1 parent d46b043 commit 9b4d16f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

packages/phoenix/packages/parsely/parsers/combinators.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class Optional extends Parser {
7979
export class Repeat extends Parser {
8080
_create (value_parser, separator_parser, { trailing = false } = {}) {
8181
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;
8383
this.trailing = trailing;
8484
}
8585

@@ -99,22 +99,23 @@ export class Repeat extends Parser {
9999
// Repeatedly parse <separator> <value>
100100
for (;;) {
101101
// 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+
}
112113

113114
// Value
114115
const result = this.value_parser.parse(subStream);
115116
if (result.status === UNRECOGNIZED) {
116117
// If we failed to parse a value, we have a trailing separator
117-
if (this.trailing === false)
118+
if (parsed_separator && this.trailing === false)
118119
return { status: INVALID, value: result };
119120
break;
120121
}

0 commit comments

Comments
 (0)