diff --git a/doc/.pandoc/templates/default.html b/doc/.pandoc/templates/default.html index 01c6e379..4e3a60b0 100644 --- a/doc/.pandoc/templates/default.html +++ b/doc/.pandoc/templates/default.html @@ -23,6 +23,7 @@ $endif$ } code { font-size: 1em; + font-family: "Courier New", monospace, serif; } td.lineNumbers { width: 40px; } div#all { diff --git a/doc/.pandoc/templates/index.html b/doc/.pandoc/templates/index.html index ce05901c..2c4dcb24 100644 --- a/doc/.pandoc/templates/index.html +++ b/doc/.pandoc/templates/index.html @@ -23,6 +23,7 @@ $endif$ } code { font-size: 1em; + font-family: "Courier New", monospace, serif; } td.lineNumbers { width: 40px; } div#all { diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 271d15ec..1b71392b 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -70,7 +70,7 @@ if (Haskell_PANDOC_EXECUTABLE) OUTPUT_DIR manual) add_pandoc_markdown (src/compiler.md - CODE "javascript" + CODE cpp OPTIONS --self-contained --table-of-contents OUTPUT_DIR manual) @@ -80,7 +80,7 @@ if (Haskell_PANDOC_EXECUTABLE) OUTPUT_DIR manual) add_pandoc_markdown (src/reference_index.md - CODE "cpp" + CODE cpp OPTIONS --self-contained OUTPUT_NAME index OUTPUT_DIR reference) diff --git a/doc/doxygen/mainpage.md b/doc/doxygen/mainpage.md index 0a94f33f..f5186a1f 100644 --- a/doc/doxygen/mainpage.md +++ b/doc/doxygen/mainpage.md @@ -18,7 +18,7 @@ Basic example ============= In Bond data schemas are defined using idl-like -[syntax](../../manual/bond_cpp.html#idl-syntax): +[syntax](../../manual/compiler.html#idl-syntax): namespace example diff --git a/doc/src/bond_cpp.md b/doc/src/bond_cpp.md index c730849d..f8c58a97 100644 --- a/doc/src/bond_cpp.md +++ b/doc/src/bond_cpp.md @@ -21,7 +21,7 @@ Bond is published on GitHub at [https://github.com/Microsoft/bond/](https://gith Basic example ============= -In Bond data schemas are defined using idl-like [syntax](#idl-syntax): +In Bond data schemas are defined using idl-like [syntax](compiler.html#idl-syntax): namespace example @@ -410,7 +410,7 @@ class][bonded_reference]: The class template has two parameters. The first one, `T`, represents schema (or type) of the data. Usually it is a struct defined via Bond -[IDL](#idl-syntax) but it can also be `void` (see +[IDL](compiler.html#idl-syntax) but it can also be `void` (see [`bonded`][bonded_void_reference]) if we want to work with data for which schema is not known at compile-time. The second parameter, `Reader`, specifies representation of the data. The default, `ProtocolReader` is a variant type @@ -1165,277 +1165,6 @@ See examples: - `examples/cpp/core/simple_json` -IDL syntax -========== - -A Bond schema definition file can contain the following elements: - -- Import statements -- Namespace definition -- Forward declarations -- Definitions - - enum - - forward declaration - - struct - - generics - - struct view -- Custom attributes -- Comments - - -Import statements ------------------- - -In order to use types defined in another schema definition file, the other file -needs to be explicitly imported. Schema file can contain zero or more import -statements and they must appear at the top of the file: - - import "file.bond" - -The file being imported can be specified using a partial path which is resolved -by Bond compiler relative to the directory containing the schema file being -compiled and any import path(s) specified using the --import-dir option(s) -passed to gbc. - -See example: `examples/cpp/core/import`. - -Namespace definition --------------------- - -All schema types are always defined within a namespace. Namespace scope starts -with namespace definition statement and ends at the end of the file. - - namespace some.unique.name - - -Enum definition ---------------- - -Bond enums are very similar to C++ enums, both in semantics and syntax used to -define them: - - enum Protocols - { - TCP, - UDP = 10 - } - -On the wire values of enums types are equivalent to 32-bit signed integers. - - -Forward declaration -------------------- - -In order to define recursive schemas, such as trees, it may be necessary to -declare a struct before it is defined. A forward declaration statement serves -this purpose: - - struct Node; - -Forward declared structs can be used in field declarations as the base type for -nullable\ and bonded\ or the element type of a container. - - struct Node; - - struct Node - { - 0: nullable left; - 1: nullable right; - } - - -Struct definition ------------------ - -Struct definition consists of a struct name, an optional base struct, and zero -or more fields. - - struct Example : Base - { - 0: uint32 fieldName = 10; - } - -Field definition consists of an ordinal, type, name and optional default value. -Field type can be: - -- Basic type: `bool`, `uint8`, `uint16`, `uint32`, `uint64`, `int8`, `int16`, -`int32`, `int64`, `float`, `double`, `string`, `wstring`. - -- Container: `blob`, `list`, `vector`, `set`, `map`, -`nullable`. - -- User-defined type: enum, struct or `bonded` where T is a struct. - -An optional default value can be specified for fields of basic types. For -integers the default can be specified as either a decimal number or a -hexadecimal number prefixed with `0x`. The only explicit default value allowed -for containers is [`nothing`](#default-value-of-nothing). Enum fields must have -an explicit default value which must be one of the enum named constants. - -Names of structs and enums defined in another namespace must be qualified with -the namespace name: - - import "bond/core/bond.bond" - - namespace example - - struct Example - { - 0: bond.GUID id; - 1: bond.BondDataType type = BT_UNAVAILABLE; - } - -Structs can be defined as sealed. Sealed structs can't be inherited from: - - sealed struct Example - { - } - -Generics --------- - -Generic structs are parameterized with one or more type parameters which can be -used within the struct definition in any place where a concrete type could be -used (e.g. base struct, field type, container element type, parameter of a -generic struct). - - struct Example : T1 - { - 0: T1 field; - 1: list list; - 2: Generic generic; - } - -Usage of a type parameter within a generic struct definition may implicitly -constrain what type(s) can be used to instantiate the generic struct: - - struct Example - { - // The default value of 10 implicitly constrains T to numeric types - 0: T x = 10; - } - -Using a type parameter in a [`nullable`](#nullable-types) or as the type of -a field with default value of [`nothing`](#default-value-of-nothing) constrains -the type parameter to be non-scalar type. If this is undesired then explicit -constraint to value type can be specified in the generic schema definition: - - struct Example - { - 0: nullable x; - 1: T y = nothing; - } - -When instantiating a generic struct all type parameters must be concrete types. -Bond IDL doesn't support the equivalent of C++ template template parameters. - -See examples: - -- `examples/cpp/core/generics` -- `examples/cpp/core/generic_tree` - - -Type aliases ------------- - -The syntax to define type aliases is very similar to C++: - - using time = int64; - using array = vector; - -An alias can be used in any context where the aliased type could be used, -including a definition of another alias: - - using times = array