Implementations must act as if they used the following algorithm to parse POSIX-compliant dotenv files.
The input to the parsing stage is a sequence of tokens from the tokenization stage.
The output of the parsing stage is the result of parsing an assignment list.
The next token is the first token in the input token sequence that has not yet been consumed. Initially, the next token is the first token in the input token sequence.
The current token is the last token to have been consumed.
- Let
node-list
be a new empty list. - Consume the next token.
- loop:
- Switch on the current token:
EOF
:- return
node-list
.
- return
Assign
:- let
node
be the result of parsing an assignment. - append
node
tonode-list
.
- let
- anything else:
- Parse error.
- Switch on the current token:
- Create a new
Assignment
node. - set the node's
name
attribute to the current token's value. - set the node's
value
attribute to the result of parsing an assignment value. - return the node.
- Let
node-list
be a new empty list. - loop:
- Consume the next token.
EOF
,Assign
:- return
node-list
.
- return
Characters
:- Create a new
Characters
node. - set the node's
value
attribute to the current token's value. - append the newly created node to
node-list
.
- Create a new
SimpleExpansion
:- Create a new
Expansion
node. - set the node's
name
attribute to the current token's value. - set the node's
operator
attribute to-
(U+002D HYPHEN-MINUS). - set the node's
value
attribute to an empty list. - append the newly created node to
node-list
.
- Create a new
StartExpansion
:- Create a new
Expansion
node. - set the node's
name
attribute to the current token's value. - set the node's
operator
attribute to the result of parsing an expansion operator. - set the node's
value
attribute to the result of parsing an expansion value. - append the newly created node to
node-list
.
- Create a new
- anything else:
- Parse error.
- Consume the next token.
Consume the next token.
ExpansionOperator
:- return the current token's value.
- anything else:
- Parse error.
- Let
node-list
be a new empty list. - loop:
- Consume the next token.
EndExpansion
:- return
node-list
.
- return
Characters
:- Create a new
Characters
node. - set the node's
value
attribute to the current token's value. - append the newly created node to
node-list
.
- Create a new
SimpleExpansion
:- Create a new
Expansion
node. - set the node's
name
attribute to the current token's value. - set the node's
operator
attribute to-
(U+002D HYPHEN-MINUS). - set the node's
value
attribute to an empty list. - append the newly created node to
node-list
.
- Create a new
StartExpansion
:- Create a new
Expansion
node. - set the node's
name
attribute to the current token's value. - set the node's
operator
attribute to the result of parsing an expansion operator. - set the node's
value
attribute to the result of parsing an expansion value. - append the newly created node to
node-list
.
- Create a new
- anything else:
- Parse error.
- Consume the next token.