@@ -53,27 +53,65 @@ YAML configuration files MUST use file extensions `.yaml` or `.yml`.
5353
5454#### Environment variable substitution
5555
56- Configuration files support environment variables substitution for references
57- which match the following PCRE2 regular expression:
56+ Configuration files support environment variables substitution for references,
57+ defined using
58+ the [ Augmented Backus-Naur Form] ( https://tools.ietf.org/html/rfc5234 ) :
5859
59- ``` regexp
60- \$\{(?:env:)?(?<ENV_NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT_VALUE>[^\n]*))?\}
60+ ``` abnf
61+ SUBSTITUTION-REF = "${" ["env:"] ENV-NAME [":-" DEFAULT-VALUE] "}"; valid substitution reference
62+ INVALID-SUBSTITUTION-REF = "${" *(VCHAR-WSP-NO-RBRACE) "}"; invalid substitution reference
63+
64+ ENV-NAME = (ALPHA / "_") *(ALPHA / DIGIT / "_"); the name of the variable to be substituted
65+ DEFAULT-VALUE = *(VCHAR-WSP-NO-RBRACE); any number of VCHAR-WSP-NO-RBRACE
66+ VCHAR-WSP-NO-RBRACE = %x21-7C / "~" / WSP; printable chars and whitespace, except }
67+
68+ ALPHA = %x41-5A / %x61-7A; A-Z / a-z
69+ DIGIT = %x30-39 ; 0-9
6170```
6271
63- The ` ENV_NAME ` MUST start with an alphabetic or ` _ ` character, and is followed
64- by 0 or more alphanumeric or ` _ ` characters.
72+ ` SUBSTITUTION-REF ` defines a valid environment variable substitution reference:
73+
74+ * Must start with ` ${ `
75+ * Optionally followed by ` env: `
76+ * Must follow with ` REF-NAME ` , the name of the environment variable to be
77+ substituted
78+ * Must start with alphabetic or ` _ ` character
79+ * Must follow with any number of alphanumeric or ` _ ` characters
80+ * Optionally followed by default value
81+ * Must start with ` :- `
82+ * Must follow with ` DEFAULT-VALUE ` , any number of printable characters and
83+ whitespace except ` } `
84+ * Must follow with ` } `
85+
86+ ` INVALID-SUBSTITUTION-REF ` defines an invalid environment variable substitution
87+ reference:
88+
89+ * Must start with ` ${ `
90+ * Must follow with any number of printable characters and whitespace except ` } `
91+ * Must follow with ` } `
92+
93+ For convenience, ` SUBSTITUTION-REF ` and ` INVALID-SUBSTITUTION-REF ` are expressed
94+ below as a PCRE2 regular expressions. Note that these expressions are
95+ non-normative.
96+
97+ ``` regexp
98+ // SUBSTITUTION-REF
99+ \$\{(?:env:)?(?<ENV-NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT-VALUE>[^\n]*))?\}
100+
101+ // INVALID-SUBSTITUTION-REF
102+ \$\{(?<INVALID_IDENTIFIER>[^}]+)\}
103+ ```
65104
66105For example, ` ${API_KEY} ` and ` ${env:API_KEY} ` are valid, while ` ${1API_KEY} `
67106and ` ${API_$KEY} ` are invalid.
68107
69108Environment variable substitution MUST only apply to scalar values. Mapping keys
70109are not candidates for substitution.
71110
72- The ` DEFAULT_VALUE ` is an optional fallback value which is substituted
73- if ` ENV_NAME ` is null, empty, or undefined. ` DEFAULT_VALUE ` consists of 0 or
74- more non line break characters (i.e. any character except ` \n ` ). If a referenced
75- environment variable is not defined and does not have a ` DEFAULT_VALUE ` , it MUST
76- be replaced with an empty value.
111+ The ` DEFAULT-VALUE ` component of ` SUBSTITUTION-REF ` is an optional fallback
112+ value which is substituted if ` ENV-NAME ` is null, empty, or undefined. If a
113+ referenced environment variable is not defined and does not have
114+ a ` DEFAULT-VALUE ` , it MUST be replaced with an empty value.
77115
78116The ` $ ` character is an escape sequence, such that ` $$ ` in the input is
79117translated to a single ` $ ` in the output. The resolved ` $ ` from an escape
@@ -83,7 +121,7 @@ to `${API_KEY}`, and the value of the `API_KEY` environment variable is NOT
83121substituted. See table below for more examples. In practice, this implies that
84122parsers consume the input from left to right, iteratively identifying the next
85123escape sequence, and matching the content since the prior escape sequence
86- against the environment variable substitution regular expression .
124+ against ` SUBSTITUTION-REF ` .
87125
88126For example, the pseudocode for processing input ` $${FOO} ${BAR} $${BAZ} `
89127where ` FOO=a, BAR=b, BAZ=c ` would resemble:
@@ -98,14 +136,10 @@ where `FOO=a, BAR=b, BAZ=c` would resemble:
98136 against ` input.substring(15+2, input.length)="{BAZ}" ` => ` "{BAZ}" ` and append
99137 to output. Return output: ` "${FOO} b ${BAZ}" ` .
100138
101- When parsing a configuration file that contains a reference not matching
102- the references regular expression but does match the following PCRE2
103- regular expression, the parser MUST return an empty result (no partial
104- results are allowed) and an error describing the parse failure to the user.
105-
106- ``` regexp
107- \$\{(?<INVALID_IDENTIFIER>[^}]+)\}
108- ```
139+ When parsing a configure file that contains a reference not
140+ matching ` SUBSTITUTION-REF ` but matching ` INVALID-SUBSTITUTION-REF ` , the parser
141+ must return an empty result (no partial results are allowed) and an error
142+ describing the parse failure to the user.
109143
110144Node types MUST be interpreted after environment variable substitution takes
111145place. This ensures the environment string representation of boolean, integer,
0 commit comments