summaryrefslogtreecommitdiff
path: root/tools/Scanner.lean
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2026-04-03 21:40:46 +0200
committerHannes Schulze <haschu0103@outlook.de>2026-04-03 21:40:46 +0200
commit09be9fb2701f0560aeb714f89fe0d1e750915ae0 (patch)
tree3d05703751e8cd4308cd1a02876ee4baf1cb61f9 /tools/Scanner.lean
parent54d62ad2f3eb72d57683780b55dad2a97b1e2dcb (diff)
parse wayland protocols
Diffstat (limited to 'tools/Scanner.lean')
-rw-r--r--tools/Scanner.lean38
1 files changed, 38 insertions, 0 deletions
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 -- <rootModule> <outPath> <srcPath>"
+ IO.println ""
+ IO.println "Description:"
+ IO.println " Read all (XML) protocols from the <srcPath> directory and"
+ IO.println " generate bindings in the <rootModule> namespace, where the"
+ IO.println " root source path is located at <outPath>."
+ return 1
+
+def main (args : List String) : IO UInt32 :=
+ match args with
+ | [rootModule, outPath, srcPath] => process rootModule outPath srcPath
+ | _ => usage