Make comments a single node in the grammar
This looks to be a *strong* idiom in tree-sitter parsers.
This commit is contained in:
parent
aa8472e73f
commit
b62fc19da9
10
grammar.js
10
grammar.js
|
@ -11,8 +11,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
extras: ($) => [
|
extras: ($) => [
|
||||||
/\s+/,
|
/\s+/,
|
||||||
$.line_comment,
|
$.comment,
|
||||||
$.block_comment,
|
|
||||||
],
|
],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
@ -23,9 +22,10 @@ module.exports = grammar({
|
||||||
$.module,
|
$.module,
|
||||||
),
|
),
|
||||||
|
|
||||||
line_comment: (_) => seq("//", /[^\n]*/),
|
comment: (_) => choice(
|
||||||
|
seq("//", /[^\n]*/),
|
||||||
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
|
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
|
||||||
|
),
|
||||||
|
|
||||||
// Definitions {{{
|
// Definitions {{{
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
[
|
(comment) @comment
|
||||||
(line_comment)
|
|
||||||
(block_comment)
|
|
||||||
] @comment
|
|
||||||
|
|
||||||
; Operators {{{
|
; Operators {{{
|
||||||
(operator) @operator
|
(operator) @operator
|
||||||
|
|
15
src/grammar.json
generated
15
src/grammar.json
generated
|
@ -21,7 +21,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"line_comment": {
|
"comment": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -34,7 +37,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"block_comment": {
|
{
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -50,6 +53,8 @@
|
||||||
"value": "/"
|
"value": "/"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"assignment": {
|
"assignment": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
@ -956,11 +961,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "line_comment"
|
"name": "comment"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "block_comment"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"conflicts": [],
|
"conflicts": [],
|
||||||
|
|
9
src/node-types.json
generated
9
src/node-types.json
generated
|
@ -168,12 +168,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "block_comment",
|
"type": "boolean_literal",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {}
|
"fields": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "boolean_literal",
|
"type": "comment",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {}
|
"fields": {}
|
||||||
},
|
},
|
||||||
|
@ -259,11 +259,6 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "line_comment",
|
|
||||||
"named": true,
|
|
||||||
"fields": {}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "list_expression",
|
"type": "list_expression",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
1208
src/parser.c
generated
1208
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@ Empty comment
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(line_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Single comment
|
Single comment
|
||||||
|
@ -18,7 +18,7 @@ Single comment
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(line_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Multiple comments
|
Multiple comments
|
||||||
|
@ -30,8 +30,8 @@ Multiple comments
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(line_comment)
|
(comment)
|
||||||
(line_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Empty block comment
|
Empty block comment
|
||||||
|
@ -42,7 +42,7 @@ Empty block comment
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Whitespace block comment
|
Whitespace block comment
|
||||||
|
@ -53,7 +53,7 @@ Whitespace block comment
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Block comment
|
Block comment
|
||||||
|
@ -64,7 +64,7 @@ Block comment
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Block comment with slashes
|
Block comment with slashes
|
||||||
|
@ -75,7 +75,7 @@ Block comment with slashes
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Block comment with asterisks
|
Block comment with asterisks
|
||||||
|
@ -86,7 +86,7 @@ Block comment with asterisks
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Block comment (multiline)
|
Block comment (multiline)
|
||||||
|
@ -103,7 +103,7 @@ Block comment (multiline)
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Block comment is not recursive
|
Block comment is not recursive
|
||||||
|
@ -114,7 +114,7 @@ Block comment is not recursive
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
(block_comment))
|
(comment))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Unterminated comment
|
Unterminated comment
|
||||||
|
|
Loading…
Reference in a new issue