Skip to content

Commit

Permalink
Merge pull request #4159 from DmitryOlshansky/issue-12367
Browse files Browse the repository at this point in the history
Fix issue 12367 - std.regex: Recognize (?# ... ) comment syntax
  • Loading branch information
9il committed Apr 11, 2016
2 parents c8cc357 + 9f25688 commit b4f0478
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.dd
Expand Up @@ -10,6 +10,7 @@ $(BUGSTITLE Library Changes,
$(LI $(XREF range, padLeft) and $(XREF range, padRight) were added.)
$(LI $(XREF uni, isAlphaNum), which is analogous to $(XREF ascii, isAlphaNum)
was added.)
$(LI $(XREF regex, regex) now supports inline comments with (?#...) syntax.
)

$(BUGSTITLE Library Changes,
Expand Down
14 changes: 14 additions & 0 deletions std/regex/internal/parser.d
Expand Up @@ -432,6 +432,20 @@ struct Parser(R)
next();
switch(current)
{
case '#':
nesting--;
fixupStack.pop();
for(;;)
{
if(!next())
error("Unexpected end of pattern");
if(current == ')')
{
next();
break;
}
}
break;
case ':':
put(Bytecode(IR.Nop, 0));
next();
Expand Down
7 changes: 7 additions & 0 deletions std/regex/internal/tests.d
Expand Up @@ -1003,3 +1003,10 @@ unittest
auto rx = regex("[c d]", "x");
assert("a b".matchFirst(rx));
}

unittest
{
auto r = regex("(?# comment)abc(?# comment2)");
assert("abc".matchFirst(r));
assertThrown(regex("(?#..."));
}
1 change: 1 addition & 0 deletions std/regex/package.d
Expand Up @@ -128,6 +128,7 @@
$(REG_TITLE Other, Subexpressions $(AMP) alternations )
$(REG_ROW (regex), Matches subexpression regex,
saving matched portion of text for later retrieval. )
$(REG_ROW (?#comment), An inline comment that is ignored while matching.)
$(REG_ROW (?:regex), Matches subexpression regex,
$(U not) saving matched portion of text. Useful to speed up matching. )
$(REG_ROW A|B, Matches subexpression A, or failing that, matches B. )
Expand Down

0 comments on commit b4f0478

Please sign in to comment.