Browse code

builder: comments should also be elided in the middle of statements following a line continuation.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2014/10/15 17:44:14
Showing 3 changed files
... ...
@@ -98,11 +98,12 @@ func Parse(rwc io.Reader) (*Node, error) {
98 98
 	scanner := bufio.NewScanner(rwc)
99 99
 
100 100
 	for scanner.Scan() {
101
-		if scanner.Text() == "" {
101
+		scannedLine := strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace)
102
+		if stripComments(scannedLine) == "" {
102 103
 			continue
103 104
 		}
104 105
 
105
-		line, child, err := parseLine(strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace))
106
+		line, child, err := parseLine(scannedLine)
106 107
 		if err != nil {
107 108
 			return nil, err
108 109
 		}
... ...
@@ -111,7 +112,7 @@ func Parse(rwc io.Reader) (*Node, error) {
111 111
 			for scanner.Scan() {
112 112
 				newline := scanner.Text()
113 113
 
114
-				if newline == "" {
114
+				if stripComments(strings.TrimSpace(newline)) == "" {
115 115
 					continue
116 116
 				}
117 117
 
... ...
@@ -26,3 +26,10 @@ frog
26 26
 RUN echo good\
27 27
 bye\
28 28
 frog
29
+
30
+RUN echo hello \
31
+# this is a comment
32
+
33
+# this is a comment with a blank line surrounding it
34
+
35
+this is some more useful stuff
... ...
@@ -7,3 +7,4 @@
7 7
 (run "echo hi   world  goodnight")
8 8
 (run "echo goodbyefrog")
9 9
 (run "echo goodbyefrog")
10
+(run "echo hello this is some more useful stuff")