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-listbe a new empty list. - Consume the next token.
- loop:
- Switch on the current token:
EOF:- return
node-list.
- return
Assign:- let
nodebe the result of parsing an assignment. - append
nodetonode-list.
- let
- anything else:
- Parse error.
- Switch on the current token:
- Create a new
Assignmentnode. - set the node's
nameattribute to the current token's value. - set the node's
valueattribute to the result of parsing an assignment value. - return the node.
- Let
node-listbe a new empty list. - loop:
- Consume the next token.
EOF,Assign:- return
node-list.
- return
Characters:- Create a new
Charactersnode. - set the node's
valueattribute to the current token's value. - append the newly created node to
node-list.
- Create a new
SimpleExpansion:- Create a new
Expansionnode. - set the node's
nameattribute to the current token's value. - set the node's
operatorattribute to-(U+002D HYPHEN-MINUS). - set the node's
valueattribute to an empty list. - append the newly created node to
node-list.
- Create a new
StartExpansion:- Create a new
Expansionnode. - set the node's
nameattribute to the current token's value. - set the node's
operatorattribute to the result of parsing an expansion operator. - set the node's
valueattribute 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-listbe a new empty list. - loop:
- Consume the next token.
EndExpansion:- return
node-list.
- return
Characters:- Create a new
Charactersnode. - set the node's
valueattribute to the current token's value. - append the newly created node to
node-list.
- Create a new
SimpleExpansion:- Create a new
Expansionnode. - set the node's
nameattribute to the current token's value. - set the node's
operatorattribute to-(U+002D HYPHEN-MINUS). - set the node's
valueattribute to an empty list. - append the newly created node to
node-list.
- Create a new
StartExpansion:- Create a new
Expansionnode. - set the node's
nameattribute to the current token's value. - set the node's
operatorattribute to the result of parsing an expansion operator. - set the node's
valueattribute 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.