Skip to content

Doc comments #2 #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions corpus/source_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,86 @@ Line comments
(source_file
(line_comment))

============================================
Doc comments
============================================

/// Doc
/// Comment
// / Now a line comment (note the space separating the third slash)

/// Doc
/// Comment
//// Four slashes makes the line a normal comment
/// Doc comment got interrupted by the line above

//! Inner doc comment line 1
//! Inner doc comment line 2
/// This is different doc comment since the line starts differently
//! Back to inner doc comment

/// Same doc comment
/// But with arbitrary indentation

/// Different doc comments

/// Are separated by newlines

----

(source_file
(doc_comment)
(line_comment)
(doc_comment)
(line_comment)
(doc_comment)
(doc_comment)
(doc_comment)
(doc_comment)
(doc_comment)
(doc_comment)
(doc_comment))

=================================================
Doc comments recursion guard 1 (should not hang)
=================================================

//!

---

(source_file (doc_comment))

=================================================
Doc comments recursion guard 2 (should not hang)
=================================================

///

---

(source_file (doc_comment))

=================================================
Comments recursion guard 1 (should not hang)
=================================================

//

---

(source_file (line_comment))

=================================================
Block comments recursion guard 1 (should not hang)
=================================================

/*

---

(source_file (ERROR))

=====================================
Greek letters in identifiers
=====================================
Expand Down
13 changes: 3 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ const primitive_types = numeric_types.concat(['bool', 'str', 'char'])
module.exports = grammar({
name: 'rust',

extras: $ => [/\s/, $.line_comment, $.block_comment],
extras: $ => [/\s/, $.line_comment, $.block_comment, $.doc_comment],

externals: $ => [
$._string_content,
$.raw_string_literal,
$.float_literal,
$.block_comment,
$.line_comment,
$.doc_comment
],

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

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

comment: $ => choice(
$.line_comment,
$.block_comment
),

line_comment: $ => token(seq(
'//', /.*/
)),

_path: $ => choice(
$.self,
alias(choice(...primitive_types), $.identifier),
Expand Down
41 changes: 12 additions & 29 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8173,35 +8173,6 @@
}
]
},
"comment": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "line_comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
}
]
},
"line_comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "//"
},
{
"type": "PATTERN",
"value": ".*"
}
]
}
},
"_path": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -8382,6 +8353,10 @@
{
"type": "SYMBOL",
"name": "block_comment"
},
{
"type": "SYMBOL",
"name": "doc_comment"
}
],
"conflicts": [
Expand Down Expand Up @@ -8427,6 +8402,14 @@
{
"type": "SYMBOL",
"name": "block_comment"
},
{
"type": "SYMBOL",
"name": "line_comment"
},
{
"type": "SYMBOL",
"name": "doc_comment"
}
],
"inline": [
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4939,6 +4939,10 @@
"type": "default",
"named": false
},
{
"type": "doc_comment",
"named": true
},
{
"type": "dyn",
"named": false
Expand Down
Loading