| Global Variables and Constants | categories I/O, Modules and System Interface Command line handling |
Serialization |
In XL CLAIRE, additionally to the main @ list redefinition, we have a command line processor that make a module able to define a particular set of option responder and associated command line documentation through 2 handlers. For instance the Reader implement the option -f used to load a file from the command line. The Reader implements :
| [option_usage(opt:{"-f", "-ef"}) : tuple(string, string, string) -> tuple("Load file", "{-f | -ef} <file:path> ...", "Load the CLAIRE file(s) <file>. The given path may contain an extension " /+ "assuming .cl by default. When the <-f> option is used, the file is " /+ "assumed to contain CLAIRE definitions (variables, class, methods) whereas " /+ " <-ef> attempts to read a file made of CLAIRE expression.")] [option_respond(opt:{"-f", "-ef"}, l:list) : void -> if not(l) invalid_option_argument(), if (not(isfile?(l[1])) & not(isfile?(l[1] /+ ".cl"))) error("~A cannot be opened", l[1]), while (l & (isfile?(l[1]) | isfile?(l[1] /+ ".cl"))) let path := l[1] in (l << 1, case opt ({"-f"} load(path), {"-ef"} eload(path)))] |
Additionally to this two handlers, a module can define a single restriction of option_parsed that will be called once the full command line has been parsed. With such an handler, a module can perform a job that depends on multiple independent option responder (that would have initialize global flags). For instance :
| *myopt*:boolean := false [option_respond(opt:{"myopt"}, l:list) : void -> *myopt* := true] [option_parsed() : void -> if *myopt* ... else ...] |
| {-h | -help} +[<m> | <option> | <index>] |
| categories | Command line handling | normal dispatch | [XL] Core interface |
A module can define a single option_parsed restriction that will be called by the command line option parser at startup as soon as the full command line is parsed. It will be used inside a module to perform an operation that rely on multiple options (for which option_respond as already been called):
| option_parsed() : void -> ... |
| categories | Command line handling | normal dispatch | [XL] Core interface |
A module can define multiple option_respond restrictions that will be called by the command line option parser at startup. option_respond will take two arguments:
| option_respond(opt:{"-opt"}, l:list[string]) : void -> ... |
| categories | Command line handling | normal dispatch | [XL] Core interface |
A module can define multiple option_usage restrictions that will be called by the command line option parser when the command line help is invoked. option_usage takes a single argument that is a constant set that contain names of multiple related options. The handler should return of tuple of 3 strings :
| option_usage(opt:{"-opt"}) : tuple(string, string, string) -> tuple("short description", "-opt <f:file>", "long description on how to use option -opt we may use <f> to reference the argument f it can also span multiple line if needed") |