Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST: encode the specific form of pair in the AST #78

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m-ildefons
Copy link
Contributor

  • Encode the specific syntax type of key/value pair in the AST.
  • Move Tests for LABEL and ENV instructions 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 hadolint/hadolint#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.

Encode the specific syntax of key/value pair in the AST.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant