From 37f059a2aa2e2083631a217aa705c33930ac691f Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Wed, 5 Jan 2022 00:02:15 -0800 Subject: [PATCH 1/2] Prevent '--platform=xxx' after 'FROM' from being mistaken for the image name --- corpus/from.txt | 15 +++++++++++++++ grammar.js | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/corpus/from.txt b/corpus/from.txt index 3449a46..766d89e 100644 --- a/corpus/from.txt +++ b/corpus/from.txt @@ -71,3 +71,18 @@ FROM sourcegraph/alpine:3.12@sha256:ce099fbcd3cf70b338fc4cb2a4e1fa9ae847de21afdb digest: (image_digest)) as: (image_alias))) +================== +From with param +================== + +FROM --platform=linux/arm64 alpine-${VERSION}-z + +--- + +(source_file + (from_instruction + (param) + (image_spec + (image_name + (expansion + (variable)))))) diff --git a/grammar.js b/grammar.js index 3327496..b17bcae 100644 --- a/grammar.js +++ b/grammar.js @@ -211,7 +211,10 @@ module.exports = grammar({ ) ), - image_name: ($) => repeat1(choice(/[^@:\s\$]+/, $.expansion)), + image_name: ($) => seq( + choice(/[^@:\s\$-][^@:\s\$]*/, $.expansion), + repeat(choice(/[^@:\s\$]+/, $.expansion)) + ), image_tag: ($) => seq( From edb5613f525c748a125d4e079493f5683aa66332 Mon Sep 17 00:00:00 2001 From: Martin Jambon Date: Wed, 5 Jan 2022 15:27:43 -0800 Subject: [PATCH 2/2] Simplify pattern Co-authored-by: Camden Cheek --- grammar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar.js b/grammar.js index b17bcae..71a205f 100644 --- a/grammar.js +++ b/grammar.js @@ -212,7 +212,7 @@ module.exports = grammar({ ), image_name: ($) => seq( - choice(/[^@:\s\$-][^@:\s\$]*/, $.expansion), + choice(/[^@:\s\$-]/, $.expansion), repeat(choice(/[^@:\s\$]+/, $.expansion)) ),