From 5473563e9af0abbc81a3cfd7079c34fbc75dfdb4 Mon Sep 17 00:00:00 2001
From: Boris Kolpackov We can now write a description of the above command line interface
in the CLI language and save it into hello.cli
:
+
include <string>;
class options
@@ -284,7 +284,7 @@ class options
a command prompt (Windows):
+$ cli hello.cli@@ -298,7 +298,7 @@ $ cli hello.cliThe following code fragment is taken from
-hello.hxx
; it should give you an idea about what gets generated:+#include <string> class options @@ -336,7 +336,7 @@ private:At this point we have everything we need to implement our application:
-+#include <iostream> #include "hello.hxx" @@ -407,7 +407,7 @@ main (int argc, char* argv[])driver.cxx
, we are ready to build and run our program. On UNIX this can be done with the following commands: -+$ c++ -o driver driver.cxx hello.cxx $ ./driver world @@ -420,7 +420,7 @@ Hi, Jane!!!We can also test the error handling:
-+$ ./driver -n 3 Jane unknown option '-n' usage: driver [options] <names> @@ -446,7 +446,7 @@ options: information is very basic and does not include any description of the purpose of each option: -+$ ./driver --help usage: driver [options] <names> options: @@ -460,7 +460,7 @@ options: also be used to automatically generate program documentation in various formats, such as HTML and man page. For example: -+include <string>; class options @@ -485,7 +485,7 @@ class optionshello.cli
and recompile our application, the usage information printed by the program will look like this: -+usage: driver [options] <names> options: --help Print usage information and exit. @@ -499,7 +499,7 @@ options: (--generate-html
CLI option) and man page (--generate-man
CLI option) formats. For example: -+$ cli --generate-html hello.cli@@ -546,7 +546,7 @@ $ cli --generate-html hello.cli option class contains one or more option definitions, for example: -+class options { bool --help; @@ -557,7 +557,7 @@ class optionsIf we translate the above CLI fragment to C++, we will get a C++ class with the following interface:
-+class options { public: @@ -640,7 +640,7 @@ public: is part of the generated CLI runtime support code. It has the following interface: -+namespace cli { class unknown_mode @@ -673,7 +673,7 @@ namespace cli of the generated CLI runtime support code and has the following abstract interface: -+namespace cli { class scanner @@ -700,7 +700,7 @@ namespace cli array (it is used internally by all the other constructors) and has the following interface: -+namespace cli { class argv_scanner @@ -724,7 +724,7 @@ namespace cli--generate-file-scanner
CLI compiler option and has the following interface: -+namespace cli { class argv_file_scanner @@ -821,7 +821,7 @@ namespace cliThe exceptions described above are part of the generated CLI runtime support code and have the following interfaces:
-+#include <exception> namespace cli @@ -970,7 +970,7 @@ namespace cli characters in other places with underscores. For example, the following option definition: -+class options { int --compression-level | --comp | -c; @@ -979,7 +979,7 @@ class optionsWill result in the following accessor function:
-+class options { int @@ -993,7 +993,7 @@ class optionsIf the option name conflicts with one of the CLI language keywords, it can be specified as a string literal:
-+class options { bool "int"; @@ -1012,7 +1012,7 @@ class options that the constructor initialization can be used with multiple arguments, for example: -+include <string>; class options @@ -1030,7 +1030,7 @@ class options as identifiers. For more complex expressions use the constructor initialization or wrap the expressions in parenthesis, for example: -+include "constants.hxx"; // Defines default_value. class options @@ -1055,7 +1055,7 @@ class options duplicates whilestd::set
will contain all the unique values. For example: -+include <set>; include <vector>; @@ -1078,7 +1078,7 @@ class options by=
. All the option values are then parsed into key/value pairs and inserted into the map. For example: -+include <map>; include <string>; @@ -1101,7 +1101,7 @@ class options it is enclosed in{}
and consists of one or more documentation strings separated by a comma, for example: -+class options { int --compression = 5 @@ -1151,7 +1151,7 @@ class optionslevel
. Here is another example using thestd::map
type: -+include <map>; include <string>; @@ -1187,7 +1187,7 @@ class options\c{int a[] = {1, 2\}}
. The following example shows how we can use these mechanisms: -+class options { int --compression = 5 @@ -1223,7 +1223,7 @@ class options in the generated C++ header file. For example, the following CLI definition: -+include <string>; include "types.hxx"; // Defines the name_type class. @@ -1236,7 +1236,7 @@ class optionsWill result in the following C++ header file:
-+#include <string> #include "types.hxx" @@ -1263,7 +1263,7 @@ class optionsOption classes can be placed into namespaces which are translated directly to C++ namespaces. For example:
-+namespace compiler { namespace lexer @@ -1295,7 +1295,7 @@ namespace compilerThe above CLI namespace structure would result in the equivalent C++ namespaces structure:
-+namespace compiler { namespace lexer -- cgit v1.1