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'
82import { closingParenthesis , openingParenthesis } from './literals.js'
9- import { trivia } from './trivia.js'
3+ import { optionalTrivia } from './trivia.js'
104
115const optionallySurroundedBy = < Output > (
126 parser1 : Parser < unknown > ,
@@ -21,16 +15,8 @@ const optionallySurroundedBy = <Output>(
2115export 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