allow one-letter environment variables

This fixes issue #11. Previously, we required environment variable names
to be one ASCII letter followed by one or more characters, but this
makes the following characters optional.
This commit is contained in:
Camden Cheek 2022-01-27 11:20:14 -07:00
parent 4e5f9a0a61
commit d34a0cebd0
No known key found for this signature in database
GPG key ID: 595BFFE3A04E48B9
4 changed files with 19 additions and 5 deletions

View file

@ -26,6 +26,20 @@ ENV TEST_2=value\ 2
name: (unquoted_string)
value: (unquoted_string))))
=========================================================
Single-letter variable
=========================================================
ENV X=42
---
(source_file
(env_instruction
(env_pair
(unquoted_string)
(unquoted_string))))
================================================================================
Multiple
================================================================================

View file

@ -195,7 +195,7 @@ module.exports = grammar({
),
_env_key: ($) =>
alias(/[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]/, $.unquoted_string),
alias(/[a-zA-Z]([a-zA-Z0-9_]*[a-zA-Z0-9])?/, $.unquoted_string),
expose_port: ($) => seq(/\d+/, optional(choice("/tcp", "/udp"))),

View file

@ -941,7 +941,7 @@
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]"
"value": "[a-zA-Z]([a-zA-Z0-9_]*[a-zA-Z0-9])?"
},
"named": true,
"value": "unquoted_string"

View file

@ -1078,7 +1078,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '\r' ||
lookahead == ' ') SKIP(5)
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(52);
('a' <= lookahead && lookahead <= 'z')) ADVANCE(204);
END_STATE();
case 6:
if (lookahead == '\n') ADVANCE(160);
@ -1283,7 +1283,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '\r' ||
lookahead == ' ') SKIP(22)
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(52);
('a' <= lookahead && lookahead <= 'z')) ADVANCE(204);
END_STATE();
case 23:
if (lookahead == '\n') ADVANCE(160);
@ -1488,7 +1488,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '\r' ||
lookahead == ' ') SKIP(45)
if (('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(52);
('a' <= lookahead && lookahead <= 'z')) ADVANCE(204);
END_STATE();
case 46:
if (lookahead == '\\') ADVANCE(1);