diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/regexp | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/regexp')
-rw-r--r-- | libgo/go/regexp/all_test.go | 7 | ||||
-rw-r--r-- | libgo/go/regexp/exec_test.go | 10 | ||||
-rw-r--r-- | libgo/go/regexp/regexp.go | 19 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/compile.go | 7 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse.go | 29 |
5 files changed, 33 insertions, 39 deletions
diff --git a/libgo/go/regexp/all_test.go b/libgo/go/regexp/all_test.go index 77f32ca..8810796 100644 --- a/libgo/go/regexp/all_test.go +++ b/libgo/go/regexp/all_test.go @@ -5,7 +5,6 @@ package regexp import ( - "os" "strings" "testing" ) @@ -33,7 +32,7 @@ var good_re = []string{ /* type stringError struct { re string - err os.Error + err error } var bad_re = []stringError{ @@ -53,10 +52,10 @@ var bad_re = []stringError{ } */ -func compileTest(t *testing.T, expr string, error os.Error) *Regexp { +func compileTest(t *testing.T, expr string, error error) *Regexp { re, err := Compile(expr) if err != error { - t.Error("compiling `", expr, "`; unexpected error: ", err.String()) + t.Error("compiling `", expr, "`; unexpected error: ", err.Error()) } return re } diff --git a/libgo/go/regexp/exec_test.go b/libgo/go/regexp/exec_test.go index 905fd4e..499d1a5 100644 --- a/libgo/go/regexp/exec_test.go +++ b/libgo/go/regexp/exec_test.go @@ -104,7 +104,7 @@ func testRE2(t *testing.T, file string) { for { line, err := r.ReadString('\n') if err != nil { - if err == os.EOF { + if err == io.EOF { break } t.Fatalf("%s:%d: %v", file, lineno, err) @@ -141,7 +141,7 @@ func testRE2(t *testing.T, file string) { } re, err = tryCompile(q) if err != nil { - if err.String() == "error parsing regexp: invalid escape sequence: `\\C`" { + if err.Error() == "error parsing regexp: invalid escape sequence: `\\C`" { // We don't and likely never will support \C; keep going. continue } @@ -275,7 +275,7 @@ func isSingleBytes(s string) bool { return true } -func tryCompile(s string) (re *Regexp, err os.Error) { +func tryCompile(s string) (re *Regexp, err error) { // Protect against panic during Compile. defer func() { if r := recover(); r != nil { @@ -370,7 +370,7 @@ Reading: lineno++ line, err := b.ReadString('\n') if err != nil { - if err != os.EOF { + if err != io.EOF { t.Errorf("%s:%d: %v", file, lineno, err) } break Reading @@ -629,7 +629,7 @@ func parseFowlerResult(s string) (ok, compiled, matched bool, pos []int) { return } var v = -1 - var err os.Error + var err error if s[:i] != "?" { v, err = strconv.Atoi(s[:i]) if err != nil { diff --git a/libgo/go/regexp/regexp.go b/libgo/go/regexp/regexp.go index a1b7951..9e9fb85 100644 --- a/libgo/go/regexp/regexp.go +++ b/libgo/go/regexp/regexp.go @@ -56,7 +56,6 @@ package regexp import ( "bytes" "io" - "os" "regexp/syntax" "strconv" "strings" @@ -69,7 +68,7 @@ var debug = false // Error is the local type for a parsing error. type Error string -func (e Error) String() string { +func (e Error) Error() string { return string(e) } @@ -108,7 +107,7 @@ func (re *Regexp) String() string { // that Perl, Python, and other implementations use, although this // package implements it without the expense of backtracking. // For POSIX leftmost-longest matching, see CompilePOSIX. -func Compile(expr string) (*Regexp, os.Error) { +func Compile(expr string) (*Regexp, error) { return compile(expr, syntax.Perl, false) } @@ -131,11 +130,11 @@ func Compile(expr string) (*Regexp, os.Error) { // subexpression, then the second, and so on from left to right. // The POSIX rule is computationally prohibitive and not even well-defined. // See http://swtch.com/~rsc/regexp/regexp2.html#posix for details. -func CompilePOSIX(expr string) (*Regexp, os.Error) { +func CompilePOSIX(expr string) (*Regexp, error) { return compile(expr, syntax.POSIX, true) } -func compile(expr string, mode syntax.Flags, longest bool) (*Regexp, os.Error) { +func compile(expr string, mode syntax.Flags, longest bool) (*Regexp, error) { re, err := syntax.Parse(expr, mode) if err != nil { return nil, err @@ -196,7 +195,7 @@ func (re *Regexp) put(z *machine) { func MustCompile(str string) *Regexp { regexp, error := Compile(str) if error != nil { - panic(`regexp: Compile(` + quote(str) + `): ` + error.String()) + panic(`regexp: Compile(` + quote(str) + `): ` + error.Error()) } return regexp } @@ -207,7 +206,7 @@ func MustCompile(str string) *Regexp { func MustCompilePOSIX(str string) *Regexp { regexp, error := CompilePOSIX(str) if error != nil { - panic(`regexp: CompilePOSIX(` + quote(str) + `): ` + error.String()) + panic(`regexp: CompilePOSIX(` + quote(str) + `): ` + error.Error()) } return regexp } @@ -392,7 +391,7 @@ func (re *Regexp) Match(b []byte) bool { // MatchReader checks whether a textual regular expression matches the text // read by the RuneReader. More complicated queries need to use Compile and // the full Regexp interface. -func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error) { +func MatchReader(pattern string, r io.RuneReader) (matched bool, error error) { re, err := Compile(pattern) if err != nil { return false, err @@ -403,7 +402,7 @@ func MatchReader(pattern string, r io.RuneReader) (matched bool, error os.Error) // MatchString checks whether a textual regular expression // matches a string. More complicated queries need // to use Compile and the full Regexp interface. -func MatchString(pattern string, s string) (matched bool, error os.Error) { +func MatchString(pattern string, s string) (matched bool, error error) { re, err := Compile(pattern) if err != nil { return false, err @@ -414,7 +413,7 @@ func MatchString(pattern string, s string) (matched bool, error os.Error) { // Match checks whether a textual regular expression // matches a byte slice. More complicated queries need // to use Compile and the full Regexp interface. -func Match(pattern string, b []byte) (matched bool, error os.Error) { +func Match(pattern string, b []byte) (matched bool, error error) { re, err := Compile(pattern) if err != nil { return false, err diff --git a/libgo/go/regexp/syntax/compile.go b/libgo/go/regexp/syntax/compile.go index c90de3f..21c6565 100644 --- a/libgo/go/regexp/syntax/compile.go +++ b/libgo/go/regexp/syntax/compile.go @@ -1,9 +1,6 @@ package syntax -import ( - "os" - "unicode" -) +import "unicode" // A patchList is a list of instruction pointers that need to be filled in (patched). // Because the pointers haven't been filled in yet, we can reuse their storage @@ -76,7 +73,7 @@ type compiler struct { // Compile compiles the regexp into a program to be executed. // The regexp should have been simplified already (returned from re.Simplify). -func Compile(re *Regexp) (*Prog, os.Error) { +func Compile(re *Regexp) (*Prog, error) { var c compiler c.init() f := c.compile(re) diff --git a/libgo/go/regexp/syntax/parse.go b/libgo/go/regexp/syntax/parse.go index bb19c5a..ba5c0a1 100644 --- a/libgo/go/regexp/syntax/parse.go +++ b/libgo/go/regexp/syntax/parse.go @@ -5,7 +5,6 @@ package syntax import ( - "os" "sort" "strings" "unicode" @@ -19,7 +18,7 @@ type Error struct { Expr string } -func (e *Error) String() string { +func (e *Error) Error() string { return "error parsing regexp: " + e.Code.String() + ": `" + e.Expr + "`" } @@ -222,7 +221,7 @@ func (p *parser) op(op Op) *Regexp { // before is the regexp suffix starting at the repetition operator. // after is the regexp suffix following after the repetition operator. // repeat returns an updated 'after' and an error, if any. -func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (string, os.Error) { +func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (string, error) { flags := p.flags if p.flags&PerlX != 0 { if len(after) > 0 && after[0] == '?' { @@ -649,7 +648,7 @@ func literalRegexp(s string, flags Flags) *Regexp { // Parsing. -func Parse(s string, flags Flags) (*Regexp, os.Error) { +func Parse(s string, flags Flags) (*Regexp, error) { if flags&Literal != 0 { // Trivial parser for literal string. if err := checkUTF8(s); err != nil { @@ -661,7 +660,7 @@ func Parse(s string, flags Flags) (*Regexp, os.Error) { // Otherwise, must do real work. var ( p parser - err os.Error + err error c rune op Op lastRepeat string @@ -889,7 +888,7 @@ func (p *parser) parseRepeat(s string) (min, max int, rest string, ok bool) { // parsePerlFlags parses a Perl flag setting or non-capturing group or both, // like (?i) or (?: or (?i:. It removes the prefix from s and updates the parse state. // The caller must have ensured that s begins with "(?". -func (p *parser) parsePerlFlags(s string) (rest string, err os.Error) { +func (p *parser) parsePerlFlags(s string) (rest string, err error) { t := s // Check for named captures, first introduced in Python's regexp library. @@ -1069,7 +1068,7 @@ func matchRune(re *Regexp, r rune) bool { } // parseVerticalBar handles a | in the input. -func (p *parser) parseVerticalBar() os.Error { +func (p *parser) parseVerticalBar() error { p.concat() // The concatenation we just parsed is on top of the stack. @@ -1152,7 +1151,7 @@ func (p *parser) swapVerticalBar() bool { } // parseRightParen handles a ) in the input. -func (p *parser) parseRightParen() os.Error { +func (p *parser) parseRightParen() error { p.concat() if p.swapVerticalBar() { // pop vertical bar @@ -1186,7 +1185,7 @@ func (p *parser) parseRightParen() os.Error { // parseEscape parses an escape sequence at the beginning of s // and returns the rune. -func (p *parser) parseEscape(s string) (r rune, rest string, err os.Error) { +func (p *parser) parseEscape(s string) (r rune, rest string, err error) { t := s[1:] if t == "" { return 0, "", &Error{ErrTrailingBackslash, ""} @@ -1302,7 +1301,7 @@ Switch: // parseClassChar parses a character class character at the beginning of s // and returns it. -func (p *parser) parseClassChar(s, wholeClass string) (r rune, rest string, err os.Error) { +func (p *parser) parseClassChar(s, wholeClass string) (r rune, rest string, err error) { if s == "" { return 0, "", &Error{Code: ErrMissingBracket, Expr: wholeClass} } @@ -1338,7 +1337,7 @@ func (p *parser) parsePerlClassEscape(s string, r []rune) (out []rune, rest stri // parseNamedClass parses a leading POSIX named character class like [:alnum:] // from the beginning of s. If one is present, it appends the characters to r // and returns the new slice r and the remainder of the string. -func (p *parser) parseNamedClass(s string, r []rune) (out []rune, rest string, err os.Error) { +func (p *parser) parseNamedClass(s string, r []rune) (out []rune, rest string, err error) { if len(s) < 2 || s[0] != '[' || s[1] != ':' { return } @@ -1401,7 +1400,7 @@ func unicodeTable(name string) (*unicode.RangeTable, *unicode.RangeTable) { // parseUnicodeClass parses a leading Unicode character class like \p{Han} // from the beginning of s. If one is present, it appends the characters to r // and returns the new slice r and the remainder of the string. -func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string, err os.Error) { +func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string, err error) { if p.flags&UnicodeGroups == 0 || len(s) < 2 || s[0] != '\\' || s[1] != 'p' && s[1] != 'P' { return } @@ -1474,7 +1473,7 @@ func (p *parser) parseUnicodeClass(s string, r []rune) (out []rune, rest string, // parseClass parses a character class at the beginning of s // and pushes it onto the parse stack. -func (p *parser) parseClass(s string) (rest string, err os.Error) { +func (p *parser) parseClass(s string) (rest string, err error) { t := s[1:] // chop [ re := p.newRegexp(OpCharClass) re.Flags = p.flags @@ -1824,7 +1823,7 @@ func (ra ranges) Swap(i, j int) { p[i], p[i+1], p[j], p[j+1] = p[j], p[j+1], p[i], p[i+1] } -func checkUTF8(s string) os.Error { +func checkUTF8(s string) error { for s != "" { rune, size := utf8.DecodeRuneInString(s) if rune == utf8.RuneError && size == 1 { @@ -1835,7 +1834,7 @@ func checkUTF8(s string) os.Error { return nil } -func nextRune(s string) (c rune, t string, err os.Error) { +func nextRune(s string) (c rune, t string, err error) { c, size := utf8.DecodeRuneInString(s) if c == utf8.RuneError && size == 1 { return 0, "", &Error{Code: ErrInvalidUTF8, Expr: s} |