@@ -1405,7 +1405,30 @@ export class _Parser implements Parser {
14051405 this . skipSpace ( ) ;
14061406 let body = this . parseExpression ( ) ;
14071407 this . skipSpace ( ) ;
1408- if ( ! this . matchBoundary ( ) ) {
1408+ const boundary = this . _boundaries [ this . _boundaries . length - 1 ] ?. tokens ;
1409+ const matchedBoundary = this . matchBoundary ( ) ;
1410+ const sameTrigger =
1411+ ( typeof def . openTrigger === 'string' &&
1412+ typeof def . closeTrigger === 'string' &&
1413+ def . openTrigger === def . closeTrigger ) ||
1414+ ( Array . isArray ( def . openTrigger ) &&
1415+ Array . isArray ( def . closeTrigger ) &&
1416+ def . openTrigger . length === def . closeTrigger . length &&
1417+ def . openTrigger . every ( ( tok , i ) => tok === def . closeTrigger [ i ] ) ) ;
1418+ if ( matchedBoundary && isEmptySequence ( body ) && sameTrigger && boundary ) {
1419+ // If the open/close delimiter are identical and the body is empty,
1420+ // we may have consumed an inner delimiter (e.g. "||3-5|-4|").
1421+ // Retry parsing without the boundary and look for the closing delimiter.
1422+ this . index = bodyStart ;
1423+ this . skipSpace ( ) ;
1424+ body = this . parseExpression ( ) ;
1425+ this . skipSpace ( ) ;
1426+ if ( ! this . matchAll ( boundary ) ) {
1427+ this . index = start ;
1428+ if ( ! this . atEnd ) continue ;
1429+ return null ;
1430+ }
1431+ } else if ( ! matchedBoundary ) {
14091432 // We couldn't parse the body up to the closing delimiter.
14101433 // This could be a case where the boundary of the enclosure is
14111434 // ambiguous, i.e. `|(a+|b|+c)|`. Attempt to parse without the boundary
0 commit comments