Skip to content

[FEATURE] Support optional partial-match when flushing the balanced search strategy #44

Description

@TomStrepsil

Is your feature request related to a problem? Please describe.

With the balanced search strategy, If the stream ends before the outermost opening delimiter has a corresponding closing delimiter, flush returns the entire accumulated content as a single unmatched string — including any complete inner pairs that could have been yielded as matches.

For example, with opening = "{" and closing = "}":

Stream:   "{ { foo }"   (two openings, one closing — outermost pair never closes)

flush() returns:  "{ { foo }"  as a non-match string

Not yielded:  "{ "        as non-match
              "{ foo }"   as match    ← inner balanced pair discarded

The balanced-match package documents an alternative: "the first match that was closed will be used" — i.e. yield the innermost complete pair and treat the outer unmatched opening as a non-match prefix.

Describe the solution you'd like

An option to enable this behaviour. It should not materially affect the performance of the default case.

Additional context

See: https://github.com/juliangruber/balanced-match#const-m--balanceda-b-str

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions