Skip to content

Commit c524e8f

Browse files
the-mikedavisamaanq
authored andcommitted
Expose doc comment contents
1 parent b0cd98e commit c524e8f

File tree

6 files changed

+87974
-87794
lines changed

6 files changed

+87974
-87794
lines changed

grammar.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ module.exports = grammar({
7474
$._string_content,
7575
$.raw_string_literal,
7676
$.float_literal,
77-
$._outer_block_doc_comment,
78-
$._inner_block_doc_comment,
79-
'*/',
77+
$._outer_block_doc_comment_marker,
78+
$._inner_block_doc_comment_marker,
79+
$._block_comment_content,
80+
$._line_doc_content,
8081
$._error_sentinel,
8182
],
8283

@@ -1512,30 +1513,40 @@ module.exports = grammar({
15121513
// A tricky edge case where what looks like a doc comment is not
15131514
seq(token.immediate(prec(2, /\/\//)), /.*/),
15141515
// A regular doc comment
1515-
seq(field('doc', alias($._line_doc_comment, $.doc_comment)), /.*/),
1516+
seq($._line_doc_comment_marker, field('doc', alias($._line_doc_content, $.doc_comment))),
15161517
token.immediate(prec(1, /.*/)),
15171518
),
15181519
),
15191520

1520-
_line_doc_comment: $ => choice(
1521+
_line_doc_comment_marker: $ => choice(
15211522
// An outer line doc comment applies to the element that it is outside of
1522-
field('outer', alias($._outer_line_doc_comment, $.outer_doc_comment)),
1523+
field('outer', alias($._outer_line_doc_comment_marker, $.outer_doc_comment_marker)),
15231524
// An inner line doc comment applies to the element it is inside of
1524-
field('inner', alias($._inner_line_doc_comment, $.inner_doc_comment)),
1525+
field('inner', alias($._inner_line_doc_comment_marker, $.inner_doc_comment_marker)),
15251526
),
15261527

1527-
_inner_line_doc_comment: _ => token.immediate(prec(2, '!')),
1528-
_outer_line_doc_comment: _ => token.immediate(prec(2, /\/[^\/\r\n]?/)),
1528+
_inner_line_doc_comment_marker: _ => token.immediate(prec(2, '!')),
1529+
_outer_line_doc_comment_marker: _ => token.immediate(prec(2, '/')),
15291530

15301531
block_comment: $ => seq(
15311532
'/*',
1532-
optional(field('doc', alias($._block_doc_comment, $.doc_comment))),
1533+
optional(
1534+
choice(
1535+
// Documentation block comments: /** docs */ or /*! docs */
1536+
seq(
1537+
$._block_doc_comment_marker,
1538+
optional(field('doc', alias($._block_comment_content, $.doc_comment))),
1539+
),
1540+
// Non-doc block comments
1541+
$._block_comment_content,
1542+
),
1543+
),
15331544
'*/',
15341545
),
15351546

1536-
_block_doc_comment: $ => choice(
1537-
field('inner', alias($._inner_block_doc_comment, $.inner_doc_comment)),
1538-
field('outer', alias($._outer_block_doc_comment, $.outer_doc_comment)),
1547+
_block_doc_comment_marker: $ => choice(
1548+
field('outer', alias($._outer_block_doc_comment_marker, $.outer_doc_comment_marker)),
1549+
field('inner', alias($._inner_block_doc_comment_marker, $.inner_doc_comment_marker)),
15391550
),
15401551

15411552
_path: $ => choice(

src/grammar.json

+65-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

+46-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)