@@ -68,6 +68,7 @@ module.exports = grammar({
6868 // preprocessor statements
6969 / \s | \\ \r ? \n / ,
7070 $ . comment ,
71+ $ . multiline_preproc_comment ,
7172 '&' ,
7273 ] ,
7374
@@ -241,7 +242,8 @@ module.exports = grammar({
241242 ')' ,
242243 ) ,
243244
244- preproc_comment : $ => choice ( / \/ \* .* \* \/ / , / \/ \/ .* / ) ,
245+ inline_preproc_comment : $ => / \/ \/ .* / ,
246+ multiline_preproc_comment : $ => / \/ \* ( [ ^ * ] | \* + [ ^ * / ] ) * \* + \/ / ,
245247
246248 preproc_binary_expression : $ => {
247249 const table = [
@@ -2438,37 +2440,51 @@ function preprocIf(suffix, content, precedence = 0) {
24382440 ) ;
24392441 }
24402442
2443+ /**
2444+ *
2445+ * @param {GrammarSymbols<string> } $
2446+ *
2447+ * @return {ChoiceRule }
2448+ *
2449+ */
2450+ function preprocComment ( $ ) {
2451+ return choice (
2452+ $ . inline_preproc_comment ,
2453+ $ . multiline_preproc_comment ,
2454+ ) ;
2455+ }
2456+
24412457 return {
24422458 [ 'preproc_if' + suffix ] : $ => prec ( precedence , seq (
24432459 preprocessor ( 'if' ) ,
24442460 field ( 'condition' , $ . _preproc_expression ) ,
2445- optional ( $ . preproc_comment ) ,
2461+ optional ( preprocComment ( $ ) ) ,
24462462 '\n' ,
24472463 content ( $ ) ,
24482464 field ( 'alternative' , optional ( alternativeBlock ( $ ) ) ) ,
24492465 preprocessor ( 'endif' ) ,
2450- optional ( $ . preproc_comment ) ,
2466+ optional ( preprocComment ( $ ) ) ,
24512467 ) ) ,
24522468
24532469 [ 'preproc_ifdef' + suffix ] : $ => prec ( precedence , seq (
24542470 choice ( preprocessor ( 'ifdef' ) , preprocessor ( 'ifndef' ) ) ,
24552471 field ( 'name' , $ . identifier ) ,
2456- optional ( $ . preproc_comment ) ,
2472+ optional ( preprocComment ( $ ) ) ,
24572473 content ( $ ) ,
24582474 field ( 'alternative' , optional ( alternativeBlock ( $ ) ) ) ,
24592475 preprocessor ( 'endif' ) ,
2460- optional ( $ . preproc_comment ) ,
2476+ optional ( preprocComment ( $ ) ) ,
24612477 ) ) ,
24622478
24632479 [ 'preproc_else' + suffix ] : $ => prec ( precedence , seq (
24642480 preprocessor ( 'else' ) ,
2465- optional ( $ . preproc_comment ) ,
2481+ optional ( preprocComment ( $ ) ) ,
24662482 content ( $ ) ,
24672483 ) ) ,
24682484
24692485 [ 'preproc_elif' + suffix ] : $ => prec ( precedence , seq (
24702486 preprocessor ( 'elif' ) ,
2471- optional ( $ . preproc_comment ) ,
2487+ optional ( preprocComment ( $ ) ) ,
24722488 field ( 'condition' , $ . _preproc_expression ) ,
24732489 '\n' ,
24742490 content ( $ ) ,
@@ -2478,7 +2494,7 @@ function preprocIf(suffix, content, precedence = 0) {
24782494 [ 'preproc_elifdef' + suffix ] : $ => prec ( precedence , seq (
24792495 choice ( preprocessor ( 'elifdef' ) , preprocessor ( 'elifndef' ) ) ,
24802496 field ( 'name' , $ . identifier ) ,
2481- optional ( $ . preproc_comment ) ,
2497+ optional ( preprocComment ( $ ) ) ,
24822498 content ( $ ) ,
24832499 field ( 'alternative' , optional ( alternativeBlock ( $ ) ) ) ,
24842500 ) ) ,
0 commit comments