Module: processTargets/modifiers/surroundingPair/findOppositeDelimiter
Functions
findOppositeDelimiter
▸ findOppositeDelimiter(delimiterOccurrences
, index
, delimiterInfo
, forceDirection
): DelimiterOccurrence
| null
Given a delimiter, scans in the appropriate direction for a matching
opposite delimiter. If we don't know which direction the delimiter is facing
(eg for a "
), we first scan right, then left if nothing is found to the
right. This algorithm will get confused in text files, but keep in mind
that for languages with a parse tree, the delimiter occurrence will usually
know which direction it is based on where it sits in the parse tree. That
information will be reflected on the IndividualDelimiter
itself.
Parameters
Name | Type | Description |
---|---|---|
delimiterOccurrences | PossibleDelimiterOccurrence [] | A list of delimiter occurrences. Expected to be sorted by offsets |
index | number | The index of the delimiter whose opposite we're looking for |
delimiterInfo | IndividualDelimiter | The delimiter info for the delimiter occurrence at the given index. Just passed through for efficiency rather than having to look it up again. Equivalent to delimiterOccurrences[index].delimiterInfo |
forceDirection | undefined | "left" | "right" | - |
Returns
DelimiterOccurrence
| null
The opposite delimiter, if found; otherwise null
Defined in
processTargets/modifiers/surroundingPair/findOppositeDelimiter.ts:26