File tree Expand file tree Collapse file tree 2 files changed +76
-4
lines changed Expand file tree Collapse file tree 2 files changed +76
-4
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,6 @@ module.exports = grammar({
110
110
[ $ . array_expression ] ,
111
111
[ $ . visibility_modifier ] ,
112
112
[ $ . visibility_modifier , $ . scoped_identifier , $ . scoped_type_identifier ] ,
113
- [ $ . foreign_mod_item , $ . function_modifiers ] ,
114
113
] ,
115
114
116
115
word : $ => $ . identifier ,
@@ -280,7 +279,8 @@ module.exports = grammar({
280
279
) ,
281
280
282
281
foreign_mod_item : $ => seq (
283
- optional ( 'unsafe' ) ,
282
+ optional ( $ . visibility_modifier ) ,
283
+ optional ( $ . _item_modifiers ) ,
284
284
$ . extern_modifier ,
285
285
choice (
286
286
';' ,
@@ -405,6 +405,7 @@ module.exports = grammar({
405
405
406
406
static_item : $ => seq (
407
407
optional ( $ . visibility_modifier ) ,
408
+ optional ( choice ( 'unsafe' , 'safe' ) ) ,
408
409
'static' ,
409
410
410
411
// Not actual rust syntax, but made popular by the lazy_static crate.
@@ -457,12 +458,21 @@ module.exports = grammar({
457
458
';' ,
458
459
) ,
459
460
460
- function_modifiers : $ => repeat1 ( choice (
461
+ function_modifiers : $ => choice (
462
+ $ . _item_modifiers ,
463
+ $ . extern_modifier ,
464
+ seq (
465
+ $ . _item_modifiers ,
466
+ $ . extern_modifier ,
467
+ ) ,
468
+ ) ,
469
+
470
+ _item_modifiers : _ => repeat1 ( choice (
461
471
'async' ,
462
472
'default' ,
463
473
'const' ,
464
474
'unsafe' ,
465
- $ . extern_modifier ,
475
+ 'safe' ,
466
476
) ) ,
467
477
468
478
where_clause : $ => prec . right ( seq (
Original file line number Diff line number Diff line change @@ -2619,3 +2619,65 @@ pub struct Loaf<T: Sized, const N: usize = 1>([T; N]);
2619
2619
(array_type
2620
2620
(type_identifier)
2621
2621
(identifier)))))
2622
+
2623
+ ================================================================================
2624
+ Unsafe extern blocks
2625
+ ================================================================================
2626
+
2627
+ unsafe extern "C" {
2628
+ pub safe fn sqrt(x: f64) -> f64;
2629
+ pub unsafe fn strlen(p: *const std::ffi::c_char) -> usize;
2630
+ pub fn free(p: *mut core::ffi::c_void);
2631
+ pub safe static IMPORTANT_BYTES: [u8; 256];
2632
+ }
2633
+
2634
+ --------------------------------------------------------------------------------
2635
+
2636
+ (source_file
2637
+ (foreign_mod_item
2638
+ (extern_modifier
2639
+ (string_literal
2640
+ (string_content)))
2641
+ (declaration_list
2642
+ (function_signature_item
2643
+ (visibility_modifier)
2644
+ (function_modifiers)
2645
+ (identifier)
2646
+ (parameters
2647
+ (parameter
2648
+ (identifier)
2649
+ (primitive_type)))
2650
+ (primitive_type))
2651
+ (function_signature_item
2652
+ (visibility_modifier)
2653
+ (function_modifiers)
2654
+ (identifier)
2655
+ (parameters
2656
+ (parameter
2657
+ (identifier)
2658
+ (pointer_type
2659
+ (scoped_type_identifier
2660
+ (scoped_identifier
2661
+ (identifier)
2662
+ (identifier))
2663
+ (type_identifier)))))
2664
+ (primitive_type))
2665
+ (function_signature_item
2666
+ (visibility_modifier)
2667
+ (identifier)
2668
+ (parameters
2669
+ (parameter
2670
+ (identifier)
2671
+ (pointer_type
2672
+ (mutable_specifier)
2673
+ (scoped_type_identifier
2674
+ (scoped_identifier
2675
+ (identifier)
2676
+ (identifier))
2677
+ (type_identifier))))))
2678
+ (static_item
2679
+ (visibility_modifier)
2680
+ (identifier)
2681
+ (array_type
2682
+ (primitive_type)
2683
+ (integer_literal))))))
You can’t perform that action at this time.
0 commit comments