Skip to content

Commit 3b9b05b

Browse files
committed
Simplify optionallySurroundedByParentheses parser
1 parent dffa4ea commit 3b9b05b

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
map,
3-
oneOf,
4-
sequence,
5-
zeroOrMore,
6-
type Parser,
7-
} from '@matt.kantor/parsing'
1+
import { map, oneOf, sequence, type Parser } from '@matt.kantor/parsing'
82
import { closingParenthesis, openingParenthesis } from './literals.js'
9-
import { trivia } from './trivia.js'
3+
import { optionalTrivia } from './trivia.js'
104

115
const optionallySurroundedBy = <Output>(
126
parser1: Parser<unknown>,
@@ -21,16 +15,8 @@ const optionallySurroundedBy = <Output>(
2115
export const optionallySurroundedByParentheses = <Output>(
2216
theParser: Parser<Output>,
2317
): Parser<Output> =>
24-
oneOf([
25-
// This allows `theParser` to greedily consume trivia.
26-
optionallySurroundedBy(
27-
openingParenthesis,
28-
theParser,
29-
sequence([zeroOrMore(trivia), closingParenthesis]),
30-
),
31-
optionallySurroundedBy(
32-
sequence([openingParenthesis, zeroOrMore(trivia)]),
33-
theParser,
34-
sequence([zeroOrMore(trivia), closingParenthesis]),
35-
),
36-
])
18+
optionallySurroundedBy(
19+
sequence([openingParenthesis, optionalTrivia]),
20+
theParser,
21+
sequence([optionalTrivia, closingParenthesis]),
22+
)

0 commit comments

Comments
 (0)