summaryrefslogtreecommitdiff
path: root/src/pkg/exp/datafmt/datafmt.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/exp/datafmt/datafmt.go')
-rw-r--r--src/pkg/exp/datafmt/datafmt.go25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/pkg/exp/datafmt/datafmt.go b/src/pkg/exp/datafmt/datafmt.go
index 10e4b54f9..6d7e76442 100644
--- a/src/pkg/exp/datafmt/datafmt.go
+++ b/src/pkg/exp/datafmt/datafmt.go
@@ -211,7 +211,6 @@ import (
"runtime"
)
-
// ----------------------------------------------------------------------------
// Format representation
@@ -228,13 +227,11 @@ import (
//
type Formatter func(state *State, value interface{}, ruleName string) bool
-
// A FormatterMap is a set of custom formatters.
// It maps a rule name to a formatter function.
//
type FormatterMap map[string]Formatter
-
// A parsed format expression is built from the following nodes.
//
type (
@@ -269,13 +266,11 @@ type (
}
)
-
// A Format is the result of parsing a format specification.
// The format may be applied repeatedly to format values.
//
type Format map[string]expr
-
// ----------------------------------------------------------------------------
// Formatting
@@ -293,7 +288,6 @@ type Environment interface {
Copy() Environment
}
-
// State represents the current formatting state.
// It is provided as argument to custom formatters.
//
@@ -309,7 +303,6 @@ type State struct {
separator expr // possibly nil
}
-
func newState(fmt Format, env Environment, errors chan os.Error) *State {
s := new(State)
s.fmt = fmt
@@ -317,12 +310,12 @@ func newState(fmt Format, env Environment, errors chan os.Error) *State {
s.errors = errors
s.linePos = token.Position{Line: 1}
- // if we have a default rule, cache it's expression for fast access
+ // if we have a default rule, cache its expression for fast access
if x, found := fmt["default"]; found {
s.default_ = x
}
- // if we have a global separator rule, cache it's expression for fast access
+ // if we have a global separator rule, cache its expression for fast access
if x, found := fmt["/"]; found {
s.separator = x
}
@@ -330,17 +323,14 @@ func newState(fmt Format, env Environment, errors chan os.Error) *State {
return s
}
-
// Env returns the environment passed to Format.Apply.
func (s *State) Env() interface{} { return s.env }
-
// LinePos returns the position of the current line beginning
// in the state's output buffer. Line numbers start at 1.
//
func (s *State) LinePos() token.Position { return s.linePos }
-
// Pos returns the position of the next byte to be written to the
// output buffer. Line numbers start at 1.
//
@@ -349,7 +339,6 @@ func (s *State) Pos() token.Position {
return token.Position{Line: s.linePos.Line, Column: offs - s.linePos.Offset, Offset: offs}
}
-
// Write writes data to the output buffer, inserting the indentation
// string after each newline or form feed character. It cannot return an error.
//
@@ -371,7 +360,6 @@ func (s *State) Write(data []byte) (int, os.Error) {
return n + n3, nil
}
-
type checkpoint struct {
env Environment
hasOutput bool
@@ -379,7 +367,6 @@ type checkpoint struct {
linePos token.Position
}
-
func (s *State) save() checkpoint {
saved := checkpoint{nil, s.hasOutput, s.output.Len(), s.linePos}
if s.env != nil {
@@ -388,19 +375,16 @@ func (s *State) save() checkpoint {
return saved
}
-
func (s *State) restore(m checkpoint) {
s.env = m.env
s.output.Truncate(m.outputLen)
}
-
func (s *State) error(msg string) {
s.errors <- os.NewError(msg)
runtime.Goexit()
}
-
// TODO At the moment, unnamed types are simply mapped to the default
// names below. For instance, all unnamed arrays are mapped to
// 'array' which is not really sufficient. Eventually one may want
@@ -440,7 +424,6 @@ func (s *State) getFormat(name string) expr {
return nil
}
-
// eval applies a format expression fexpr to a value. If the expression
// evaluates internally to a non-nil []byte, that slice is appended to
// the state's output buffer and eval returns true. Otherwise, eval
@@ -653,7 +636,6 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
return false
}
-
// Eval formats each argument according to the format
// f and returns the resulting []byte and os.Error. If
// an error occurred, the []byte contains the partially
@@ -688,7 +670,6 @@ func (f Format) Eval(env Environment, args ...interface{}) ([]byte, os.Error) {
return s.output.Bytes(), err
}
-
// ----------------------------------------------------------------------------
// Convenience functions
@@ -705,7 +686,6 @@ func (f Format) Fprint(w io.Writer, env Environment, args ...interface{}) (int,
return w.Write(data)
}
-
// Print formats each argument according to the format f
// and writes to standard output. The result is the total
// number of bytes written and an os.Error, if any.
@@ -714,7 +694,6 @@ func (f Format) Print(args ...interface{}) (int, os.Error) {
return f.Fprint(os.Stdout, nil, args...)
}
-
// Sprint formats each argument according to the format f
// and returns the resulting string. If an error occurs
// during formatting, the result string contains the