Closed jaxwilko closed 1 year ago
@jaxwilko if this is to be a true lexer and parsing an environment file into an AST, I would suggest making the initial environment variable a token, as well as the equals sign (and possibly even the whitespace between), so you get a true representation of each portion of the code.
Another little edge case to consider - I believe you can set an environment variable with no value whatsoever, which is the same as setting the environment variable as an empty string, but it otherwise exists, so it is not null.
Example:
EMPTY_VAR=
@jaxwilko I've added some additional test cases of valid environment variables. If they're too hard, just revert :P
@bennothommo I thought I would have found time for this earlier, but at least it's done now. I've refactored the lexer to do 2 things differently:
file()
returns.LGTM!
This PR is a bit overkill, but resolves the issue reported in https://github.com/wintercms/laravel-config-writer/issues/1.
The problem was previously each line was parsed as a single entity, i.e. a line could be either a
comment
or aenv
entry, but never two things.The new approach provided by this PR is to use a proper
Lexer
to convert the source into tokens. By doing this, multiple tokens can exist on the same line.This ensures that the following:
Can be interpreted and updated, preserving the original whitespace and comments.
I've added some additional tests to confirm the newly supported functionality