aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/template
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-03 02:17:34 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-03 02:17:34 +0000
commit2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch)
tree7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/template
parent02e9018f1616b23f1276151797216717b3564202 (diff)
downloadgcc-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/template')
-rw-r--r--libgo/go/template/doc.go4
-rw-r--r--libgo/go/template/exec.go15
-rw-r--r--libgo/go/template/exec_test.go6
-rw-r--r--libgo/go/template/funcs.go9
-rw-r--r--libgo/go/template/helper.go33
-rw-r--r--libgo/go/template/parse.go5
-rw-r--r--libgo/go/template/parse/node.go3
-rw-r--r--libgo/go/template/parse/parse.go9
-rw-r--r--libgo/go/template/parse/set.go3
-rw-r--r--libgo/go/template/set.go7
10 files changed, 43 insertions, 51 deletions
diff --git a/libgo/go/template/doc.go b/libgo/go/template/doc.go
index a52f32d..42f9e56 100644
--- a/libgo/go/template/doc.go
+++ b/libgo/go/template/doc.go
@@ -117,7 +117,7 @@ An argument is a simple value, denoted by one of the following.
.Method
The result is the value of invoking the method with dot as the
receiver, dot.Method(). Such a method must have one return value (of
- any type) or two return values, the second of which is an os.Error.
+ any type) or two return values, the second of which is an error.
If it has two and the returned error is non-nil, execution terminates
and an error is returned to the caller as the value of Execute.
Method invocations may be chained and combined with fields and keys
@@ -159,7 +159,7 @@ passed as the last argument of the following command. The output of the final
command in the pipeline is the value of the pipeline.
The output of a command will be either one value or two values, the second of
-which has type os.Error. If that second value is present and evaluates to
+which has type error. If that second value is present and evaluates to
non-nil, execution terminates and the error is returned to the caller of
Execute.
diff --git a/libgo/go/template/exec.go b/libgo/go/template/exec.go
index 34c6633..228477c 100644
--- a/libgo/go/template/exec.go
+++ b/libgo/go/template/exec.go
@@ -7,7 +7,6 @@ package template
import (
"fmt"
"io"
- "os"
"reflect"
"runtime"
"strings"
@@ -70,25 +69,25 @@ func (s *state) errorf(format string, args ...interface{}) {
}
// error terminates processing.
-func (s *state) error(err os.Error) {
+func (s *state) error(err error) {
s.errorf("%s", err)
}
// errRecover is the handler that turns panics into returns from the top
// level of Parse.
-func errRecover(errp *os.Error) {
+func errRecover(errp *error) {
e := recover()
if e != nil {
if _, ok := e.(runtime.Error); ok {
panic(e)
}
- *errp = e.(os.Error)
+ *errp = e.(error)
}
}
// Execute applies a parsed template to the specified data object,
// writing the output to wr.
-func (t *Template) Execute(wr io.Writer, data interface{}) (err os.Error) {
+func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
defer errRecover(&err)
value := reflect.ValueOf(data)
state := &state{
@@ -446,7 +445,7 @@ func methodByName(receiver reflect.Value, name string) (reflect.Value, bool) {
}
var (
- osErrorType = reflect.TypeOf((*os.Error)(nil)).Elem()
+ osErrorType = reflect.TypeOf((*error)(nil)).Elem()
fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
)
@@ -493,9 +492,9 @@ func (s *state) evalCall(dot, fun reflect.Value, name string, args []parse.Node,
argv[i] = final
}
result := fun.Call(argv)
- // If we have an os.Error that is not nil, stop execution and return that error to the caller.
+ // If we have an error that is not nil, stop execution and return that error to the caller.
if len(result) == 2 && !result[1].IsNil() {
- s.errorf("error calling %s: %s", name, result[1].Interface().(os.Error))
+ s.errorf("error calling %s: %s", name, result[1].Interface().(error))
}
return result[0]
}
diff --git a/libgo/go/template/exec_test.go b/libgo/go/template/exec_test.go
index 2d2b402..e32de4d 100644
--- a/libgo/go/template/exec_test.go
+++ b/libgo/go/template/exec_test.go
@@ -158,8 +158,8 @@ func (t *T) MSort(m map[string]int) []string {
return keys
}
-// EPERM returns a value and an os.Error according to its argument.
-func (t *T) EPERM(error bool) (bool, os.Error) {
+// EPERM returns a value and an error according to its argument.
+func (t *T) EPERM(error bool) (bool, error) {
if error {
return true, os.EPERM
}
@@ -548,7 +548,7 @@ func TestExecuteError(t *testing.T) {
err = tmpl.Execute(b, tVal)
if err == nil {
t.Errorf("expected error; got none")
- } else if !strings.Contains(err.String(), os.EPERM.String()) {
+ } else if !strings.Contains(err.Error(), os.EPERM.Error()) {
if *debug {
fmt.Printf("test execute error: %s\n", err)
}
diff --git a/libgo/go/template/funcs.go b/libgo/go/template/funcs.go
index 938559e..26c3a6e 100644
--- a/libgo/go/template/funcs.go
+++ b/libgo/go/template/funcs.go
@@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
- "os"
"reflect"
"strings"
"unicode"
@@ -18,7 +17,7 @@ import (
// FuncMap is the type of the map defining the mapping from names to functions.
// Each function must have either a single return value, or two return values of
-// which the second has type os.Error. If the second argument evaluates to non-nil
+// which the second has type error. If the second argument evaluates to non-nil
// during execution, execution terminates and Execute returns an error.
type FuncMap map[string]interface{}
@@ -69,7 +68,7 @@ func addFuncs(out, in FuncMap) {
// goodFunc checks that the function or method has the right result signature.
func goodFunc(typ reflect.Type) bool {
- // We allow functions with 1 result or 2 results where the second is an os.Error.
+ // We allow functions with 1 result or 2 results where the second is an error.
switch {
case typ.NumOut() == 1:
return true
@@ -102,7 +101,7 @@ func findFunction(name string, tmpl *Template, set *Set) (reflect.Value, bool) {
// index returns the result of indexing its first argument by the following
// arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each
// indexed item must be a map, slice, or array.
-func index(item interface{}, indices ...interface{}) (interface{}, os.Error) {
+func index(item interface{}, indices ...interface{}) (interface{}, error) {
v := reflect.ValueOf(item)
for _, i := range indices {
index := reflect.ValueOf(i)
@@ -144,7 +143,7 @@ func index(item interface{}, indices ...interface{}) (interface{}, os.Error) {
// Length
// length returns the length of the item, with an error if it has no defined length.
-func length(item interface{}) (int, os.Error) {
+func length(item interface{}) (int, error) {
v, isNil := indirect(reflect.ValueOf(item))
if isNil {
return 0, fmt.Errorf("len of nil pointer")
diff --git a/libgo/go/template/helper.go b/libgo/go/template/helper.go
index 1dc90f7..a743a83 100644
--- a/libgo/go/template/helper.go
+++ b/libgo/go/template/helper.go
@@ -9,17 +9,16 @@ package template
import (
"fmt"
"io/ioutil"
- "os"
"path/filepath"
)
// Functions and methods to parse a single template.
-// Must is a helper that wraps a call to a function returning (*Template, os.Error)
+// Must is a helper that wraps a call to a function returning (*Template, error)
// and panics if the error is non-nil. It is intended for use in variable initializations
// such as
// var t = template.Must(template.New("name").Parse("text"))
-func Must(t *Template, err os.Error) *Template {
+func Must(t *Template, err error) *Template {
if err != nil {
panic(err)
}
@@ -28,7 +27,7 @@ func Must(t *Template, err os.Error) *Template {
// ParseFile creates a new Template and parses the template definition from
// the named file. The template name is the base name of the file.
-func ParseFile(filename string) (*Template, os.Error) {
+func ParseFile(filename string) (*Template, error) {
t := New(filepath.Base(filename))
return t.ParseFile(filename)
}
@@ -37,7 +36,7 @@ func ParseFile(filename string) (*Template, os.Error) {
// definition from the named file. The template name is the base name
// of the file. It also adds the template to the set. Function bindings are
// checked against those in the set.
-func parseFileInSet(filename string, set *Set) (*Template, os.Error) {
+func parseFileInSet(filename string, set *Set) (*Template, error) {
t := New(filepath.Base(filename))
return t.parseFileInSet(filename, set)
}
@@ -45,7 +44,7 @@ func parseFileInSet(filename string, set *Set) (*Template, os.Error) {
// ParseFile reads the template definition from a file and parses it to
// construct an internal representation of the template for execution.
// The returned template will be nil if an error occurs.
-func (t *Template) ParseFile(filename string) (*Template, os.Error) {
+func (t *Template) ParseFile(filename string) (*Template, error) {
b, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
@@ -57,7 +56,7 @@ func (t *Template) ParseFile(filename string) (*Template, os.Error) {
// are checked against those in the set and the template is added
// to the set.
// The returned template will be nil if an error occurs.
-func (t *Template) parseFileInSet(filename string, set *Set) (*Template, os.Error) {
+func (t *Template) parseFileInSet(filename string, set *Set) (*Template, error) {
b, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
@@ -67,11 +66,11 @@ func (t *Template) parseFileInSet(filename string, set *Set) (*Template, os.Erro
// Functions and methods to parse a set.
-// SetMust is a helper that wraps a call to a function returning (*Set, os.Error)
+// SetMust is a helper that wraps a call to a function returning (*Set, error)
// and panics if the error is non-nil. It is intended for use in variable initializations
// such as
// var s = template.SetMust(template.ParseSetFiles("file"))
-func SetMust(s *Set, err os.Error) *Set {
+func SetMust(s *Set, err error) *Set {
if err != nil {
panic(err)
}
@@ -81,7 +80,7 @@ func SetMust(s *Set, err os.Error) *Set {
// ParseFiles parses the named files into a set of named templates.
// Each file must be parseable by itself.
// If an error occurs, parsing stops and the returned set is nil.
-func (s *Set) ParseFiles(filenames ...string) (*Set, os.Error) {
+func (s *Set) ParseFiles(filenames ...string) (*Set, error) {
for _, filename := range filenames {
b, err := ioutil.ReadFile(filename)
if err != nil {
@@ -97,7 +96,7 @@ func (s *Set) ParseFiles(filenames ...string) (*Set, os.Error) {
// ParseSetFiles creates a new Set and parses the set definition from the
// named files. Each file must be individually parseable.
-func ParseSetFiles(filenames ...string) (*Set, os.Error) {
+func ParseSetFiles(filenames ...string) (*Set, error) {
s := new(Set)
for _, filename := range filenames {
b, err := ioutil.ReadFile(filename)
@@ -116,7 +115,7 @@ func ParseSetFiles(filenames ...string) (*Set, os.Error) {
// pattern. The pattern is processed by filepath.Glob and must match at
// least one file.
// If an error occurs, parsing stops and the returned set is nil.
-func (s *Set) ParseGlob(pattern string) (*Set, os.Error) {
+func (s *Set) ParseGlob(pattern string) (*Set, error) {
filenames, err := filepath.Glob(pattern)
if err != nil {
return nil, err
@@ -130,7 +129,7 @@ func (s *Set) ParseGlob(pattern string) (*Set, os.Error) {
// ParseSetGlob creates a new Set and parses the set definition from the
// files identified by the pattern. The pattern is processed by filepath.Glob
// and must match at least one file.
-func ParseSetGlob(pattern string) (*Set, os.Error) {
+func ParseSetGlob(pattern string) (*Set, error) {
set, err := new(Set).ParseGlob(pattern)
if err != nil {
return nil, err
@@ -150,7 +149,7 @@ func ParseSetGlob(pattern string) (*Set, os.Error) {
// individual templates, which are then added to the set.
// Each file must be parseable by itself.
// If an error occurs, parsing stops and the returned set is nil.
-func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, os.Error) {
+func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, error) {
for _, filename := range filenames {
_, err := parseFileInSet(filename, s)
if err != nil {
@@ -170,7 +169,7 @@ func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, os.Error) {
// individual templates, which are then added to the set.
// Each file must be parseable by itself.
// If an error occurs, parsing stops and the returned set is nil.
-func (s *Set) ParseTemplateGlob(pattern string) (*Set, os.Error) {
+func (s *Set) ParseTemplateGlob(pattern string) (*Set, error) {
filenames, err := filepath.Glob(pattern)
if err != nil {
return nil, err
@@ -194,7 +193,7 @@ func (s *Set) ParseTemplateGlob(pattern string) (*Set, os.Error) {
// individual templates, which are then added to the set.
// Each file must be parseable by itself. Parsing stops if an error is
// encountered.
-func ParseTemplateFiles(filenames ...string) (*Set, os.Error) {
+func ParseTemplateFiles(filenames ...string) (*Set, error) {
set := new(Set)
set.init()
for _, filename := range filenames {
@@ -220,7 +219,7 @@ func ParseTemplateFiles(filenames ...string) (*Set, os.Error) {
// individual templates, which are then added to the set.
// Each file must be parseable by itself. Parsing stops if an error is
// encountered.
-func ParseTemplateGlob(pattern string) (*Set, os.Error) {
+func ParseTemplateGlob(pattern string) (*Set, error) {
set := new(Set)
filenames, err := filepath.Glob(pattern)
if err != nil {
diff --git a/libgo/go/template/parse.go b/libgo/go/template/parse.go
index 3068a77..2fbd37f 100644
--- a/libgo/go/template/parse.go
+++ b/libgo/go/template/parse.go
@@ -5,7 +5,6 @@
package template
import (
- "os"
"reflect"
"template/parse"
)
@@ -62,7 +61,7 @@ func (t *Template) Funcs(funcMap FuncMap) *Template {
// Parse parses the template definition string to construct an internal
// representation of the template for execution.
-func (t *Template) Parse(s string) (tmpl *Template, err os.Error) {
+func (t *Template) Parse(s string) (tmpl *Template, err error) {
t.Tree, err = parse.New(t.name).Parse(s, t.leftDelim, t.rightDelim, t.parseFuncs, builtins)
if err != nil {
return nil, err
@@ -74,7 +73,7 @@ func (t *Template) Parse(s string) (tmpl *Template, err os.Error) {
// representation of the template for execution. It also adds the template
// to the set.
// Function bindings are checked against those in the set.
-func (t *Template) ParseInSet(s string, set *Set) (tmpl *Template, err os.Error) {
+func (t *Template) ParseInSet(s string, set *Set) (tmpl *Template, err error) {
var setFuncs FuncMap
if set != nil {
setFuncs = set.parseFuncs
diff --git a/libgo/go/template/parse/node.go b/libgo/go/template/parse/node.go
index 7411327..a4e5514 100644
--- a/libgo/go/template/parse/node.go
+++ b/libgo/go/template/parse/node.go
@@ -9,7 +9,6 @@ package parse
import (
"bytes"
"fmt"
- "os"
"strconv"
"strings"
)
@@ -239,7 +238,7 @@ type NumberNode struct {
Text string // The original textual representation from the input.
}
-func newNumber(text string, typ itemType) (*NumberNode, os.Error) {
+func newNumber(text string, typ itemType) (*NumberNode, error) {
n := &NumberNode{NodeType: NodeNumber, Text: text}
switch typ {
case itemCharConstant:
diff --git a/libgo/go/template/parse/parse.go b/libgo/go/template/parse/parse.go
index 9934d82..1b6ab3a 100644
--- a/libgo/go/template/parse/parse.go
+++ b/libgo/go/template/parse/parse.go
@@ -8,7 +8,6 @@ package parse
import (
"fmt"
- "os"
"runtime"
"strconv"
"unicode"
@@ -75,7 +74,7 @@ func (t *Tree) errorf(format string, args ...interface{}) {
}
// error terminates processing.
-func (t *Tree) error(err os.Error) {
+func (t *Tree) error(err error) {
t.errorf("%s", err)
}
@@ -94,7 +93,7 @@ func (t *Tree) unexpected(token item, context string) {
}
// recover is the handler that turns panics into returns from the top level of Parse.
-func (t *Tree) recover(errp *os.Error) {
+func (t *Tree) recover(errp *error) {
e := recover()
if e != nil {
if _, ok := e.(runtime.Error); ok {
@@ -103,7 +102,7 @@ func (t *Tree) recover(errp *os.Error) {
if t != nil {
t.stopParse()
}
- *errp = e.(os.Error)
+ *errp = e.(error)
}
return
}
@@ -147,7 +146,7 @@ func (t *Tree) atEOF() bool {
// Parse parses the template definition string to construct an internal
// representation of the template for execution. If either action delimiter
// string is empty, the default ("{{" or "}}") is used.
-func (t *Tree) Parse(s, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree *Tree, err os.Error) {
+func (t *Tree) Parse(s, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree *Tree, err error) {
defer t.recover(&err)
t.startParse(funcs, lex(t.Name, s, leftDelim, rightDelim))
t.parse(true)
diff --git a/libgo/go/template/parse/set.go b/libgo/go/template/parse/set.go
index b909f71..d363eef 100644
--- a/libgo/go/template/parse/set.go
+++ b/libgo/go/template/parse/set.go
@@ -6,14 +6,13 @@ package parse
import (
"fmt"
- "os"
"strconv"
)
// Set returns a slice of Trees created by parsing the template set
// definition in the argument string. If an error is encountered,
// parsing stops and an empty slice is returned with the error.
-func Set(text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree map[string]*Tree, err os.Error) {
+func Set(text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree map[string]*Tree, err error) {
tree = make(map[string]*Tree)
defer (*Tree)(nil).recover(&err)
lex := lex("set", text, leftDelim, rightDelim)
diff --git a/libgo/go/template/set.go b/libgo/go/template/set.go
index 712961b..bd0dfc6 100644
--- a/libgo/go/template/set.go
+++ b/libgo/go/template/set.go
@@ -7,7 +7,6 @@ package template
import (
"fmt"
"io"
- "os"
"reflect"
"template/parse"
)
@@ -66,7 +65,7 @@ func (s *Set) Add(templates ...*Template) *Set {
}
// add adds the argument template to the set.
-func (s *Set) add(t *Template) os.Error {
+func (s *Set) add(t *Template) error {
s.init()
if t.set != nil {
return fmt.Errorf("template: %q already in a set", t.name)
@@ -92,7 +91,7 @@ func (s *Set) FuncMap() FuncMap {
// Execute applies the named template to the specified data object, writing
// the output to wr.
-func (s *Set) Execute(wr io.Writer, name string, data interface{}) os.Error {
+func (s *Set) Execute(wr io.Writer, name string, data interface{}) error {
tmpl := s.tmpl[name]
if tmpl == nil {
return fmt.Errorf("template: no template %q in set", name)
@@ -104,7 +103,7 @@ func (s *Set) Execute(wr io.Writer, name string, data interface{}) os.Error {
// multiple times for a given set, adding the templates defined in the string
// to the set. If a template is redefined, the element in the set is
// overwritten with the new definition.
-func (s *Set) Parse(text string) (*Set, os.Error) {
+func (s *Set) Parse(text string) (*Set, error) {
trees, err := parse.Set(text, s.leftDelim, s.rightDelim, s.parseFuncs, builtins)
if err != nil {
return nil, err