From 47a922db413c2f652410b39b3e26421d166da893 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Wed, 26 Jan 2022 14:41:32 -0800 Subject: [PATCH] Support multiple files in ADD/COPY instructions Fixes https://github.com/camdencheek/tree-sitter-dockerfile/issues/12 --- corpus/add.txt | 13 +++++++++++++ corpus/copy.txt | 13 +++++++++++++ grammar.js | 10 ++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/corpus/add.txt b/corpus/add.txt index 512c436..13aa1b5 100644 --- a/corpus/add.txt +++ b/corpus/add.txt @@ -25,3 +25,16 @@ ADD --chown=a:b /src ./dst (path) (path))) +================== +Multiple files +================== + +ADD src1 src2 dst + +--- + +(source_file + (add_instruction + (path) + (path) + (path))) diff --git a/corpus/copy.txt b/corpus/copy.txt index 83cf305..4882fa5 100644 --- a/corpus/copy.txt +++ b/corpus/copy.txt @@ -25,3 +25,16 @@ COPY --chown=a:b /src ./dst (path) (path))) +================== +Multiple files +================== + +COPY src1 src2 dst + +--- + +(source_file + (copy_instruction + (path) + (path) + (path))) diff --git a/grammar.js b/grammar.js index 2e6a6a7..f1a1a88 100644 --- a/grammar.js +++ b/grammar.js @@ -68,8 +68,9 @@ module.exports = grammar({ seq( alias(/[aA][dD][dD]/, "ADD"), optional($.param), - $.path, - $._non_newline_whitespace, + repeat1( + seq($.path, $._non_newline_whitespace) + ), $.path ), @@ -77,8 +78,9 @@ module.exports = grammar({ seq( alias(/[cC][oO][pP][yY]/, "COPY"), optional($.param), - $.path, - $._non_newline_whitespace, + repeat1( + seq($.path, $._non_newline_whitespace) + ), $.path ),