Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(785)

Issue 5971058: code review 5971058: regexp: implement backtracking with pcre fallback (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 12 months ago by bradfitz
Modified:
10 years, 10 months ago
CC:
golang-dev
Visibility:
Public.

Description

regexp: implement backtracking with pcre fallback Go's current regular expression package doesn't support all popular patterns which programmers from other languages have come to expect. Notably, the Go regexp package doesn’t implement the useful backreference functionality. Without that, users can't match "catcat" or "dogdog" with (cat|dog)\1 and would need to otherwise fall back to writing multiple lines of code, possibly involving an "if" statement. To permit more expressiveness than Go's strictly "regular" regular expressions, this change permits falling back to the wildly popular PCRE library when Go would previously return a compile error. This permits programmers to copy-paste common regular expressions from forum sites, stackoverflow, etc. and rest assured that they'll work as they would have in PHP or Ruby. Go shouldn't let ideological fundamentalism about algorithmic purity limit user adoption. Thanks to Florian Wiemer for his work on the pcre package which is now promoted to the core library. This CL doesn't yet implement Perl's (?{ code }) construct. A future CL will bring Campher into the core, permitting calling into Perl from Go regular expressions. Fixes issue 3451

Patch Set 1 #

Patch Set 2 : diff -r 15a98eba66e0 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 3 : diff -r 15a98eba66e0 https://go.googlecode.com/hg/ #

Total comments: 7
Unified diffs Side-by-side diffs Delta from patch set Stats (+505 lines, -3 lines) Patch
M src/cmd/api/goapi.go View 1 1 chunk +3 lines, -0 lines 0 comments Download
M src/pkg/go/build/deps_test.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/regexp/exec.go View 1 1 chunk +3 lines, -0 lines 0 comments Download
A src/pkg/regexp/fallback.go View 1 1 chunk +86 lines, -0 lines 1 comment Download
M src/pkg/regexp/find_test.go View 1 2 chunks +18 lines, -0 lines 0 comments Download
A src/pkg/regexp/pcre/pcre.go View 1 1 chunk +384 lines, -0 lines 4 comments Download
M src/pkg/regexp/regexp.go View 1 4 chunks +10 lines, -2 lines 2 comments Download

Messages

Total messages: 12
bradfitz
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 12 months ago (2012-04-01 04:01:38 UTC) #1
mtj1
http://swtch.com/~rsc/regexp/regexp1.html On Sat, Mar 31, 2012 at 9:01 PM, <bradfitz@golang.org> wrote: > Reviewers: golang-dev_googlegroups.com, > ...
11 years, 12 months ago (2012-04-01 04:07:17 UTC) #2
adg
http://codereview.appspot.com/5971058/diff/1002/src/pkg/regexp/fallback.go File src/pkg/regexp/fallback.go (right): http://codereview.appspot.com/5971058/diff/1002/src/pkg/regexp/fallback.go#newcode1 src/pkg/regexp/fallback.go:1: // +build !cmd_go_bootstrap put the build line after the ...
11 years, 12 months ago (2012-04-01 04:07:49 UTC) #3
bradfitz
http://codereview.appspot.com/5971058/diff/1002/src/pkg/regexp/fallback.go File src/pkg/regexp/fallback.go (right): http://codereview.appspot.com/5971058/diff/1002/src/pkg/regexp/fallback.go#newcode1 src/pkg/regexp/fallback.go:1: // +build !cmd_go_bootstrap On 2012/04/01 04:07:49, adg wrote: > ...
11 years, 12 months ago (2012-04-01 04:11:45 UTC) #4
dsymonds
I like the approach, but what about running both native and PCRE in parallel? There ...
11 years, 12 months ago (2012-04-01 04:58:55 UTC) #5
bradfitz
Interesting idea. It could even learn over time (per-*Regexp) which is fastest. On Mar 31, ...
11 years, 12 months ago (2012-04-01 05:06:03 UTC) #6
nigeltao
Nice start. Any chance of some benchmarks? http://codereview.appspot.com/5971058/diff/3001/src/pkg/regexp/fallback.go File src/pkg/regexp/fallback.go (right): http://codereview.appspot.com/5971058/diff/3001/src/pkg/regexp/fallback.go#newcode51 src/pkg/regexp/fallback.go:51: var buf ...
11 years, 12 months ago (2012-04-01 05:08:40 UTC) #7
dsymonds
On Sun, Apr 1, 2012 at 3:06 PM, Brad Fitzpatrick <bradfitz@golang.org> wrote: > It could ...
11 years, 12 months ago (2012-04-01 05:09:53 UTC) #8
r
LGTM
11 years, 12 months ago (2012-04-01 07:35:40 UTC) #9
0xjnml
On Sunday, April 1, 2012 6:01:38 AM UTC+2, Brad Fitzpatrick wrote: > > I'd like ...
11 years, 12 months ago (2012-04-01 08:28:05 UTC) #10
zhigangc
We have open-sourced rubex. https://github.com/moovweb/rubex It uses the same regexp lib (oniguruma) that Ruby uses. ...
11 years, 11 months ago (2012-04-23 17:49:50 UTC) #11
0xjnml
11 years, 11 months ago (2012-04-23 18:14:34 UTC) #12
On 2012/04/23 17:49:50, zhigangc wrote:
> We have open-sourced rubex. https://github.com/moovweb/rubex
> 
> It uses the same regexp lib (oniguruma) that Ruby uses. 

Let me just [re]quote Michael.
On 2012/04/01 04:07:17, mtj1 wrote:
> http://swtch.com/%7Ersc/regexp/regexp1.html
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b