Skip to content

Commit

Permalink
feat: structure comment node similar to string
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Aug 14, 2023
1 parent 7268c1c commit b50e46f
Show file tree
Hide file tree
Showing 5 changed files with 2,441 additions and 2,448 deletions.
13 changes: 5 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,13 @@ module.exports = grammar({
comment: ($) =>
choice(
seq(
field('start', alias('--', 'comment_start')),
field('content', alias(/[^\r\n]*/, 'comment_content'))
field('start', '--'),
field('content', alias(/[^\r\n]*/, $.comment_content))
),
seq(
field('start', alias($._block_comment_start, 'comment_start')),
field(
'content',
optional(alias($._block_comment_content, 'comment_content'))
),
field('end', alias($._block_comment_end, 'comment_end'))
field('start', alias($._block_comment_start, '[[')),
field('content', alias($._block_comment_content, $.comment_content)),
field('end', alias($._block_comment_end, ']]'))
)
),
},
Expand Down
37 changes: 12 additions & 25 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2982,13 +2982,8 @@
"type": "FIELD",
"name": "start",
"content": {
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "--"
},
"named": false,
"value": "comment_start"
"type": "STRING",
"value": "--"
}
},
{
Expand All @@ -3000,7 +2995,7 @@
"type": "PATTERN",
"value": "[^\\r\\n]*"
},
"named": false,
"named": true,
"value": "comment_content"
}
}
Expand All @@ -3019,28 +3014,20 @@
"name": "_block_comment_start"
},
"named": false,
"value": "comment_start"
"value": "[["
}
},
{
"type": "FIELD",
"name": "content",
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_block_comment_content"
},
"named": false,
"value": "comment_content"
},
{
"type": "BLANK"
}
]
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_block_comment_content"
},
"named": true,
"value": "comment_content"
}
},
{
Expand All @@ -3053,7 +3040,7 @@
"name": "_block_comment_end"
},
"named": false,
"value": "comment_end"
"value": "]]"
}
}
]
Expand Down
26 changes: 13 additions & 13 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@
"fields": {
"content": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "comment_content",
"named": false
"named": true
}
]
},
Expand All @@ -313,7 +313,7 @@
"required": false,
"types": [
{
"type": "comment_end",
"type": "]]",
"named": false
}
]
Expand All @@ -323,7 +323,11 @@
"required": true,
"types": [
{
"type": "comment_start",
"type": "--",
"named": false
},
{
"type": "[[",
"named": false
}
]
Expand Down Expand Up @@ -1085,6 +1089,10 @@
"type": "-",
"named": false
},
{
"type": "--",
"named": false
},
{
"type": ".",
"named": false
Expand Down Expand Up @@ -1175,15 +1183,7 @@
},
{
"type": "comment_content",
"named": false
},
{
"type": "comment_end",
"named": false
},
{
"type": "comment_start",
"named": false
"named": true
},
{
"type": "do",
Expand Down
Loading

0 comments on commit b50e46f

Please sign in to comment.