whitespace = _{ " " } comment = { whitespace* ~ "#" ~ (ASCII_ALPHANUMERIC | "_" | "-" | "$" | "=" | "{" | "}" | whitespace)* } env_key = { ("_" | ASCII_ALPHA) ~ ("_" | ASCII_ALPHANUMERIC)+ } // Interpolations can appear in a few spots. braced_interpolation = _{ "${" ~ env_key ~ "}" } unbraced_interpolation = _{ "$" ~ env_key } interpolation = { braced_interpolation | unbraced_interpolation } // Unquoted value characters are different from quoted ones. unquoted_character = { ASCII_ALPHANUMERIC | "-" | interpolation } unquoted_value = _{ (unquoted_character | interpolation)+ } quoted_character = { ASCII_ALPHANUMERIC | ":" | "." | "," | "_" | whitespace } quoted_value = { (quoted_character | interpolation)* } multiline_value = { (quoted_character | interpolation | NEWLINE)* } multiline_value_no_interpolation_character = { "$" | "{" | "}" } multiline_value_no_interpolation = { (quoted_character | multiline_value_no_interpolation_character | NEWLINE)* } // There are a few different kinds of values in .env files. unquoted = { unquoted_value } single_quoted = _{ "'" ~ quoted_value ~ "'" } double_quoted = _{ "\"" ~ quoted_value ~ "\"" } triple_single = _{ "'''" ~ multiline_value_no_interpolation ~ "'''" } triple_double = _{ "\"\"\"" ~ multiline_value ~ "\"\"\"" } env_value = _{ triple_single | triple_double | single_quoted | double_quoted } assignment = { "export "? ~ env_key ~ "=" ~ ( (whitespace? ~ unquoted) | env_value )? } emptyline = { NEWLINE } line = { assignment | comment | emptyline } file = { SOI ~ line* ~ EOI }