add optional leading comment to shell_command

Previously, if a shell command started with a comment line, parsing
would fail because shell_command expected the first line to be a shell
line. This adds an optional comment to the beginning of the
shell_command to handle this correctly.
This commit is contained in:
Camden Cheek 2022-01-23 12:33:36 -07:00
parent 98e201aaf7
commit 28ac8596ba
No known key found for this signature in database
GPG key ID: 595BFFE3A04E48B9
4 changed files with 3710 additions and 3601 deletions

View file

@ -38,3 +38,40 @@ RUN echo hello \
(comment) (comment)
(comment) (comment)
(shell_fragment)))) (shell_fragment))))
==================
Run with immediate line continuation
==================
RUN \
# comment
world
---
(source_file
(run_instruction
(line_continuation)
(shell_command
(comment)
(shell_fragment))))
==================
Run with immediate continuation and comment
==================
RUN \
echo foo \
# comment
echo foo
---
(source_file
(run_instruction
(line_continuation)
(shell_command
(shell_fragment)
(line_continuation)
(comment)
(shell_fragment))))

View file

@ -180,7 +180,9 @@ module.exports = grammar({
seq( seq(
field("name", $._env_key), field("name", $._env_key),
token.immediate("="), token.immediate("="),
optional(field("value", choice($.double_quoted_string, $.unquoted_string))) optional(
field("value", choice($.double_quoted_string, $.unquoted_string))
)
), ),
_spaced_env_pair: ($) => _spaced_env_pair: ($) =>
@ -211,7 +213,8 @@ module.exports = grammar({
) )
), ),
image_name: ($) => seq( image_name: ($) =>
seq(
choice(/[^@:\s\$-]/, $.expansion), choice(/[^@:\s\$-]/, $.expansion),
repeat(choice(/[^@:\s\$]+/, $.expansion)) repeat(choice(/[^@:\s\$]+/, $.expansion))
), ),
@ -249,11 +252,13 @@ module.exports = grammar({
shell_command: ($) => shell_command: ($) =>
seq( seq(
repeat($._comment_line),
$.shell_fragment, $.shell_fragment,
repeat( repeat(
seq( seq(
alias($.required_line_continuation, $.line_continuation), alias($.required_line_continuation, $.line_continuation),
repeat($._comment_line), $.shell_fragment repeat($._comment_line),
$.shell_fragment
) )
) )
), ),

View file

@ -1251,6 +1251,13 @@
"shell_command": { "shell_command": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_comment_line"
}
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "shell_fragment" "name": "shell_fragment"

File diff suppressed because it is too large Load diff