Module: processTargets/modifiers/surroundingPair/generateUnmatchedDelimiters
Functions
findUnmatchedDelimiter
▸ findUnmatchedDelimiter(delimiterOccurrences
, initialIndex
, acceptableDelimiters
, lookForward
): DelimiterOccurrence
| null
Finds the first instance of an unmatched delimiter in the given direction
This function is a simplified version of generateUnmatchedDelimiters, so look there for details of the algorithm
Parameters
Name | Type | Description |
---|---|---|
delimiterOccurrences | PossibleDelimiterOccurrence [] | A list of delimiter occurrences. Expected to be sorted by offsets |
initialIndex | number | The index of the delimiter to start from |
acceptableDelimiters | SimpleSurroundingPairName [] | A list of names of acceptable delimiters to look for |
lookForward | boolean | Whether to scan forwards or backwards |
Returns
DelimiterOccurrence
| null
The first acceptable unmatched delimiter, if one is found otherwise null
Defined in
processTargets/modifiers/surroundingPair/generateUnmatchedDelimiters.ts:22
generateUnmatchedDelimiters
▸ generateUnmatchedDelimiters(delimiterOccurrences
, initialIndex
, getCurrentAcceptableDelimiters
, lookForward
): Generator
<DelimiterOccurrence
, void
, never
>
This function is the heart of our surrounding pair algorithm. It scans in one direction (either forwards or backwards) through a list of delimiters, yielding each unmatched delimiter that it finds.
The algorithm proceeds by keeping a map from delimiter names to counts. Every time it sees an instance of an opening or closing delimiter of the given type, it will either increment or decrement the counter for the given delimiter, depending which direction we're scanning.
If the count for any delimiter drops to -1, we yield it because it means it is unmatched.
yields
Occurrences of unmatched delimiters
Parameters
Name | Type | Description |
---|---|---|
delimiterOccurrences | PossibleDelimiterOccurrence [] | A list of delimiter occurrences. Expected to be sorted by offsets |
initialIndex | number | The index of the delimiter to start from |
getCurrentAcceptableDelimiters | () => SimpleSurroundingPairName [] | A function that returns a list of names of acceptable delimiters to look for. We expect that this list might change every time we yield, depending on the outcome of the scan in the other direction |
lookForward | boolean | Whether to scan forwards or backwards |
Returns
Generator
<DelimiterOccurrence
, void
, never
>
Defined in
processTargets/modifiers/surroundingPair/generateUnmatchedDelimiters.ts:61