Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file alba_console.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314openFmlibopenCommonmoduleParser=Parser_langmoduleRepl_parser=Parser.Make(Parser.Command)modulePretty_make(Io:Io.SIG)=structmoduleLocated=Character_parser.LocatedmoduleExpression=Ast.ExpressionmoduleOut=Fmlib.Io.Output(Io)modulePP=Pretty_printer.Pretty(Out)includePPletput_left(width:int)(s:string):t=letlen=String.lengthsiniflen<widththenchain[strings;fill(width-len)' ']elsestringsletprint(fd:Io.File.Out.fd)(width:int)(pp:t):unitIo.t=Out.runfd(PP.run0widthwidthpp)end(* Pretty_make *)moduleLocated=Character_parser.LocatedmoduleMake(Io:Io.SIG)=structmodulePretty=Pretty_make(Io)typecommand_line={command:stringoption;workspace:string;package_paths:stringlist;verbosity:int;force:bool;arguments:stringlist(* reversed *)}moduleCLP=Argument_parser.Make(structtypet=command_lineend)letfind_in_array(p:'a->bool)(arr:'aarray):int=Interval.find(funi->parr.(i))0(Array.lengtharr)letfind_elem_in_array(a:'a)(arr:'aarray):int=find_in_array(fune->e=a)arrlethas_file(name:string)(arr:stringarray):bool=find_elem_in_arraynamearr<Array.lengtharrletrecfind_workspace(path:string):(string*stringarray)optionIo.t=(* Find a directory with a file named "alba-workspace.yml" in the
directory [path] and all its parent directories.
Return the path to the directory, the directory entries and the
position of the file "alba-workspace.yml" in the entries. *)letopenIoinDirectory.readpath>>=function|None->returnNone|Somearr->letlen=Array.lengtharrinletpos=find_elem_in_array"alba-workspace.yml"arrinifpos=lenthen(* not the root of the workspace *)matchPath.splitpathwith|None->returnNone|Some(dir,_)->find_workspacedirelsereturn@@Some(path,arr)letfind_packages(ws_path:string)(entries:stringarray):stringlistIo.t=(* Find the packages in the workspace [ws_path].
Return a list of paths
*)letopenIoinletrecfindpathentrieslst=letlen=Array.lengthentriesinletrecfind_in_entriesilst=ifi=lenthenreturnlstelseletpath1=Path.joinpathentries.(i)inDirectory.readpath1>>=function|None->find_in_entries(i+1)lst|Someentries1->findpath1entries1lst>>=funlst->find_in_entries(i+1)lstinifhas_file"alba-package.yml"entriesthenreturn@@path::lstelsefind_in_entries0lstinfindws_pathentries[]letexplore_workspace(cmd:command_line):(string*stringlist)optionIo.t=(* Find the root of the workspace and a list of package directories in
the workspace. *)letopenIoinStdout.line"explore workspace ...">>=fun_->Path.absolutecmd.workspace>>=funpath->find_workspace(Path.normalizepath)>>=function|None->returnNone|Some(path,entries)->find_packagespathentries>>=funpkgs->return@@Some(path,pkgs)letcompile(cmd:command_line):unitIo.t=Io.(Stdout.line"compile ...">>=fun_->explore_workspacecmd>>=function|None->Stdout.line"no workspace found"|Some(ws_path,_)->Stdout.line("workspace <"^ws_path^">"))letstatus(_:command_line):unitIo.t=Io.Stdout.line"status ..."letevaluate(_:command_line):unitIo.t=letmoduleRepl=Repl.Make(Io)inRepl.run_eval()letcompile_module_:unitIo.t=letmoduleCompile=Module.Make(Io)inCompile.run()letrepl_:unitIo.t=letmoduleRepl=Repl.Make(Io)inRepl.run_cli()letcommands:(string*(command_line->unitIo.t)*string)list=["compile",compile,"Compile the modules provided on the command line and all its \
dependencies if compilation is required. If no modules are provided \
all modules of the package which require compilation are compiled.";"status",status,"Display all modules which require compilation or recompilation.";"repl",repl,"Start an interactive programming session.";"evaluate",evaluate,"Read an expression from standard input and evaluate it.";"module",compile_module,"Compile a module from standard input. The module might have commands \
like ':evaluate <expression>' or ':typecheck <expression>' in it."]letcommand_options:(CLP.key*CLP.spec*CLP.doc)list=letopenCLPin[("-verbosity",Int(funia->{awithverbosity=i}),"Verbosity level (default 1)");("-w",String(funsa->{awithworkspace=s}),"Path into an Alba workspace (default: current working directory)");("-I",String(funsa->{awithpackage_paths=s::a.package_paths}),"Add argument to search path for used packages");("-force",Unit(funa->{awithforce=true}),"Force compilation, even if it is not necessary")]letparse(args:stringarray):(command_line,CLP.error)result=letopenCLPinparseargs{command=None;workspace="";package_paths=[];verbosity=1;force=false;arguments=[]}command_options(funsa->matcha.commandwith|None->{awithcommand=Somes}|Some_->{awitharguments=s::a.arguments})letprint_options:Pretty.t=letopenPrettyinchain(List.map(fun(key,spec,doc)->chain[cut;put_left20(key^CLP.argument_typespec);nest20@@fill_paragraphdoc])command_options)letprint_commands:Pretty.t=letopenPrettyinchain(List.map(fun(cmd,_,doc)->chain[cut;put_left10cmd;nest10@@fill_paragraphdoc])commands)letprint_usage:Pretty.t=letopenPrettyinchain[string"Usage: alba command options arguments";cut;cut;nest_list4[string"Commands:";print_commands];cut;cut;nest_list4[string"Options:";print_options];cut]letprint_error(s:string):unitIo.t=letopenPrettyinprintIo.File.stderr80(string"Error: "<+>strings<+>cut<+>cut<+>print_usage)letrun():unit=letopenIoinProcess.execute(Process.command_line>>=funargs->matchparseargswith|Okcl->beginmatchcl.commandwith|None->print_error"no commands given"|Somecmd->matchList.find(fun(c,_,_)->c=cmd)commandswith|None->print_error("Unknown command '"^cmd^"'")|Some(_,f,_)->fclend|Errore->print_error(CLP.string_of_errore)>>=fun_->Process.exit1)end