mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -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"
|
||||
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
|
||||
it is intended to provide a common grammar for generating those formats. Currently UCG is able to
|
||||
generate conversions for the following formats.
|
||||
|
||||
[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 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
|
||||
* Command Line Flags
|
||||
|
@ -9,7 +9,7 @@ An Overview
|
||||
-----------
|
||||
|
||||
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
|
||||
an expression, introduce named bindings, or create different outputs. All statements
|
||||
must be terminiated by a semicolon.
|
||||
|
@ -407,25 +407,27 @@ Macros
|
||||
-----
|
||||
|
||||
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
|
||||
close over their environment so they can only reference values defined in their
|
||||
arguments. They can't refer to bindings or other macros defined elsewhere. They
|
||||
are useful for constructing tuples of a certain shape or otherwise promoting
|
||||
data reuse. You define a macro with the `macro` keyword followed by the
|
||||
arguments in parentheses, a `=>`, and then a tuple literal.
|
||||
configurations don't execute so they never appear in output. Macros close over
|
||||
their environment in the file they are declared in. They are useful for
|
||||
constructing tuples of a certain shape or otherwise promoting data reuse. You
|
||||
define a macro with the `macro` keyword followed by the arguments in
|
||||
parentheses, a `=>`, and then a tuple literal.
|
||||
|
||||
```
|
||||
let mymacro = macro (arg1, arg2) => {
|
||||
host = arg1,
|
||||
port = arg2,
|
||||
connstr = "couchdb://@:@" % (arg1, arg2),
|
||||
}
|
||||
};
|
||||
|
||||
let my_dbconf = mymacro("couchdb.example.org", "9090");
|
||||
|
||||
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
|
||||
-------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user