diff options
Diffstat (limited to 'tools/Scanner.lean')
| -rw-r--r-- | tools/Scanner.lean | 38 |
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 |
