Commit 6c230fbc authored by Russ Cox's avatar Russ Cox

regexp: move to old/regexp, replace with exp/regexp

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5127042
parent a8a18f65
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
"io" "io"
"log" "log"
"os" "os"
"exp/regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"go/scanner" "go/scanner"
"go/token" "go/token"
"io" "io"
"exp/regexp" "regexp"
"strconv" "strconv"
"template" "template"
) )
......
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"exp/regexp" "regexp"
"runtime" "runtime"
"sort" "sort"
"strings" "strings"
......
...@@ -48,7 +48,7 @@ import ( ...@@ -48,7 +48,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"exp/regexp" "regexp"
"sort" "sort"
"strings" "strings"
) )
......
...@@ -40,7 +40,7 @@ import ( ...@@ -40,7 +40,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"exp/regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"time" "time"
......
...@@ -82,8 +82,6 @@ DIRS=\ ...@@ -82,8 +82,6 @@ DIRS=\
exp/gui\ exp/gui\
exp/gui/x11\ exp/gui/x11\
exp/norm\ exp/norm\
exp/regexp\
exp/regexp/syntax\
exp/template/html\ exp/template/html\
expvar\ expvar\
flag\ flag\
...@@ -131,6 +129,7 @@ DIRS=\ ...@@ -131,6 +129,7 @@ DIRS=\
net/dict\ net/dict\
net/textproto\ net/textproto\
netchan\ netchan\
old/regexp\
old/template\ old/template\
os\ os\
os/signal\ os/signal\
...@@ -141,6 +140,7 @@ DIRS=\ ...@@ -141,6 +140,7 @@ DIRS=\
rand\ rand\
reflect\ reflect\
regexp\ regexp\
regexp/syntax\
rpc\ rpc\
rpc/jsonrpc\ rpc/jsonrpc\
runtime\ runtime\
......
...@@ -8,13 +8,13 @@ import ( ...@@ -8,13 +8,13 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"exp/norm" "exp/norm"
"exp/regexp"
"flag" "flag"
"fmt" "fmt"
"http" "http"
"log" "log"
"os" "os"
"path" "path"
"regexp"
"runtime" "runtime"
"strings" "strings"
"strconv" "strconv"
......
...@@ -18,10 +18,10 @@ package suffixarray ...@@ -18,10 +18,10 @@ package suffixarray
import ( import (
"bytes" "bytes"
"exp/regexp"
"gob" "gob"
"io" "io"
"os" "os"
"regexp"
"sort" "sort"
) )
......
...@@ -6,8 +6,8 @@ package suffixarray ...@@ -6,8 +6,8 @@ package suffixarray
import ( import (
"bytes" "bytes"
"exp/regexp"
"rand" "rand"
"regexp"
"sort" "sort"
"strings" "strings"
"testing" "testing"
......
# Copyright 2011 The Go Authors. All rights reserved. # Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
include ../../../Make.inc include ../../../Make.inc
TARG=exp/regexp TARG=old/regexp
GOFILES=\ GOFILES=\
exec.go\
regexp.go\ regexp.go\
include ../../../Make.pkg include ../../../Make.pkg
...@@ -24,13 +24,13 @@ var good_re = []string{ ...@@ -24,13 +24,13 @@ var good_re = []string{
`[a-z]`, `[a-z]`,
`[a-abc-c\-\]\[]`, `[a-abc-c\-\]\[]`,
`[a-z]+`, `[a-z]+`,
`[]`,
`[abc]`, `[abc]`,
`[^1234]`, `[^1234]`,
`[^\n]`, `[^\n]`,
`\!\\`, `\!\\`,
} }
/*
type stringError struct { type stringError struct {
re string re string
err os.Error err os.Error
...@@ -51,7 +51,6 @@ var bad_re = []stringError{ ...@@ -51,7 +51,6 @@ var bad_re = []stringError{
{`a??`, ErrBadClosure}, {`a??`, ErrBadClosure},
{`\x`, ErrBadBackslash}, {`\x`, ErrBadBackslash},
} }
*/
func compileTest(t *testing.T, expr string, error os.Error) *Regexp { func compileTest(t *testing.T, expr string, error os.Error) *Regexp {
re, err := Compile(expr) re, err := Compile(expr)
...@@ -67,13 +66,11 @@ func TestGoodCompile(t *testing.T) { ...@@ -67,13 +66,11 @@ func TestGoodCompile(t *testing.T) {
} }
} }
/*
func TestBadCompile(t *testing.T) { func TestBadCompile(t *testing.T) {
for i := 0; i < len(bad_re); i++ { for i := 0; i < len(bad_re); i++ {
compileTest(t, bad_re[i].re, bad_re[i].err) compileTest(t, bad_re[i].re, bad_re[i].err)
} }
} }
*/
func matchTest(t *testing.T, test *FindTest) { func matchTest(t *testing.T, test *FindTest) {
re := compileTest(t, test.pat, nil) re := compileTest(t, test.pat, nil)
...@@ -243,7 +240,7 @@ var metaTests = []MetaTest{ ...@@ -243,7 +240,7 @@ var metaTests = []MetaTest{
{`foo`, `foo`, `foo`, true}, {`foo`, `foo`, `foo`, true},
{`foo\.\$`, `foo\\\.\\\$`, `foo.$`, true}, // has meta but no operator {`foo\.\$`, `foo\\\.\\\$`, `foo.$`, true}, // has meta but no operator
{`foo.\$`, `foo\.\\\$`, `foo`, false}, // has escaped operators and real operators {`foo.\$`, `foo\.\\\$`, `foo`, false}, // has escaped operators and real operators
{`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[\{\]\}\\\|,<\.>/\?~`, `!@#`, false}, {`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[{\]}\\\|,<\.>/\?~`, `!@#`, false},
} }
func TestQuoteMeta(t *testing.T) { func TestQuoteMeta(t *testing.T) {
......
...@@ -58,8 +58,8 @@ var findTests = []FindTest{ ...@@ -58,8 +58,8 @@ var findTests = []FindTest{
{`(([^xyz]*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 3, 4)}, {`(([^xyz]*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 3, 4)},
{`((a|b|c)*(d))`, "abcd", build(1, 0, 4, 0, 4, 2, 3, 3, 4)}, {`((a|b|c)*(d))`, "abcd", build(1, 0, 4, 0, 4, 2, 3, 3, 4)},
{`(((a|b|c)*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 2, 3, 3, 4)}, {`(((a|b|c)*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 2, 3, 3, 4)},
{`\a\f\n\r\t\v`, "\a\f\n\r\t\v", build(1, 0, 6)}, {`\a\b\f\n\r\t\v`, "\a\b\f\n\r\t\v", build(1, 0, 7)},
{`[\a\f\n\r\t\v]+`, "\a\f\n\r\t\v", build(1, 0, 6)}, {`[\a\b\f\n\r\t\v]+`, "\a\b\f\n\r\t\v", build(1, 0, 7)},
{`a*(|(b))c*`, "aacc", build(1, 0, 4, 2, 2, -1, -1)}, {`a*(|(b))c*`, "aacc", build(1, 0, 4, 2, 2, -1, -1)},
{`(.*).*`, "ab", build(1, 0, 2, 0, 2)}, {`(.*).*`, "ab", build(1, 0, 2, 0, 2)},
...@@ -80,32 +80,6 @@ var findTests = []FindTest{ ...@@ -80,32 +80,6 @@ var findTests = []FindTest{
{`data`, "daXY data", build(1, 5, 9)}, {`data`, "daXY data", build(1, 5, 9)},
{`da(.)a$`, "daXY data", build(1, 5, 9, 7, 8)}, {`da(.)a$`, "daXY data", build(1, 5, 9, 7, 8)},
{`zx+`, "zzx", build(1, 1, 3)}, {`zx+`, "zzx", build(1, 1, 3)},
{`ab$`, "abcab", build(1, 3, 5)},
{`(aa)*$`, "a", build(1, 1, 1, -1, -1)},
{`(?:.|(?:.a))`, "", nil},
{`(?:A(?:A|a))`, "Aa", build(1, 0, 2)},
{`(?:A|(?:A|a))`, "a", build(1, 0, 1)},
{`(a){0}`, "", build(1, 0, 0, -1, -1)},
{`(?-s)(?:(?:^).)`, "\n", nil},
{`(?s)(?:(?:^).)`, "\n", build(1, 0, 1)},
{`(?:(?:^).)`, "\n", nil},
{`\b`, "x", build(2, 0, 0, 1, 1)},
{`\b`, "xx", build(2, 0, 0, 2, 2)},
{`\b`, "x y", build(4, 0, 0, 1, 1, 2, 2, 3, 3)},
{`\b`, "xx yy", build(4, 0, 0, 2, 2, 3, 3, 5, 5)},
{`\B`, "x", nil},
{`\B`, "xx", build(1, 1, 1)},
{`\B`, "x y", nil},
{`\B`, "xx yy", build(2, 1, 1, 4, 4)},
// RE2 tests
{`[^\S\s]`, "abcd", nil},
{`[^\S[:space:]]`, "abcd", nil},
{`[^\D\d]`, "abcd", nil},
{`[^\D[:digit:]]`, "abcd", nil},
{`(?i)\W`, "x", nil},
{`(?i)\W`, "k", nil},
{`(?i)\W`, "s", nil},
// can backslash-escape any punctuation // can backslash-escape any punctuation
{`\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~`, {`\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~`,
...@@ -235,7 +209,7 @@ func TestFindAll(t *testing.T) { ...@@ -235,7 +209,7 @@ func TestFindAll(t *testing.T) {
case test.matches == nil && result != nil: case test.matches == nil && result != nil:
t.Errorf("expected no match; got one: %s", test) t.Errorf("expected no match; got one: %s", test)
case test.matches != nil && result == nil: case test.matches != nil && result == nil:
t.Fatalf("expected match; got none: %s", test) t.Errorf("expected match; got none: %s", test)
case test.matches != nil && result != nil: case test.matches != nil && result != nil:
if len(test.matches) != len(result) { if len(test.matches) != len(result) {
t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test) t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
......
# Copyright 2009 The Go Authors. All rights reserved. # Copyright 2011 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
...@@ -6,6 +6,7 @@ include ../../Make.inc ...@@ -6,6 +6,7 @@ include ../../Make.inc
TARG=regexp TARG=regexp
GOFILES=\ GOFILES=\
exec.go\
regexp.go\ regexp.go\
include ../../Make.pkg include ../../Make.pkg
...@@ -24,13 +24,13 @@ var good_re = []string{ ...@@ -24,13 +24,13 @@ var good_re = []string{
`[a-z]`, `[a-z]`,
`[a-abc-c\-\]\[]`, `[a-abc-c\-\]\[]`,
`[a-z]+`, `[a-z]+`,
`[]`,
`[abc]`, `[abc]`,
`[^1234]`, `[^1234]`,
`[^\n]`, `[^\n]`,
`\!\\`, `\!\\`,
} }
/*
type stringError struct { type stringError struct {
re string re string
err os.Error err os.Error
...@@ -51,6 +51,7 @@ var bad_re = []stringError{ ...@@ -51,6 +51,7 @@ var bad_re = []stringError{
{`a??`, ErrBadClosure}, {`a??`, ErrBadClosure},
{`\x`, ErrBadBackslash}, {`\x`, ErrBadBackslash},
} }
*/
func compileTest(t *testing.T, expr string, error os.Error) *Regexp { func compileTest(t *testing.T, expr string, error os.Error) *Regexp {
re, err := Compile(expr) re, err := Compile(expr)
...@@ -66,11 +67,13 @@ func TestGoodCompile(t *testing.T) { ...@@ -66,11 +67,13 @@ func TestGoodCompile(t *testing.T) {
} }
} }
/*
func TestBadCompile(t *testing.T) { func TestBadCompile(t *testing.T) {
for i := 0; i < len(bad_re); i++ { for i := 0; i < len(bad_re); i++ {
compileTest(t, bad_re[i].re, bad_re[i].err) compileTest(t, bad_re[i].re, bad_re[i].err)
} }
} }
*/
func matchTest(t *testing.T, test *FindTest) { func matchTest(t *testing.T, test *FindTest) {
re := compileTest(t, test.pat, nil) re := compileTest(t, test.pat, nil)
...@@ -240,7 +243,7 @@ var metaTests = []MetaTest{ ...@@ -240,7 +243,7 @@ var metaTests = []MetaTest{
{`foo`, `foo`, `foo`, true}, {`foo`, `foo`, `foo`, true},
{`foo\.\$`, `foo\\\.\\\$`, `foo.$`, true}, // has meta but no operator {`foo\.\$`, `foo\\\.\\\$`, `foo.$`, true}, // has meta but no operator
{`foo.\$`, `foo\.\\\$`, `foo`, false}, // has escaped operators and real operators {`foo.\$`, `foo\.\\\$`, `foo`, false}, // has escaped operators and real operators
{`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[{\]}\\\|,<\.>/\?~`, `!@#`, false}, {`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[\{\]\}\\\|,<\.>/\?~`, `!@#`, false},
} }
func TestQuoteMeta(t *testing.T) { func TestQuoteMeta(t *testing.T) {
......
package regexp package regexp
import "exp/regexp/syntax" import "regexp/syntax"
// A queue is a 'sparse array' holding pending threads of execution. // A queue is a 'sparse array' holding pending threads of execution.
// See http://research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html // See http://research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html
......
...@@ -7,11 +7,11 @@ package regexp ...@@ -7,11 +7,11 @@ package regexp
import ( import (
"bufio" "bufio"
"compress/bzip2" "compress/bzip2"
"exp/regexp/syntax"
"fmt" "fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"regexp/syntax"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
......
...@@ -58,8 +58,8 @@ var findTests = []FindTest{ ...@@ -58,8 +58,8 @@ var findTests = []FindTest{
{`(([^xyz]*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 3, 4)}, {`(([^xyz]*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 3, 4)},
{`((a|b|c)*(d))`, "abcd", build(1, 0, 4, 0, 4, 2, 3, 3, 4)}, {`((a|b|c)*(d))`, "abcd", build(1, 0, 4, 0, 4, 2, 3, 3, 4)},
{`(((a|b|c)*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 2, 3, 3, 4)}, {`(((a|b|c)*)(d))`, "abcd", build(1, 0, 4, 0, 4, 0, 3, 2, 3, 3, 4)},
{`\a\b\f\n\r\t\v`, "\a\b\f\n\r\t\v", build(1, 0, 7)}, {`\a\f\n\r\t\v`, "\a\f\n\r\t\v", build(1, 0, 6)},
{`[\a\b\f\n\r\t\v]+`, "\a\b\f\n\r\t\v", build(1, 0, 7)}, {`[\a\f\n\r\t\v]+`, "\a\f\n\r\t\v", build(1, 0, 6)},
{`a*(|(b))c*`, "aacc", build(1, 0, 4, 2, 2, -1, -1)}, {`a*(|(b))c*`, "aacc", build(1, 0, 4, 2, 2, -1, -1)},
{`(.*).*`, "ab", build(1, 0, 2, 0, 2)}, {`(.*).*`, "ab", build(1, 0, 2, 0, 2)},
...@@ -80,6 +80,32 @@ var findTests = []FindTest{ ...@@ -80,6 +80,32 @@ var findTests = []FindTest{
{`data`, "daXY data", build(1, 5, 9)}, {`data`, "daXY data", build(1, 5, 9)},
{`da(.)a$`, "daXY data", build(1, 5, 9, 7, 8)}, {`da(.)a$`, "daXY data", build(1, 5, 9, 7, 8)},
{`zx+`, "zzx", build(1, 1, 3)}, {`zx+`, "zzx", build(1, 1, 3)},
{`ab$`, "abcab", build(1, 3, 5)},
{`(aa)*$`, "a", build(1, 1, 1, -1, -1)},
{`(?:.|(?:.a))`, "", nil},
{`(?:A(?:A|a))`, "Aa", build(1, 0, 2)},
{`(?:A|(?:A|a))`, "a", build(1, 0, 1)},
{`(a){0}`, "", build(1, 0, 0, -1, -1)},
{`(?-s)(?:(?:^).)`, "\n", nil},
{`(?s)(?:(?:^).)`, "\n", build(1, 0, 1)},
{`(?:(?:^).)`, "\n", nil},
{`\b`, "x", build(2, 0, 0, 1, 1)},
{`\b`, "xx", build(2, 0, 0, 2, 2)},
{`\b`, "x y", build(4, 0, 0, 1, 1, 2, 2, 3, 3)},
{`\b`, "xx yy", build(4, 0, 0, 2, 2, 3, 3, 5, 5)},
{`\B`, "x", nil},
{`\B`, "xx", build(1, 1, 1)},
{`\B`, "x y", nil},
{`\B`, "xx yy", build(2, 1, 1, 4, 4)},
// RE2 tests
{`[^\S\s]`, "abcd", nil},
{`[^\S[:space:]]`, "abcd", nil},
{`[^\D\d]`, "abcd", nil},
{`[^\D[:digit:]]`, "abcd", nil},
{`(?i)\W`, "x", nil},
{`(?i)\W`, "k", nil},
{`(?i)\W`, "s", nil},
// can backslash-escape any punctuation // can backslash-escape any punctuation
{`\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~`, {`\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~`,
...@@ -209,7 +235,7 @@ func TestFindAll(t *testing.T) { ...@@ -209,7 +235,7 @@ func TestFindAll(t *testing.T) {
case test.matches == nil && result != nil: case test.matches == nil && result != nil:
t.Errorf("expected no match; got one: %s", test) t.Errorf("expected no match; got one: %s", test)
case test.matches != nil && result == nil: case test.matches != nil && result == nil:
t.Errorf("expected match; got none: %s", test) t.Fatalf("expected match; got none: %s", test)
case test.matches != nil && result != nil: case test.matches != nil && result != nil:
if len(test.matches) != len(result) { if len(test.matches) != len(result) {
t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test) t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
......
This diff is collapsed.
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
include ../../../../Make.inc include ../../../Make.inc
TARG=exp/regexp/syntax TARG=regexp/syntax
GOFILES=\ GOFILES=\
compile.go\ compile.go\
parse.go\ parse.go\
...@@ -13,4 +13,4 @@ GOFILES=\ ...@@ -13,4 +13,4 @@ GOFILES=\
regexp.go\ regexp.go\
simplify.go\ simplify.go\
include ../../../../Make.pkg include ../../../Make.pkg
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment