import Scanner.Protocol import Scanner.Parser import Scanner.Processor open WaylandScanner def parseRawProtocol (path : System.FilePath) : IO Raw.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 rawProtocols ← (← srcPath.readDir) |>.map IO.FS.DirEntry.path |>.mapM parseRawProtocol let clientProtocols ← processProtocols rawProtocols |> IO.ofExcept let rootModuleComponents := rootModule.split "." |>.map String.Slice.toString |>.toArray let rootModulePath := rootModuleComponents.foldl (· / ·) outPath IO.println (reprStr clientProtocols) 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