declare grammar name command
declares a command
.
Declares to BAP that a command with the given name
should be invoked when a user specifies the name
or :name
as the first argument in the command line. The grammar
defines the command line grammar of this command.
where <command1>
... <commandN>
are the names of declared commands, grammar1
... grammarN
are corresponding grammars for each command, and G'
is the global
When the command is selected and command line arguments are parsed successfully, the command
function is applied to the specified command line arguments. The result of evaluation of the command
will become the result of the Bap_main.init ()
expression in the host program.
If the function with the given name
is already registered, then the command is not registered and BAP initialization will terminate abnormally with the configuration error condition.
Examples
Note, the examples below assume the following preamble:
open Core_kernel
open Bap_main.Extension
1) Declare a command with no arguments:
let () =
Command.(declare "hello" args) @@
fun ctxt ->
printf "the `hello' command is called\n";
Ok ()
2) Declaring a command with one positional argument
let input = Command.argument Type.int
let () =
Command.(declare "hello" (args $input)) @@
fun input ctxt ->
printf "called as `hello %d'\n" input
3) Declaring a command with an optional named parameter, and many positional arguments.
let inputs = Command.arguments Type.string
let output = Command.parameter Type.string "output"
let () =
Command.(declare "copy" (args $output $inputs)) @@
fun output inputs ->
printf "copying %s inputs to %s\n"
(String.concat ~sep:" " inputs) output
@parameter doc defines the documentation for the declared command, it could be as simple one-line description or a full featured manual in the markdown syntax. See the corresponding parameter in the Bap_main.init
function for the description of the accepted.
@parameter requires defines the set of features that are required by the implementation of this command. It defaults to the set of all possible features. The context value passed to the command
function will be refined to the context of extensions which are providing the specified features, i.e., between different invocations of BAP it will not change if the configuration parameters of extensions on which the command depends didn't change.