2121
2222// ignore the current argument. This will still leave a command parsed, but
2323// will not incorporate the arguments into the ast.
24- func parseIgnore (rest string ) (* Node , map [string ]bool , error ) {
24+ func parseIgnore (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
2525 return & Node {}, nil , nil
2626}
2727
@@ -30,12 +30,12 @@ func parseIgnore(rest string) (*Node, map[string]bool, error) {
3030//
3131// ONBUILD RUN foo bar -> (onbuild (run foo bar))
3232//
33- func parseSubCommand (rest string ) (* Node , map [string ]bool , error ) {
33+ func parseSubCommand (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
3434 if rest == "" {
3535 return nil , nil , nil
3636 }
3737
38- _ , child , err := ParseLine (rest )
38+ _ , child , err := ParseLine (rest , d )
3939 if err != nil {
4040 return nil , nil , err
4141 }
@@ -46,7 +46,7 @@ func parseSubCommand(rest string) (*Node, map[string]bool, error) {
4646// helper to parse words (i.e space delimited or quoted strings) in a statement.
4747// The quotes are preserved as part of this function and they are stripped later
4848// as part of processWords().
49- func parseWords (rest string ) []string {
49+ func parseWords (rest string , d * Directive ) []string {
5050 const (
5151 inSpaces = iota // looking for start of a word
5252 inWord
@@ -96,7 +96,7 @@ func parseWords(rest string) []string {
9696 blankOK = true
9797 phase = inQuote
9898 }
99- if ch == tokenEscape {
99+ if ch == d . EscapeToken {
100100 if pos + chWidth == len (rest ) {
101101 continue // just skip an escape token at end of line
102102 }
@@ -115,7 +115,7 @@ func parseWords(rest string) []string {
115115 phase = inWord
116116 }
117117 // The escape token is special except for ' quotes - can't escape anything for '
118- if ch == tokenEscape && quote != '\'' {
118+ if ch == d . EscapeToken && quote != '\'' {
119119 if pos + chWidth == len (rest ) {
120120 phase = inWord
121121 continue // just skip the escape token at end
@@ -133,14 +133,14 @@ func parseWords(rest string) []string {
133133
134134// parse environment like statements. Note that this does *not* handle
135135// variable interpolation, which will be handled in the evaluator.
136- func parseNameVal (rest string , key string ) (* Node , map [string ]bool , error ) {
136+ func parseNameVal (rest string , key string , d * Directive ) (* Node , map [string ]bool , error ) {
137137 // This is kind of tricky because we need to support the old
138138 // variant: KEY name value
139139 // as well as the new one: KEY name=value ...
140140 // The trigger to know which one is being used will be whether we hit
141141 // a space or = first. space ==> old, "=" ==> new
142142
143- words := parseWords (rest )
143+ words := parseWords (rest , d )
144144 if len (words ) == 0 {
145145 return nil , nil , nil
146146 }
@@ -187,12 +187,12 @@ func parseNameVal(rest string, key string) (*Node, map[string]bool, error) {
187187 return rootnode , nil , nil
188188}
189189
190- func parseEnv (rest string ) (* Node , map [string ]bool , error ) {
191- return parseNameVal (rest , "ENV" )
190+ func parseEnv (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
191+ return parseNameVal (rest , "ENV" , d )
192192}
193193
194- func parseLabel (rest string ) (* Node , map [string ]bool , error ) {
195- return parseNameVal (rest , "LABEL" )
194+ func parseLabel (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
195+ return parseNameVal (rest , "LABEL" , d )
196196}
197197
198198// parses a statement containing one or more keyword definition(s) and/or
@@ -203,8 +203,8 @@ func parseLabel(rest string) (*Node, map[string]bool, error) {
203203// In addition, a keyword definition alone is of the form `keyword` like `name1`
204204// above. And the assignments `name2=` and `name3=""` are equivalent and
205205// assign an empty value to the respective keywords.
206- func parseNameOrNameVal (rest string ) (* Node , map [string ]bool , error ) {
207- words := parseWords (rest )
206+ func parseNameOrNameVal (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
207+ words := parseWords (rest , d )
208208 if len (words ) == 0 {
209209 return nil , nil , nil
210210 }
@@ -229,7 +229,7 @@ func parseNameOrNameVal(rest string) (*Node, map[string]bool, error) {
229229
230230// parses a whitespace-delimited set of arguments. The result is effectively a
231231// linked list of string arguments.
232- func parseStringsWhitespaceDelimited (rest string ) (* Node , map [string ]bool , error ) {
232+ func parseStringsWhitespaceDelimited (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
233233 if rest == "" {
234234 return nil , nil , nil
235235 }
@@ -253,7 +253,7 @@ func parseStringsWhitespaceDelimited(rest string) (*Node, map[string]bool, error
253253}
254254
255255// parsestring just wraps the string in quotes and returns a working node.
256- func parseString (rest string ) (* Node , map [string ]bool , error ) {
256+ func parseString (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
257257 if rest == "" {
258258 return nil , nil , nil
259259 }
@@ -263,7 +263,7 @@ func parseString(rest string) (*Node, map[string]bool, error) {
263263}
264264
265265// parseJSON converts JSON arrays to an AST.
266- func parseJSON (rest string ) (* Node , map [string ]bool , error ) {
266+ func parseJSON (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
267267 rest = strings .TrimLeftFunc (rest , unicode .IsSpace )
268268 if ! strings .HasPrefix (rest , "[" ) {
269269 return nil , nil , fmt .Errorf (`Error parsing "%s" as a JSON array` , rest )
@@ -296,12 +296,12 @@ func parseJSON(rest string) (*Node, map[string]bool, error) {
296296// parseMaybeJSON determines if the argument appears to be a JSON array. If
297297// so, passes to parseJSON; if not, quotes the result and returns a single
298298// node.
299- func parseMaybeJSON (rest string ) (* Node , map [string ]bool , error ) {
299+ func parseMaybeJSON (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
300300 if rest == "" {
301301 return nil , nil , nil
302302 }
303303
304- node , attrs , err := parseJSON (rest )
304+ node , attrs , err := parseJSON (rest , d )
305305
306306 if err == nil {
307307 return node , attrs , nil
@@ -318,8 +318,8 @@ func parseMaybeJSON(rest string) (*Node, map[string]bool, error) {
318318// parseMaybeJSONToList determines if the argument appears to be a JSON array. If
319319// so, passes to parseJSON; if not, attempts to parse it as a whitespace
320320// delimited string.
321- func parseMaybeJSONToList (rest string ) (* Node , map [string ]bool , error ) {
322- node , attrs , err := parseJSON (rest )
321+ func parseMaybeJSONToList (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
322+ node , attrs , err := parseJSON (rest , d )
323323
324324 if err == nil {
325325 return node , attrs , nil
@@ -328,11 +328,11 @@ func parseMaybeJSONToList(rest string) (*Node, map[string]bool, error) {
328328 return nil , nil , err
329329 }
330330
331- return parseStringsWhitespaceDelimited (rest )
331+ return parseStringsWhitespaceDelimited (rest , d )
332332}
333333
334334// The HEALTHCHECK command is like parseMaybeJSON, but has an extra type argument.
335- func parseHealthConfig (rest string ) (* Node , map [string ]bool , error ) {
335+ func parseHealthConfig (rest string , d * Directive ) (* Node , map [string ]bool , error ) {
336336 // Find end of first argument
337337 var sep int
338338 for ; sep < len (rest ); sep ++ {
@@ -352,7 +352,7 @@ func parseHealthConfig(rest string) (*Node, map[string]bool, error) {
352352 }
353353
354354 typ := rest [:sep ]
355- cmd , attrs , err := parseMaybeJSON (rest [next :])
355+ cmd , attrs , err := parseMaybeJSON (rest [next :], d )
356356 if err != nil {
357357 return nil , nil , err
358358 }
0 commit comments