1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

builder: Remove blankNode(), use &Node{} instead.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
Erik Hollensbe 2014-08-10 04:01:10 -07:00
parent 21b15ac920
commit 135f54ccbf
2 changed files with 10 additions and 15 deletions

View file

@ -20,7 +20,7 @@ var (
// ignore the current argument. This will still leave a command parsed, but // ignore the current argument. This will still leave a command parsed, but
// will not incorporate the arguments into the ast. // will not incorporate the arguments into the ast.
func parseIgnore(rest string) (*Node, error) { func parseIgnore(rest string) (*Node, error) {
return blankNode(), nil return &Node{}, nil
} }
// used for onbuild. Could potentially be used for anything that represents a // used for onbuild. Could potentially be used for anything that represents a
@ -40,11 +40,11 @@ func parseSubCommand(rest string) (*Node, error) {
// parse environment like statements. Note that this does *not* handle // parse environment like statements. Note that this does *not* handle
// variable interpolation, which will be handled in the evaluator. // variable interpolation, which will be handled in the evaluator.
func parseEnv(rest string) (*Node, error) { func parseEnv(rest string) (*Node, error) {
node := blankNode() node := &Node{}
rootnode := node rootnode := node
strs := TOKEN_WHITESPACE.Split(rest, 2) strs := TOKEN_WHITESPACE.Split(rest, 2)
node.Value = strs[0] node.Value = strs[0]
node.Next = blankNode() node.Next = &Node{}
node.Next.Value = strs[1] node.Next.Value = strs[1]
return rootnode, nil return rootnode, nil
@ -53,13 +53,13 @@ func parseEnv(rest string) (*Node, error) {
// parses a whitespace-delimited set of arguments. The result is effectively a // parses a whitespace-delimited set of arguments. The result is effectively a
// linked list of string arguments. // linked list of string arguments.
func parseStringsWhitespaceDelimited(rest string) (*Node, error) { func parseStringsWhitespaceDelimited(rest string) (*Node, error) {
node := blankNode() node := &Node{}
rootnode := node rootnode := node
prevnode := node prevnode := node
for _, str := range TOKEN_WHITESPACE.Split(rest, -1) { // use regexp for _, str := range TOKEN_WHITESPACE.Split(rest, -1) { // use regexp
prevnode = node prevnode = node
node.Value = str node.Value = str
node.Next = blankNode() node.Next = &Node{}
node = node.Next node = node.Next
} }
@ -80,7 +80,7 @@ func parseString(rest string) (*Node, error) {
func parseJSON(rest string) (*Node, error) { func parseJSON(rest string) (*Node, error) {
var ( var (
myJson []interface{} myJson []interface{}
next = blankNode() next = &Node{}
orignext = next orignext = next
prevnode = next prevnode = next
) )
@ -98,7 +98,7 @@ func parseJSON(rest string) (*Node, error) {
return nil, dockerFileErrJSONNesting return nil, dockerFileErrJSONNesting
} }
next.Value = str.(string) next.Value = str.(string)
next.Next = blankNode() next.Next = &Node{}
prevnode = next prevnode = next
next = next.Next next = next.Next
} }
@ -124,7 +124,7 @@ func parseMaybeJSON(rest string) (*Node, error) {
} }
} }
node := blankNode() node := &Node{}
node.Value = rest node.Value = rest
return node, nil return node, nil
} }

View file

@ -59,11 +59,6 @@ func init() {
} }
} }
// empty node. Useful for managing structure.
func blankNode() *Node {
return &Node{"", nil, []*Node{}}
}
// parse a line and return the remainder. // parse a line and return the remainder.
func parseLine(line string) (string, *Node, error) { func parseLine(line string) (string, *Node, error) {
if line = stripComments(line); line == "" { if line = stripComments(line); line == "" {
@ -77,7 +72,7 @@ func parseLine(line string) (string, *Node, error) {
cmd, args := splitCommand(line) cmd, args := splitCommand(line)
node := blankNode() node := &Node{}
node.Value = cmd node.Value = cmd
sexp, err := fullDispatch(cmd, args) sexp, err := fullDispatch(cmd, args)
@ -96,7 +91,7 @@ func Parse(rwc io.Reader) (*Node, error) {
var child *Node var child *Node
var line string var line string
var err error var err error
root := blankNode() root := &Node{}
scanner := bufio.NewScanner(rwc) scanner := bufio.NewScanner(rwc)
for scanner.Scan() { for scanner.Scan() {