[Issue 18336] Add std.algorithm.findMatchingParen

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 30 16:10:13 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18336

Seb <greensunny12 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Add                         |Add
                   |std.algorithm.untilClosingP |std.algorithm.findMatchingP
                   |arens                       |aren

--- Comment #2 from Seb <greensunny12 at gmail.com> ---
I just opened this issue because balancedParens is quite limited and could be
generalized.

For the archive. Here's Andrei's response:

> Yah we should have an algorithm findMatchingParen that assumes r.front is the opening paren and advances the range until it's positioned on the corresponding closing paren. An optional rParen can be passed for unusual closing parens.

@Jack:

> I'm wondering how useful something like this would be in real world 

There's the example from dlang.org to parse ddoc strings.
Here's another for finding everything within one HTML tag or all it's enclosing
ones:

"<foo foo=bar/>".findMatchingParen('<', '>').writeln; // foo foo=bar/
"<foo><bar/><foobar><bar/></foobar></foo>".findMatchingParen('<', '>',
2).writeln; // foo><bar/><foobar><bar/></foobar></foo>

https://run.dlang.io/is/ah7wmd

Of course, it would require a better, intuitive API to allow both use cases
nicely.

--


More information about the Digitalmars-d-bugs mailing list