Feat: add mutable pointer type *mut T and *mut opaque

- Grammar: update pointer_type to support optional mut keyword;
  LL(1) verified (56 named rules, no conflicts)
- AST: update Type enum with mutable: bool field for Pointer and
  OpaquePointer variants
- Parser: consume optional mut token in parse_type; update all
  existing pointer tests; add 4 new mut pointer tests (85 pass)
- VSCode extension: add *mut capture-group pattern for syntax
  highlighting; update SYNTAX.md with pointer mutability table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 10:37:21 +01:00
parent 53c66a3d03
commit 7cdcad7df3
5 changed files with 97 additions and 29 deletions

View File

@@ -271,13 +271,20 @@ named_type = IDENT ;
(* --- Pointer types --- *)
(* *)
(* "*" type typed pointer; the pointee type is known. *)
(* "*opaque" untyped/opaque pointer (no pointee type info). *)
(* "*" type immutable typed pointer (read-only through ptr) *)
(* "*mut" type mutable typed pointer (read-write through ptr) *)
(* "*opaque" immutable untyped pointer (like C's const void* *)
(* "*mut opaque" mutable untyped pointer (like C's void* *)
(* *)
(* LL(1) note: after "*", "opaque" is not in FIRST(type), so the *)
(* two alternatives are always distinguishable with one token. *)
(* LL(1) note: after "*", peek at next token: *)
(* "mut" mutable pointer; consume "mut", then parse *)
(* "opaque" | type *)
(* "opaque" immutable opaque pointer *)
(* other immutable typed pointer; parse type directly *)
(* "mut" is a keyword; it is not in FIRST(type) and is distinct *)
(* from "opaque", so all three cases are unambiguous with one token.*)
pointer_type = "*" , ( "opaque" | type ) ;
pointer_type = "*" , [ "mut" ] , ( "opaque" | type ) ;
(* --- Array types --- *)