AST: encode the specific form of pair in the AST
- Encode the specific syntax type of key/value pair in the AST.
- Move Tests for
LABELandENVinstructions to their own files
Docker currently supports two forms for key value pairs. The key=value
syntax and the deprecated key value syntax. These are primarily used
in the ENV and LABEL instructions.
This change adds encoding for which form was parsed to the syntax tree.
Having this information can be used e.g. to warn about the use of
deprecated syntax and to specify which syntax form the pretty printer
should produce.
This is a draft PR because I am not sure if this is the best way to do this, but I need feedback to decide.
On the one hand this breaks backward compatibility quite badly, on the other hand, every other way to encode the parsed syntax version in the AST will also break backwards compatibility.
Motivation for this change is that it is needed for https://github.com/hadolint/hadolint/issues/752, because without it, looking at the AST does not show which syntax was used in the ENV respectively LABEL instruction.
An alternative implementation would be to extend the Pairs type such that it includes annotation about the syntax used something like so:
data PairSyntax
= DeprecatedPairSyntax
| RecommendedPairSyntax
type Pair = (Text, Text)
data Pairs =
{ pairs :: [Pair],
syntax :: PairSyntax
}
This would have the benefit that it might be possible to convert easily from [Pair] to Pairs and thus make migration less painful. However parsing becomes harder.