use extra to allow comments anywhere

This commit is contained in:
Camden Cheek 2024-04-19 15:28:09 -06:00
parent b4a90e2b98
commit 439c3e7b8a
No known key found for this signature in database
GPG key ID: 595BFFE3A04E48B9
6 changed files with 5999 additions and 5852 deletions

View file

@ -1,7 +1,7 @@
module.exports = grammar({
name: "dockerfile",
extras: ($) => [/\s+/, $.line_continuation],
extras: ($) => [/\s+/, $.line_continuation, $.comment],
externals: ($) => [
$.heredoc_marker,
$.heredoc_line,
@ -11,7 +11,7 @@ module.exports = grammar({
],
rules: {
source_file: ($) => repeat(seq(choice($._instruction, $.comment), "\n")),
source_file: ($) => repeat(seq($._instruction, "\n")),
_instruction: ($) =>
choice(
@ -373,12 +373,10 @@ module.exports = grammar({
shell_command: ($) =>
seq(
repeat($._comment_line),
$.shell_fragment,
repeat(
seq(
alias($.required_line_continuation, $.line_continuation),
repeat($._comment_line),
$.shell_fragment
)
)
@ -408,10 +406,6 @@ module.exports = grammar({
line_continuation: () => /\\[ \t]*\n/,
required_line_continuation: () => "\\\n",
_comment_line: ($) => seq(alias($._anon_comment, $.comment), "\n"),
_anon_comment: () => seq("#", /.*/),
json_string_array: ($) =>
seq(
"[",

58
src/grammar.json generated
View file

@ -5,20 +5,11 @@
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_instruction"
},
{
"type": "SYMBOL",
"name": "comment"
}
]
},
{
"type": "STRING",
"value": "\n"
@ -1591,13 +1582,6 @@
"shell_command": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_comment_line"
}
},
{
"type": "SYMBOL",
"name": "shell_fragment"
@ -1616,13 +1600,6 @@
"named": true,
"value": "line_continuation"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_comment_line"
}
},
{
"type": "SYMBOL",
"name": "shell_fragment"
@ -1677,37 +1654,6 @@
"type": "STRING",
"value": "\\\n"
},
"_comment_line": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_anon_comment"
},
"named": true,
"value": "comment"
},
{
"type": "STRING",
"value": "\n"
}
]
},
"_anon_comment": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "PATTERN",
"value": ".*"
}
]
},
"json_string_array": {
"type": "SEQ",
"members": [
@ -1962,6 +1908,10 @@
{
"type": "SYMBOL",
"name": "line_continuation"
},
{
"type": "SYMBOL",
"name": "comment"
}
],
"conflicts": [],

21
src/node-types.json generated
View file

@ -75,11 +75,6 @@
]
}
},
{
"type": "comment",
"named": true,
"fields": {}
},
{
"type": "copy_instruction",
"named": true,
@ -675,10 +670,6 @@
"multiple": true,
"required": true,
"types": [
{
"type": "comment",
"named": true
},
{
"type": "line_continuation",
"named": true
@ -755,10 +746,6 @@
"type": "cmd_instruction",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "copy_instruction",
"named": true
@ -924,10 +911,6 @@
"type": "\"",
"named": false
},
{
"type": "#",
"named": false
},
{
"type": "$",
"named": false
@ -1068,6 +1051,10 @@
"type": "_heredoc_nl",
"named": false
},
{
"type": "comment",
"named": true
},
{
"type": "escape_sequence",
"named": true

11684
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -52,8 +52,8 @@ RUN \
(source_file
(run_instruction
(line_continuation)
(shell_command
(comment)
(shell_command
(shell_fragment))))
==================

View file

@ -139,3 +139,21 @@ ENV TZ America/Toronto
(env_pair
name: (unquoted_string)
value: (unquoted_string))))
================================================================================
Comment immediately after continuation
================================================================================
ENV \
# Where do you live?
TZ America/Toronto
--------------------------------------------------------------------------------
(source_file
(env_instruction
(line_continuation)
(comment)
(env_pair
name: (unquoted_string)
value: (unquoted_string))))