@@ -74,7 +74,10 @@ module.exports = grammar({
74
74
$ . _string_content ,
75
75
$ . raw_string_literal ,
76
76
$ . float_literal ,
77
- $ . block_comment ,
77
+ $ . _outer_block_doc_comment ,
78
+ $ . _inner_block_doc_comment ,
79
+ '*/' ,
80
+ $ . _error_sentinel ,
78
81
] ,
79
82
80
83
supertypes : $ => [
@@ -1497,9 +1500,42 @@ module.exports = grammar({
1497
1500
$ . block_comment ,
1498
1501
) ,
1499
1502
1500
- line_comment : _ => token ( seq (
1501
- '//' , / .* / ,
1502
- ) ) ,
1503
+ line_comment : $ => seq (
1504
+ // All line comments start with two //
1505
+ '//' ,
1506
+ // Then are followed by:
1507
+ // - 2 or more slashes making it a regular comment
1508
+ // - 1 slash or 1 or more bang operators making it a doc comment
1509
+ // - or just content for the comment
1510
+ choice (
1511
+ // A tricky edge case where what looks like a doc comment is not
1512
+ seq ( token . immediate ( prec ( 2 , / \/ \/ / ) ) , / .* / ) ,
1513
+ // A regular doc comment
1514
+ seq ( field ( 'doc' , alias ( $ . _line_doc_comment , $ . doc_comment ) ) , / .* / ) ,
1515
+ token . immediate ( prec ( 1 , / .* / ) ) ,
1516
+ ) ,
1517
+ ) ,
1518
+
1519
+ _line_doc_comment : $ => choice (
1520
+ // An outer line doc comment applies to the element that it is outside of
1521
+ field ( 'outer' , alias ( $ . _outer_line_doc_comment , $ . outer_doc_comment ) ) ,
1522
+ // An inner line doc comment applies to the element it is inside of
1523
+ field ( 'inner' , alias ( $ . _inner_line_doc_comment , $ . inner_doc_comment ) ) ,
1524
+ ) ,
1525
+
1526
+ _inner_line_doc_comment : _ => token . immediate ( prec ( 2 , '!' ) ) ,
1527
+ _outer_line_doc_comment : _ => token . immediate ( prec ( 2 , / \/ [ ^ \/ ] / ) ) ,
1528
+
1529
+ block_comment : $ => seq (
1530
+ '/*' ,
1531
+ optional ( field ( 'doc' , alias ( $ . _block_doc_comment , $ . doc_comment ) ) ) ,
1532
+ '*/' ,
1533
+ ) ,
1534
+
1535
+ _block_doc_comment : $ => choice (
1536
+ field ( 'inner' , alias ( $ . _inner_block_doc_comment , $ . inner_doc_comment ) ) ,
1537
+ field ( 'outer' , alias ( $ . _outer_block_doc_comment , $ . outer_doc_comment ) ) ,
1538
+ ) ,
1503
1539
1504
1540
_path : $ => choice (
1505
1541
$ . self ,
0 commit comments