Skip to content

Commit

Permalink
feat: expose doc comment contents
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis authored Apr 5, 2024
1 parent b0cd98e commit 927a1b5
Show file tree
Hide file tree
Showing 6 changed files with 87,974 additions and 87,794 deletions.
37 changes: 24 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ module.exports = grammar({
$._string_content,
$.raw_string_literal,
$.float_literal,
$._outer_block_doc_comment,
$._inner_block_doc_comment,
'*/',
$._outer_block_doc_comment_marker,
$._inner_block_doc_comment_marker,
$._block_comment_content,
$._line_doc_content,
$._error_sentinel,
],

Expand Down Expand Up @@ -1512,30 +1513,40 @@ module.exports = grammar({
// A tricky edge case where what looks like a doc comment is not
seq(token.immediate(prec(2, /\/\//)), /.*/),
// A regular doc comment
seq(field('doc', alias($._line_doc_comment, $.doc_comment)), /.*/),
seq($._line_doc_comment_marker, field('doc', alias($._line_doc_content, $.doc_comment))),
token.immediate(prec(1, /.*/)),
),
),

_line_doc_comment: $ => choice(
_line_doc_comment_marker: $ => choice(
// An outer line doc comment applies to the element that it is outside of
field('outer', alias($._outer_line_doc_comment, $.outer_doc_comment)),
field('outer', alias($._outer_line_doc_comment_marker, $.outer_doc_comment_marker)),
// An inner line doc comment applies to the element it is inside of
field('inner', alias($._inner_line_doc_comment, $.inner_doc_comment)),
field('inner', alias($._inner_line_doc_comment_marker, $.inner_doc_comment_marker)),
),

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

block_comment: $ => seq(
'/*',
optional(field('doc', alias($._block_doc_comment, $.doc_comment))),
optional(
choice(
// Documentation block comments: /** docs */ or /*! docs */
seq(
$._block_doc_comment_marker,
optional(field('doc', alias($._block_comment_content, $.doc_comment))),
),
// Non-doc block comments
$._block_comment_content,
),
),
'*/',
),

_block_doc_comment: $ => choice(
field('inner', alias($._inner_block_doc_comment, $.inner_doc_comment)),
field('outer', alias($._outer_block_doc_comment, $.outer_doc_comment)),
_block_doc_comment_marker: $ => choice(
field('outer', alias($._outer_block_doc_comment_marker, $.outer_doc_comment_marker)),
field('inner', alias($._inner_block_doc_comment_marker, $.inner_doc_comment_marker)),
),

_path: $ => choice(
Expand Down
100 changes: 65 additions & 35 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 46 additions & 28 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 927a1b5

Please sign in to comment.