Name variable node for expansions

This commit is contained in:
Camden Cheek 2021-05-10 17:35:00 -06:00
parent 0c4af3e20f
commit 74e7f4c3e6
No known key found for this signature in database
GPG key ID: 595BFFE3A04E48B9
6 changed files with 4422 additions and 5644 deletions

View file

@ -60,7 +60,8 @@ LABEL key="value${FOO}"
(label_pair (label_pair
key: (unquoted_string) key: (unquoted_string)
value: (double_quoted_string value: (double_quoted_string
(expansion))))) (expansion
(variable))))))
================== ==================
Stopsignal Stopsignal
@ -72,7 +73,8 @@ STOPSIGNAL $FOO
(source_file (source_file
(stopsignal_instruction (stopsignal_instruction
(expansion))) (expansion
(variable))))
================== ==================
User User
@ -85,8 +87,10 @@ USER foo$FOO:bar$BAR
(source_file (source_file
(user_instruction (user_instruction
user: (unquoted_string user: (unquoted_string
(expansion)) (expansion
(variable)))
group: (unquoted_string group: (unquoted_string
(expansion)))) (expansion
(variable)))))

View file

@ -9,9 +9,11 @@ ADD /$FOO ./${bar}
(source_file (source_file
(add_instruction (add_instruction
(path (path
(expansion)) (expansion
(variable)))
(path (path
(expansion)))) (expansion
(variable)))))
================== ==================
Copy Copy
@ -24,9 +26,11 @@ COPY $FOO ./${bar}
(source_file (source_file
(copy_instruction (copy_instruction
(path (path
(expansion)) (expansion
(variable)))
(path (path
(expansion)))) (expansion
(variable)))))
================== ==================
Special chars Special chars
@ -39,9 +43,11 @@ COPY $FOO ./${bar:-abc}
(source_file (source_file
(copy_instruction (copy_instruction
(path (path
(expansion)) (expansion
(variable)))
(path (path
(expansion)))) (expansion
(variable)))))
================== ==================
Env Env
@ -60,19 +66,23 @@ ENV TEST="foo$BAR" \
(env_pair (env_pair
name: (unquoted_string) name: (unquoted_string)
value: (double_quoted_string value: (double_quoted_string
(expansion))) (expansion
(variable))))
(env_pair (env_pair
name: (unquoted_string) name: (unquoted_string)
value: (unquoted_string value: (unquoted_string
(expansion))) (expansion
(variable))))
(env_pair (env_pair
name: (unquoted_string) name: (unquoted_string)
value: (double_quoted_string value: (double_quoted_string
(expansion))) (expansion
(variable))))
(env_pair (env_pair
name: (unquoted_string) name: (unquoted_string)
value: (unquoted_string value: (unquoted_string
(expansion))))) (expansion
(variable))))))
================== ==================
Expose Expose
@ -86,7 +96,8 @@ EXPOSE $FOO
(source_file (source_file
(expose_instruction (expose_instruction
(expose_port (expose_port
(expansion)))) (expansion
(variable)))))
================== ==================
From From
@ -100,13 +111,17 @@ FROM foo/$FOO:$BAR@sha256:$BAZ AS baz$QUX
(from_instruction (from_instruction
(image_spec (image_spec
name: (image_name name: (image_name
(expansion)) (expansion
(variable)))
tag: (image_tag tag: (image_tag
(expansion)) (expansion
(variable)))
digest: (image_digest digest: (image_digest
(expansion))) (expansion
(variable))))
as: (image_alias as: (image_alias
(expansion)))) (expansion
(variable)))))
================== ==================
Label Label
@ -121,7 +136,8 @@ LABEL key="value$FOO"
(label_pair (label_pair
key: (unquoted_string) key: (unquoted_string)
value: (double_quoted_string value: (double_quoted_string
(expansion))))) (expansion
(variable))))))
================== ==================
Stopsignal Stopsignal
@ -133,7 +149,8 @@ STOPSIGNAL $FOO
(source_file (source_file
(stopsignal_instruction (stopsignal_instruction
(expansion))) (expansion
(variable))))
================== ==================
User User
@ -146,9 +163,11 @@ USER foo$FOO:bar${bar}
(source_file (source_file
(user_instruction (user_instruction
user: (unquoted_string user: (unquoted_string
(expansion)) (expansion
(variable)))
group: (unquoted_string group: (unquoted_string
(expansion)))) (expansion
(variable)))))
================== ==================
Volume Volume
@ -162,9 +181,11 @@ volume /my$FOO /my${bar}
(source_file (source_file
(volume_instruction (volume_instruction
(path (path
(expansion)) (expansion
(variable)))
(path (path
(expansion)))) (expansion
(variable)))))
================== ==================
Workdir Workdir
@ -177,7 +198,8 @@ WORKDIR /tmp/$FOO
(source_file (source_file
(workdir_instruction (workdir_instruction
(path (path
(expansion)))) (expansion
(variable)))))
================== ==================
@ -192,6 +214,8 @@ ONBUILD ADD /$FOO ./${bar}
(onbuild_instruction (onbuild_instruction
(add_instruction (add_instruction
(path (path
(expansion)) (expansion
(variable)))
(path (path
(expansion))))) (expansion
(variable))))))

View file

@ -194,12 +194,14 @@ module.exports = grammar({
expansion: $ => seq( expansion: $ => seq(
'$', '$',
repeat1(choice( choice(
token.immediate(/[a-zA-Z][a-zA-Z0-9_]*/), $.variable,
seq('{', /[^\}]+/, '}'), seq('{', alias(/[^\}]+/, $.variable), '}'),
)) )
), ),
variable: $ => token.immediate(/[a-zA-Z][a-zA-Z0-9_]*/),
env_pair: $ => seq( env_pair: $ => seq(
field("name", alias(/[a-zA-Z][a-zA-Z0-9_]+[a-zA-Z0-9]/, $.unquoted_string)), field("name", alias(/[a-zA-Z][a-zA-Z0-9_]+[a-zA-Z0-9]/, $.unquoted_string)),

View file

@ -801,39 +801,45 @@
"value": "$" "value": "$"
}, },
{ {
"type": "REPEAT1", "type": "CHOICE",
"content": { "members": [
"type": "CHOICE", {
"members": [ "type": "SYMBOL",
{ "name": "variable"
"type": "IMMEDIATE_TOKEN", },
"content": { {
"type": "PATTERN", "type": "SEQ",
"value": "[a-zA-Z][a-zA-Z0-9_]*" "members": [
} {
}, "type": "STRING",
{ "value": "{"
"type": "SEQ", },
"members": [ {
{ "type": "ALIAS",
"type": "STRING", "content": {
"value": "{"
},
{
"type": "PATTERN", "type": "PATTERN",
"value": "[^\\}]+" "value": "[^\\}]+"
}, },
{ "named": true,
"type": "STRING", "value": "variable"
"value": "}" },
} {
] "type": "STRING",
} "value": "}"
] }
} ]
}
]
} }
] ]
}, },
"variable": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[a-zA-Z][a-zA-Z0-9_]*"
}
},
"env_pair": { "env_pair": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

View file

@ -177,7 +177,17 @@
{ {
"type": "expansion", "type": "expansion",
"named": true, "named": true,
"fields": {} "fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "variable",
"named": true
}
]
}
}, },
{ {
"type": "expose_instruction", "type": "expose_instruction",
@ -861,6 +871,10 @@
"type": "escape_sequence", "type": "escape_sequence",
"named": true "named": true
}, },
{
"type": "variable",
"named": true
},
{ {
"type": "{", "type": "{",
"named": false "named": false

File diff suppressed because it is too large Load diff