support multiple parameters to ADD and COPY

This commit adds support for parsing multiple parameters to both `ADD`
and `COPY` commands.

For example, tree-sitter-dockerfile now correctly parses both of these
lines from the dockerfile reference[^1]:

```dockerfile
ADD --chown=myuser:mygroup --chmod=655 files* /somedir/
COPY --chown=myuser:mygroup --chmod=644 files* /somedir/
```

Closes #43

[^1]: https://docs.docker.com/engine/reference/builder/
This commit is contained in:
Eric Crosson 2023-10-09 18:38:49 -05:00
parent 1800d5a067
commit c9351d9009
5 changed files with 4122 additions and 4052 deletions

View file

@ -38,3 +38,18 @@ ADD src1 src2 dst
(path) (path)
(path) (path)
(path))) (path)))
==================
Multiple params
==================
ADD --chown=a:b --chmod=644 src dst
---
(source_file
(add_instruction
(param)
(param)
(path)
(path)))

View file

@ -38,3 +38,18 @@ COPY src1 src2 dst
(path) (path)
(path) (path)
(path))) (path)))
==================
Multiple params
==================
COPY --chown=a:b --chmod=644 src dst
---
(source_file
(copy_instruction
(param)
(param)
(path)
(path)))

View file

@ -73,7 +73,7 @@ module.exports = grammar({
add_instruction: ($) => add_instruction: ($) =>
seq( seq(
alias(/[aA][dD][dD]/, "ADD"), alias(/[aA][dD][dD]/, "ADD"),
optional($.param), repeat($.param),
repeat1( repeat1(
seq($.path, $._non_newline_whitespace) seq($.path, $._non_newline_whitespace)
), ),
@ -83,7 +83,7 @@ module.exports = grammar({
copy_instruction: ($) => copy_instruction: ($) =>
seq( seq(
alias(/[cC][oO][pP][yY]/, "COPY"), alias(/[cC][oO][pP][yY]/, "COPY"),
optional($.param), repeat($.param),
repeat1( repeat1(
seq($.path, $._non_newline_whitespace) seq($.path, $._non_newline_whitespace)
), ),

View file

@ -336,16 +336,11 @@
"value": "ADD" "value": "ADD"
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "param"
"name": "param" }
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "REPEAT1", "type": "REPEAT1",
@ -382,16 +377,11 @@
"value": "COPY" "value": "COPY"
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "param"
"name": "param" }
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "REPEAT1", "type": "REPEAT1",

File diff suppressed because it is too large Load diff