Skip to content

Commit 67d304c

Browse files
authored
Merge pull request #99 from resolritter/doc_comments
Designate doc comments
2 parents 5993f53 + 5c30f3d commit 67d304c

File tree

6 files changed

+48405
-49324
lines changed

6 files changed

+48405
-49324
lines changed

corpus/source_files.txt

+30
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ Line comments
5555
(source_file
5656
(line_comment))
5757

58+
============================================
59+
Doc comments
60+
============================================
61+
62+
/// Doc
63+
/// Comment
64+
// / Now a line comment (note the space separating the third slash)
65+
66+
/// Doc
67+
/// Comment
68+
//// Four slashes makes the line a normal comment
69+
/// Doc comment got interrupted by the line above
70+
71+
//! Inner doc comment line 1
72+
//! Inner doc comment line 2
73+
/// This is different doc comment since the line starts differently
74+
//! Back to inner doc comment
75+
76+
----
77+
78+
(source_file
79+
(doc_comment)
80+
(line_comment)
81+
(doc_comment)
82+
(line_comment)
83+
(doc_comment)
84+
(doc_comment)
85+
(doc_comment)
86+
(doc_comment))
87+
5888
=====================================
5989
Greek letters in identifiers
6090
=====================================

grammar.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ const primitive_types = numeric_types.concat(['bool', 'str', 'char'])
3838
module.exports = grammar({
3939
name: 'rust',
4040

41-
extras: $ => [/\s/, $.line_comment, $.block_comment],
41+
extras: $ => [/\s/, $.line_comment, $.block_comment, $.doc_comment],
4242

4343
externals: $ => [
4444
$._string_content,
4545
$.raw_string_literal,
4646
$.float_literal,
4747
$.block_comment,
48+
$.line_comment,
49+
$.doc_comment
4850
],
4951

5052
supertypes: $ => [
@@ -1426,15 +1428,6 @@ module.exports = grammar({
14261428

14271429
boolean_literal: $ => choice('true', 'false'),
14281430

1429-
comment: $ => choice(
1430-
$.line_comment,
1431-
$.block_comment
1432-
),
1433-
1434-
line_comment: $ => token(seq(
1435-
'//', /.*/
1436-
)),
1437-
14381431
_path: $ => choice(
14391432
$.self,
14401433
alias(choice(...primitive_types), $.identifier),

src/grammar.json

+12-29
Original file line numberDiff line numberDiff line change
@@ -8173,35 +8173,6 @@
81738173
}
81748174
]
81758175
},
8176-
"comment": {
8177-
"type": "CHOICE",
8178-
"members": [
8179-
{
8180-
"type": "SYMBOL",
8181-
"name": "line_comment"
8182-
},
8183-
{
8184-
"type": "SYMBOL",
8185-
"name": "block_comment"
8186-
}
8187-
]
8188-
},
8189-
"line_comment": {
8190-
"type": "TOKEN",
8191-
"content": {
8192-
"type": "SEQ",
8193-
"members": [
8194-
{
8195-
"type": "STRING",
8196-
"value": "//"
8197-
},
8198-
{
8199-
"type": "PATTERN",
8200-
"value": ".*"
8201-
}
8202-
]
8203-
}
8204-
},
82058176
"_path": {
82068177
"type": "CHOICE",
82078178
"members": [
@@ -8382,6 +8353,10 @@
83828353
{
83838354
"type": "SYMBOL",
83848355
"name": "block_comment"
8356+
},
8357+
{
8358+
"type": "SYMBOL",
8359+
"name": "doc_comment"
83858360
}
83868361
],
83878362
"conflicts": [
@@ -8427,6 +8402,14 @@
84278402
{
84288403
"type": "SYMBOL",
84298404
"name": "block_comment"
8405+
},
8406+
{
8407+
"type": "SYMBOL",
8408+
"name": "line_comment"
8409+
},
8410+
{
8411+
"type": "SYMBOL",
8412+
"name": "doc_comment"
84308413
}
84318414
],
84328415
"inline": [

src/node-types.json

+4
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,10 @@
49394939
"type": "default",
49404940
"named": false
49414941
},
4942+
{
4943+
"type": "doc_comment",
4944+
"named": true
4945+
},
49424946
{
49434947
"type": "dyn",
49444948
"named": false

0 commit comments

Comments
 (0)