Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: src/pkg/text/template/parse/node.go

Issue 6459056: code review 6459056: text/template: add 'nil' as a keyword in the language (Closed)
Patch Set: diff -r 87e3318f6a52 https://code.google.com/p/go/ Created 12 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/text/template/parse/lex_test.go ('k') | src/pkg/text/template/parse/parse.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Parse nodes. 5 // Parse nodes.
6 6
7 package parse 7 package parse
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
(...skipping 26 matching lines...) Expand all
37 NodeAction // A simple action such as field evaluati on. 37 NodeAction // A simple action such as field evaluati on.
38 NodeBool // A boolean constant. 38 NodeBool // A boolean constant.
39 NodeCommand // An element of a pipeline. 39 NodeCommand // An element of a pipeline.
40 NodeDot // The cursor, dot. 40 NodeDot // The cursor, dot.
41 nodeElse // An else action. Not added to tree. 41 nodeElse // An else action. Not added to tree.
42 nodeEnd // An end action. Not added to tree. 42 nodeEnd // An end action. Not added to tree.
43 NodeField // A field or method name. 43 NodeField // A field or method name.
44 NodeIdentifier // An identifier; always a function name. 44 NodeIdentifier // An identifier; always a function name.
45 NodeIf // An if action. 45 NodeIf // An if action.
46 NodeList // A list of Nodes. 46 NodeList // A list of Nodes.
47 NodeNil // An untyped nil constant.
47 NodeNumber // A numerical constant. 48 NodeNumber // A numerical constant.
48 NodePipe // A pipeline of commands. 49 NodePipe // A pipeline of commands.
49 NodeRange // A range action. 50 NodeRange // A range action.
50 NodeString // A string constant. 51 NodeString // A string constant.
51 NodeTemplate // A template invocation action. 52 NodeTemplate // A template invocation action.
52 NodeVariable // A $ variable. 53 NodeVariable // A $ variable.
53 NodeWith // A with action. 54 NodeWith // A with action.
54 ) 55 )
55 56
56 // Nodes. 57 // Nodes.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 282 }
282 283
283 func (d *DotNode) String() string { 284 func (d *DotNode) String() string {
284 return "." 285 return "."
285 } 286 }
286 287
287 func (d *DotNode) Copy() Node { 288 func (d *DotNode) Copy() Node {
288 return newDot() 289 return newDot()
289 } 290 }
290 291
292 // NilNode holds the special identifier 'nil' representing an untyped nil consta nt.
293 // It is represented by a nil pointer.
294 type NilNode bool
295
296 func newNil() *NilNode {
297 return nil
298 }
299
300 func (d *NilNode) Type() NodeType {
301 return NodeNil
302 }
303
304 func (d *NilNode) String() string {
305 return "nil"
306 }
307
308 func (d *NilNode) Copy() Node {
309 return newNil()
310 }
311
291 // FieldNode holds a field (identifier starting with '.'). 312 // FieldNode holds a field (identifier starting with '.').
292 // The names may be chained ('.x.y'). 313 // The names may be chained ('.x.y').
293 // The period is dropped from each ident. 314 // The period is dropped from each ident.
294 type FieldNode struct { 315 type FieldNode struct {
295 NodeType 316 NodeType
296 Ident []string // The identifiers in lexical order. 317 Ident []string // The identifiers in lexical order.
297 } 318 }
298 319
299 func newField(ident string) *FieldNode { 320 func newField(ident string) *FieldNode {
300 return &FieldNode{NodeType: NodeField, Ident: strings.Split(ident[1:], " .")} // [1:] to drop leading period 321 return &FieldNode{NodeType: NodeField, Ident: strings.Split(ident[1:], " .")} // [1:] to drop leading period
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 func (t *TemplateNode) String() string { 620 func (t *TemplateNode) String() string {
600 if t.Pipe == nil { 621 if t.Pipe == nil {
601 return fmt.Sprintf("{{template %q}}", t.Name) 622 return fmt.Sprintf("{{template %q}}", t.Name)
602 } 623 }
603 return fmt.Sprintf("{{template %q %s}}", t.Name, t.Pipe) 624 return fmt.Sprintf("{{template %q %s}}", t.Name, t.Pipe)
604 } 625 }
605 626
606 func (t *TemplateNode) Copy() Node { 627 func (t *TemplateNode) Copy() Node {
607 return newTemplate(t.Line, t.Name, t.Pipe.CopyPipe()) 628 return newTemplate(t.Line, t.Name, t.Pipe.CopyPipe())
608 } 629 }
OLDNEW
« no previous file with comments | « src/pkg/text/template/parse/lex_test.go ('k') | src/pkg/text/template/parse/parse.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b