Add Engine::disable_doc_comments and smarter doc-comments treatment.
This commit is contained in:
@@ -55,6 +55,7 @@ The Rhai Scripting Language
|
||||
2. [Export a Rust Function](plugins/function.md)
|
||||
5. [Rhai Language Reference](language/index.md)
|
||||
1. [Comments](language/comments.md)
|
||||
1. [Doc-Comments](language/doc-comments.md)
|
||||
2. [Values and Types](language/values-and-types.md)
|
||||
1. [Dynamic Values](language/dynamic.md)
|
||||
2. [Serialization/Deserialization with `serde`](rust/serde.md)
|
||||
@@ -79,14 +80,14 @@ The Rhai Scripting Language
|
||||
9. [If Statement](language/if.md)
|
||||
10. [Switch Expression](language/switch.md)
|
||||
11. [While Loop](language/while.md)
|
||||
11. [Do Loop](language/do.md)
|
||||
12. [Loop Statement](language/loop.md)
|
||||
13. [For Loop](language/for.md)
|
||||
12. [Do Loop](language/do.md)
|
||||
13. [Loop Statement](language/loop.md)
|
||||
14. [For Loop](language/for.md)
|
||||
1. [Iterators for Custom Types](language/iterator.md)
|
||||
14. [Return Values](language/return.md)
|
||||
15. [Throw Exception on Error](language/throw.md)
|
||||
16. [Catch Exceptions](language/try-catch.md)
|
||||
17. [Functions](language/functions.md)
|
||||
15. [Return Values](language/return.md)
|
||||
16. [Throw Exception on Error](language/throw.md)
|
||||
17. [Catch Exceptions](language/try-catch.md)
|
||||
18. [Functions](language/functions.md)
|
||||
1. [Call Method as Function](language/method.md)
|
||||
2. [Overloading](language/overload.md)
|
||||
3. [Namespaces](language/fn-namespaces.md)
|
||||
@@ -94,11 +95,11 @@ The Rhai Scripting Language
|
||||
5. [Currying](language/fn-curry.md)
|
||||
6. [Anonymous Functions](language/fn-anon.md)
|
||||
7. [Closures](language/fn-closure.md)
|
||||
18. [Print and Debug](language/print-debug.md)
|
||||
19. [Modules](language/modules/index.md)
|
||||
19. [Print and Debug](language/print-debug.md)
|
||||
20. [Modules](language/modules/index.md)
|
||||
1. [Export Variables, Functions and Sub-Modules](language/modules/export.md)
|
||||
2. [Import Modules](language/modules/import.md)
|
||||
20. [Eval Function](language/eval.md)
|
||||
21. [Eval Function](language/eval.md)
|
||||
6. [Safety and Protection](safety/index.md)
|
||||
1. [Checked Arithmetic](safety/checked.md)
|
||||
2. [Sand-Boxing](safety/sandbox.md)
|
||||
|
@@ -48,7 +48,7 @@ In this case, the first parameter should be `&mut T` of the custom type and the
|
||||
|
||||
> `set$prop(_, _, _)`
|
||||
|
||||
### Script-defined functions
|
||||
### Script-Defined Functions
|
||||
|
||||
Script-defined [function] signatures contain parameter names. Since all parameters, as well as
|
||||
the return value, are [`Dynamic`] the types are simply not shown.
|
||||
@@ -69,7 +69,7 @@ is the same as:
|
||||
|
||||
> `foo(x: Dynamic, y: Dynamic, z: Dynamic) -> Result<Dynamic, Box<EvalAltResult>>`
|
||||
|
||||
### Plugin functions
|
||||
### Plugin Functions
|
||||
|
||||
Functions defined in [plugin modules] are the best. They contain all the metadata
|
||||
describing the functions.
|
||||
|
@@ -5,14 +5,15 @@ Engine Configuration Options
|
||||
|
||||
A number of other configuration options are available from the `Engine` to fine-tune behavior and safeguards.
|
||||
|
||||
| Method | Not available under | Description |
|
||||
| ------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `set_optimization_level` | [`no_optimize`] | sets the amount of script _optimizations_ performed. See [script optimization]. |
|
||||
| `set_max_expr_depths` | [`unchecked`] | sets the maximum nesting levels of an expression/statement. See [maximum statement depth]. |
|
||||
| `set_max_call_levels` | [`unchecked`] | sets the maximum number of function call levels (default 50) to avoid infinite recursion. See [maximum call stack depth]. |
|
||||
| `set_max_operations` | [`unchecked`] | sets the maximum number of _operations_ that a script is allowed to consume. See [maximum number of operations]. |
|
||||
| `set_max_modules` | [`unchecked`] | sets the maximum number of [modules] that a script is allowed to load. See [maximum number of modules]. |
|
||||
| `set_max_string_size` | [`unchecked`] | sets the maximum length (in UTF-8 bytes) for [strings]. See [maximum length of strings]. |
|
||||
| `set_max_array_size` | [`unchecked`], [`no_index`] | sets the maximum size for [arrays]. See [maximum size of arrays]. |
|
||||
| `set_max_map_size` | [`unchecked`], [`no_object`] | sets the maximum number of properties for [object maps]. See [maximum size of object maps]. |
|
||||
| `disable_symbol` | | disables a certain keyword or operator. See [disable keywords and operators]. |
|
||||
| Method | Not available under | Description |
|
||||
| ------------------------ | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| `set_doc_comments` | | enables/disables [doc-comments] |
|
||||
| `set_optimization_level` | [`no_optimize`] | sets the amount of script _optimizations_ performedSee [script optimization] |
|
||||
| `set_max_expr_depths` | [`unchecked`] | sets the maximum nesting levels of an expression/statementSee [maximum statement depth] |
|
||||
| `set_max_call_levels` | [`unchecked`] | sets the maximum number of function call levels (default 50) to avoid infinite recursionSee [maximum call stack depth] |
|
||||
| `set_max_operations` | [`unchecked`] | sets the maximum number of _operations_ that a script is allowed to consumeSee [maximum number of operations] |
|
||||
| `set_max_modules` | [`unchecked`] | sets the maximum number of [modules] that a script is allowed to loadSee [maximum number of modules] |
|
||||
| `set_max_string_size` | [`unchecked`] | sets the maximum length (in UTF-8 bytes) for [strings]See [maximum length of strings] |
|
||||
| `set_max_array_size` | [`unchecked`], [`no_index`] | sets the maximum size for [arrays]See [maximum size of arrays] |
|
||||
| `set_max_map_size` | [`unchecked`], [`no_object`] | sets the maximum number of properties for [object maps]See [maximum size of object maps] |
|
||||
| `disable_symbol` | | disables a certain keyword or operatorSee [disable keywords and operators] |
|
||||
|
@@ -22,43 +22,3 @@ let /* intruder comment */ name = "Bob";
|
||||
/*/*/*/*/**/*/*/*/*/
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
Doc-Comments
|
||||
------------
|
||||
|
||||
Similar to Rust, comments starting with `///` (three slashes) or `/**` (two asterisks) are
|
||||
_doc-comments_.
|
||||
|
||||
Doc-comments can only appear in front of [function] definitions, not any other elements:
|
||||
|
||||
```rust
|
||||
/// This is a valid one-line doc-comment
|
||||
fn foo() {}
|
||||
|
||||
/** This is a
|
||||
** valid block
|
||||
** doc-comment
|
||||
**/
|
||||
fn bar(x) {
|
||||
/// Syntax error - this doc-comment is invalid
|
||||
x + 1
|
||||
}
|
||||
|
||||
/** Syntax error - this doc-comment is invalid */
|
||||
let x = 42;
|
||||
|
||||
/// Syntax error - this doc-comment is also invalid
|
||||
{
|
||||
let x = 42;
|
||||
}
|
||||
```
|
||||
|
||||
Doc-comments are stored within the script's [`AST`] after compilation.
|
||||
|
||||
The `AST::iter_functions` method provides a `ScriptFnMetadata` instance
|
||||
for each function defined within the script, which includes doc-comments.
|
||||
|
||||
Doc-comments never affect the evaluation of a script nor do they incur
|
||||
significant performance overhead. However, third party tools can take advantage
|
||||
of this information to auto-generate documentation for Rhai script functions.
|
||||
|
76
doc/src/language/doc-comments.md
Normal file
76
doc/src/language/doc-comments.md
Normal file
@@ -0,0 +1,76 @@
|
||||
Doc-Comments
|
||||
============
|
||||
|
||||
Similar to Rust, comments starting with `///` (three slashes) or `/**` (two asterisks) are
|
||||
_doc-comments_.
|
||||
|
||||
Doc-comments can only appear in front of [function] definitions, not any other elements:
|
||||
|
||||
```rust
|
||||
/// This is a valid one-line doc-comment
|
||||
fn foo() {}
|
||||
|
||||
/** This is a
|
||||
** valid block
|
||||
** doc-comment
|
||||
**/
|
||||
fn bar(x) {
|
||||
/// Syntax error - this doc-comment is invalid
|
||||
x + 1
|
||||
}
|
||||
|
||||
/** Syntax error - this doc-comment is invalid */
|
||||
let x = 42;
|
||||
|
||||
/// Syntax error - this doc-comment is also invalid
|
||||
{
|
||||
let x = 42;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Special Cases
|
||||
-------------
|
||||
|
||||
Long streams of `//////...` and `/*****...` do _NOT_ form doc-comments.
|
||||
This is consistent with popular comment block styles for C-like languages.
|
||||
|
||||
```rust
|
||||
/////////////////////////////// <- this is not a doc-comment
|
||||
// This is not a doc-comment // <- this is a normal comment
|
||||
/////////////////////////////// <- this is not a doc-comment
|
||||
|
||||
// However, watch out for comment lines starting with '///'
|
||||
|
||||
////////////////////////////////////////// <- this is not a doc-comment
|
||||
/// This, however, IS a doc-comment!!! /// <- this starts with '///'
|
||||
////////////////////////////////////////// <- this is not a doc-comment
|
||||
|
||||
/****************************************
|
||||
* *
|
||||
* This is also not a doc-comment block *
|
||||
* so we don't have to put this in *
|
||||
* front of a function. *
|
||||
* *
|
||||
****************************************/
|
||||
```
|
||||
|
||||
|
||||
|
||||
Using Doc-Comments
|
||||
------------------
|
||||
|
||||
Doc-comments are stored within the script's [`AST`] after compilation.
|
||||
|
||||
The `AST::iter_functions` method provides a `ScriptFnMetadata` instance
|
||||
for each function defined within the script, which includes doc-comments.
|
||||
|
||||
Doc-comments never affect the evaluation of a script nor do they incur
|
||||
significant performance overhead. However, third party tools can take advantage
|
||||
of this information to auto-generate documentation for Rhai script functions.
|
||||
|
||||
|
||||
Disabling Doc-Comments
|
||||
----------------------
|
||||
|
||||
Doc-comments can be disabled via the `Engine::set_doc_comments` method.
|
@@ -91,7 +91,7 @@
|
||||
[timestamp]: {{rootUrl}}/language/timestamps.md
|
||||
[timestamps]: {{rootUrl}}/language/timestamps.md
|
||||
|
||||
[doc-comments]: {{rootUrl}}/language/comments.md#doc-comments
|
||||
[doc-comments]: {{rootUrl}}/language/doc-comments.md
|
||||
[function]: {{rootUrl}}/language/functions.md
|
||||
[functions]: {{rootUrl}}/language/functions.md
|
||||
[function overloading]: {{rootUrl}}/rust/functions.md#function-overloading
|
||||
|
Reference in New Issue
Block a user