diff options
Diffstat (limited to 'src/pkg/exp/datafmt')
-rw-r--r-- | src/pkg/exp/datafmt/datafmt.go | 42 | ||||
-rw-r--r-- | src/pkg/exp/datafmt/parser.go | 10 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/pkg/exp/datafmt/datafmt.go b/src/pkg/exp/datafmt/datafmt.go index 46c412342..6d816fc2d 100644 --- a/src/pkg/exp/datafmt/datafmt.go +++ b/src/pkg/exp/datafmt/datafmt.go @@ -408,20 +408,20 @@ func (s *State) error(msg string) { // func typename(typ reflect.Type) string { - switch typ.(type) { - case *reflect.ArrayType: + switch typ.Kind() { + case reflect.Array: return "array" - case *reflect.SliceType: + case reflect.Slice: return "array" - case *reflect.ChanType: + case reflect.Chan: return "chan" - case *reflect.FuncType: + case reflect.Func: return "func" - case *reflect.InterfaceType: + case reflect.Interface: return "interface" - case *reflect.MapType: + case reflect.Map: return "map" - case *reflect.PtrType: + case reflect.Ptr: return "ptr" } return typ.String() @@ -519,38 +519,38 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool { case "*": // indirection: operation is type-specific - switch v := value.(type) { - case *reflect.ArrayValue: + switch v := value; v.Kind() { + case reflect.Array: if v.Len() <= index { return false } - value = v.Elem(index) + value = v.Index(index) - case *reflect.SliceValue: + case reflect.Slice: if v.IsNil() || v.Len() <= index { return false } - value = v.Elem(index) + value = v.Index(index) - case *reflect.MapValue: + case reflect.Map: s.error("reflection support for maps incomplete") - case *reflect.PtrValue: + case reflect.Ptr: if v.IsNil() { return false } value = v.Elem() - case *reflect.InterfaceValue: + case reflect.Interface: if v.IsNil() { return false } value = v.Elem() - case *reflect.ChanValue: + case reflect.Chan: s.error("reflection support for chans incomplete") - case *reflect.FuncValue: + case reflect.Func: s.error("reflection support for funcs incomplete") default: @@ -560,9 +560,9 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool { default: // value is value of named field var field reflect.Value - if sval, ok := value.(*reflect.StructValue); ok { + if sval := value; sval.Kind() == reflect.Struct { field = sval.FieldByName(t.fieldName) - if field == nil { + if !field.IsValid() { // TODO consider just returning false in this case s.error(fmt.Sprintf("error: no field `%s` in `%s`", t.fieldName, value.Type())) } @@ -672,7 +672,7 @@ func (f Format) Eval(env Environment, args ...interface{}) ([]byte, os.Error) { go func() { for _, v := range args { fld := reflect.NewValue(v) - if fld == nil { + if !fld.IsValid() { errors <- os.NewError("nil argument") return } diff --git a/src/pkg/exp/datafmt/parser.go b/src/pkg/exp/datafmt/parser.go index c6d140264..7dedb531a 100644 --- a/src/pkg/exp/datafmt/parser.go +++ b/src/pkg/exp/datafmt/parser.go @@ -22,7 +22,7 @@ type parser struct { file *token.File pos token.Pos // token position tok token.Token // one token look-ahead - lit []byte // token literal + lit string // token literal packs map[string]string // PackageName -> ImportPath rules map[string]expr // RuleName -> Expression @@ -62,7 +62,7 @@ func (p *parser) errorExpected(pos token.Pos, msg string) { // make the error message more specific msg += ", found '" + p.tok.String() + "'" if p.tok.IsLiteral() { - msg += " " + string(p.lit) + msg += " " + p.lit } } p.error(pos, msg) @@ -80,7 +80,7 @@ func (p *parser) expect(tok token.Token) token.Pos { func (p *parser) parseIdentifier() string { - name := string(p.lit) + name := p.lit p.expect(token.IDENT) return name } @@ -130,7 +130,7 @@ func (p *parser) parseRuleName() (string, bool) { func (p *parser) parseString() string { s := "" if p.tok == token.STRING { - s, _ = strconv.Unquote(string(p.lit)) + s, _ = strconv.Unquote(p.lit) // Unquote may fail with an error, but only if the scanner found // an illegal string in the first place. In this case the error // has already been reported. @@ -181,7 +181,7 @@ func (p *parser) parseField() expr { var fname string switch p.tok { case token.ILLEGAL: - if string(p.lit) != "@" { + if p.lit != "@" { return nil } fname = "@" |