@@ -5,6 +5,64 @@ use crate::lexer::TokenKind;
55pub ( crate ) fn check ( analyzer : & mut Analyzer < ' _ > ) {
66 check_operator_overload_attempts ( analyzer) ;
77 check_implicit_conversion_attempts ( analyzer) ;
8+ check_own_struct_attempts ( analyzer) ;
9+ check_surface_reference_attempts ( analyzer) ;
10+ }
11+
12+ fn check_own_struct_attempts ( analyzer : & mut Analyzer < ' _ > ) {
13+ for index in 0 ..analyzer. tokens . len ( ) . saturating_sub ( 1 ) {
14+ if analyzer. tokens [ index] . is_ident_text ( "own" )
15+ && analyzer. tokens [ index + 1 ] . is_ident_text ( "struct" )
16+ {
17+ analyzer. diagnostics . push (
18+ Diagnostic :: error (
19+ code:: OWN_STRUCT_ATTEMPT ,
20+ "`own struct` is not part of RSScript v0.4.1." ,
21+ analyzer. tokens [ index] . span . clone ( ) ,
22+ "own struct attempt" ,
23+ )
24+ . with_cause ( "v0.4.1 has only `class`, `struct`, and `resource` type declarations." )
25+ . with_fix (
26+ "choose_type_kind" ,
27+ "Use `struct` for inline values, `class` for managed identity, or `resource` for deterministic cleanup." ,
28+ "manual" ,
29+ ) ,
30+ ) ;
31+ }
32+ }
33+ }
34+
35+ fn check_surface_reference_attempts ( analyzer : & mut Analyzer < ' _ > ) {
36+ for index in 0 ..analyzer. tokens . len ( ) {
37+ if !analyzer. tokens [ index] . symbol ( "&" ) || is_boolean_and ( analyzer, index) {
38+ continue ;
39+ }
40+ analyzer. diagnostics . push (
41+ Diagnostic :: error (
42+ code:: SURFACE_REFERENCE_ATTEMPT ,
43+ "surface reference syntax is not part of RSScript." ,
44+ analyzer. tokens [ index] . span . clone ( ) ,
45+ "surface reference attempt" ,
46+ )
47+ . with_cause ( "RSScript uses explicit data effects instead of `&T` or `&mut T` syntax." )
48+ . with_fix (
49+ "use_data_effect" ,
50+ "Use a parameter effect such as `value: read T` or `value: mut T`." ,
51+ "manual" ,
52+ ) ,
53+ ) ;
54+ }
55+ }
56+
57+ fn is_boolean_and ( analyzer : & Analyzer < ' _ > , index : usize ) -> bool {
58+ analyzer
59+ . tokens
60+ . get ( index. wrapping_sub ( 1 ) )
61+ . is_some_and ( |token| token. symbol ( "&" ) )
62+ || analyzer
63+ . tokens
64+ . get ( index + 1 )
65+ . is_some_and ( |token| token. symbol ( "&" ) )
866}
967
1068fn check_implicit_conversion_attempts ( analyzer : & mut Analyzer < ' _ > ) {
0 commit comments