From 1f5491a5af7bd0f1ec4046994d6344886465cba5 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Sun, 5 Apr 2026 16:15:03 +0200 Subject: initial codegen --- tools/Scanner/Protocol.lean | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tools/Scanner/Protocol.lean') diff --git a/tools/Scanner/Protocol.lean b/tools/Scanner/Protocol.lean index 77908d9..6f74126 100644 --- a/tools/Scanner/Protocol.lean +++ b/tools/Scanner/Protocol.lean @@ -15,6 +15,32 @@ def Description.ofSummary (s : String) : Description := def Identifier := String deriving Repr, BEq, Ord, Inhabited +def Identifier.quoted (ident : Identifier) : String := + let s : String := ident + s!"\"{s}\"" + +private def Identifier.pascalCase' (parts : List String.Slice) : String := + parts + |>.map (String.capitalize ∘ String.Slice.toString) + |> String.join + +private def sanitize (s : String) : String := + let isInvalid := + ((0 : String.Pos.Raw).get s).isDigit || s == "class" + if isInvalid then "_" ++ s else s + +def Identifier.pascalCase (ident : Identifier) : String := + ident + |>.split "_" + |>.toList + |> pascalCase' + |> sanitize + +def Identifier.camelCase (ident : Identifier) : String := + match (ident.split "_").toList with + | [] => "" + | x::xs => sanitize (x.toString ++ pascalCase' xs) + namespace Raw structure EnumEntryDesc where @@ -145,6 +171,7 @@ structure MessageDesc where since : Nat deprecatedSince : Option Nat arguments : Array ArgumentDesc + rawArguments : Array Raw.ArgumentDesc deriving Repr, BEq, Inhabited inductive ReturnType where -- cgit v1.3.1