os.ErrorString
}
-// All the literals are aces.
+// Most of the literals are aces.
var lbrace = []byte{ '{' }
var rbrace = []byte{ '}' }
var space = []byte{ ' ' }
+var tab = []byte{ '\t' }
// The various types of "tokens", which are plain text or (usually) brace-delimited descriptors
const (
return;
}
switch w[0] {
- case ".meta-left", ".meta-right", ".space":
+ case ".meta-left", ".meta-right", ".space", ".tab":
tok = tokLiteral;
return;
case ".or":
t.elems.Push(&literalElement{t.rdelim});
case ".space":
t.elems.Push(&literalElement{space});
+ case ".tab":
+ t.elems.Push(&literalElement{tab});
default:
t.parseError("internal error: unknown literal: %s", w[0]);
}
return true;
}
-// Public interface
+// -- Public interface
// Parse initializes a Template by parsing its definition. The string
// s contains the template text. If any errors occur, Parse returns
t.parse();
t.errorchan <- nil; // clean return;
}();
- err = <-t.errorchan;
- return
+ return <-t.errorchan;
}
-// Execute executes a parsed template on the specified data object,
+// Execute applies a parsed template to the specified data object,
// generating output to wr.
func (t *Template) Execute(data interface{}, wr io.Write) os.Error {
// Extract the driver data.
&Test{ " {.meta-left} \n", "{" },
&Test{ " {.meta-right} \n", "}" },
&Test{ " {.space} \n", " " },
+ &Test{ " {.tab} \n", "\t" },
&Test{ " {#comment} \n", "" },
// Variables at top level