From 09be9fb2701f0560aeb714f89fe0d1e750915ae0 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Fri, 3 Apr 2026 21:40:46 +0200 Subject: parse wayland protocols --- tools/Scanner.lean | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tools/Scanner.lean (limited to 'tools/Scanner.lean') diff --git a/tools/Scanner.lean b/tools/Scanner.lean new file mode 100644 index 0000000..d6962c7 --- /dev/null +++ b/tools/Scanner.lean @@ -0,0 +1,38 @@ +import Scanner.Protocol +import Scanner.Parser + +open WaylandScanner + +def parseProtocol (path : System.FilePath) : IO ProtocolDesc := do + parse (← IO.FS.readFile path) + |>.mapError (fun ε ↦ s!"{path}: {ε}") + |> IO.ofExcept + +def process (rootModule : String) (outPath : System.FilePath) (srcPath : System.FilePath) : IO UInt32 := do + let protocols ← (← srcPath.readDir) + |>.map IO.FS.DirEntry.path + |>.mapM parseProtocol + let rootModuleComponents := rootModule.split "." + |>.map String.Slice.toString + |>.toArray + let rootModulePath := rootModuleComponents.foldl (· / ·) outPath + IO.println (reprStr protocols) + IO.FS.createDirAll rootModulePath + let indexPath := rootModulePath.addExtension "lean" + IO.FS.writeFile indexPath "" + return 0 + +def usage : IO UInt32 := do + IO.println "Usage:" + IO.println " lake exe WaylandScanner -- " + IO.println "" + IO.println "Description:" + IO.println " Read all (XML) protocols from the directory and" + IO.println " generate bindings in the namespace, where the" + IO.println " root source path is located at ." + return 1 + +def main (args : List String) : IO UInt32 := + match args with + | [rootModule, outPath, srcPath] => process rootModule outPath srcPath + | _ => usage -- cgit v1.3.1