Skip to content

Commit

Permalink
feat(parse): update repeat grammar
Browse files Browse the repository at this point in the history
- support specifying min repeat count only (max: infinity), e.g. `{3,}`
  • Loading branch information
postspectacular committed Jul 19, 2020
1 parent 22188a4 commit 7aae9ac
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/parse/src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ const REPEAT = maybe(
oneOf("?*+", "repeat"),
collect(
seq(
[
litD("{"),
UINT,
maybe(hoistResult(seq([litD(","), UINT]))),
litD("}"),
],
[litD("{"), UINT, maybe(lit(",")), maybe(UINT), litD("}")],
"repeatN"
)
),
Expand Down Expand Up @@ -320,8 +315,8 @@ const compileRepeat = (
return parser;
}
} else if (rspec.id === "repeatN") {
const [n, m] = rspec.result;
return repeat(parser, n, m || n);
const [n, sep, m] = rspec.result;
return repeat(parser, n, sep ? m || Infinity : m || n);
}
return parser;
};
Expand Down

0 comments on commit 7aae9ac

Please sign in to comment.