mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DOCS: Modify the docs to reflect macros as closures.
This commit is contained in:
parent
685ee7407e
commit
44d6247b46
@ -2,10 +2,12 @@
|
|||||||
title = "Introduction to UCG"
|
title = "Introduction to UCG"
|
||||||
in_seach_index = true
|
in_seach_index = true
|
||||||
+++
|
+++
|
||||||
[UCG](https://crates.io/crates/ucg) is a universal grammar for configuration. It's goal is not to define a configuration format
|
|
||||||
like JSON, YAML, or TOML. It is not intended to replace the other configuration formats. Instead
|
[UCG](https://crates.io/crates/ucg) is a universal grammar for configuration.
|
||||||
it is intended to provide a common grammar for generating those formats. Currently UCG is able to
|
It's goal is not to define a configuration format like JSON, YAML, or TOML. It
|
||||||
generate conversions for the following formats.
|
is not intended to replace the other configuration formats. Instead it is
|
||||||
|
intended to provide a common grammar for generating those formats. Currently
|
||||||
|
UCG is able to generate conversions for the following formats.
|
||||||
|
|
||||||
* Environment Variables
|
* Environment Variables
|
||||||
* Command Line Flags
|
* Command Line Flags
|
||||||
|
@ -9,7 +9,7 @@ An Overview
|
|||||||
-----------
|
-----------
|
||||||
|
|
||||||
UCG is a language specialized for generating configurations. It does not have classes,
|
UCG is a language specialized for generating configurations. It does not have classes,
|
||||||
inheritance, closures, or a full type system. All values are immutable once bound to
|
inheritance, or a full type system. All values are immutable once bound to
|
||||||
a name. A valid UCG file is composed of a series of statements. Statements can be
|
a name. A valid UCG file is composed of a series of statements. Statements can be
|
||||||
an expression, introduce named bindings, or create different outputs. All statements
|
an expression, introduce named bindings, or create different outputs. All statements
|
||||||
must be terminiated by a semicolon.
|
must be terminiated by a semicolon.
|
||||||
|
@ -407,25 +407,27 @@ Macros
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
Macros look like functions but they are resolved at compile time and
|
Macros look like functions but they are resolved at compile time and
|
||||||
configurations don't execute so they never appear in output. Macros do not
|
configurations don't execute so they never appear in output. Macros close over
|
||||||
close over their environment so they can only reference values defined in their
|
their environment in the file they are declared in. They are useful for
|
||||||
arguments. They can't refer to bindings or other macros defined elsewhere. They
|
constructing tuples of a certain shape or otherwise promoting data reuse. You
|
||||||
are useful for constructing tuples of a certain shape or otherwise promoting
|
define a macro with the `macro` keyword followed by the arguments in
|
||||||
data reuse. You define a macro with the `macro` keyword followed by the
|
parentheses, a `=>`, and then a tuple literal.
|
||||||
arguments in parentheses, a `=>`, and then a tuple literal.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
let mymacro = macro (arg1, arg2) => {
|
let mymacro = macro (arg1, arg2) => {
|
||||||
host = arg1,
|
host = arg1,
|
||||||
port = arg2,
|
port = arg2,
|
||||||
connstr = "couchdb://@:@" % (arg1, arg2),
|
connstr = "couchdb://@:@" % (arg1, arg2),
|
||||||
}
|
};
|
||||||
|
|
||||||
let my_dbconf = mymacro("couchdb.example.org", "9090");
|
let my_dbconf = mymacro("couchdb.example.org", "9090");
|
||||||
|
|
||||||
let my_dbhost = dbconf.host;
|
let my_dbhost = dbconf.host;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that while macros can close over their environment they can not reference
|
||||||
|
other fields in the macro body itself.
|
||||||
|
|
||||||
Modules
|
Modules
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user