mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DOCS: update the grammar and expression docs.
Adds the new form of format expressions using tuples. Regarding Issue #23
This commit is contained in:
parent
3c1b3ce86a
commit
315fbabc3d
@ -258,8 +258,9 @@ let imported_val = (import "some_file.ucg").val;
|
|||||||
Format Expressions
|
Format Expressions
|
||||||
----------
|
----------
|
||||||
|
|
||||||
UCG has a format expression that has a limited form of string templating. A
|
UCG has a format expression that has a limited form of string templating. Format expressions come in two forms.
|
||||||
format expression starts with a string followed by the `%` operator and a list
|
|
||||||
|
The simplest form starts with a string followed by the `%` operator and a list
|
||||||
of arguments in parentheses separated by commas. Trailing commas are allowed.
|
of arguments in parentheses separated by commas. Trailing commas are allowed.
|
||||||
The format string should have `@` characters in each location where a value
|
The format string should have `@` characters in each location where a value
|
||||||
should be placed. Any primitive value can be used as an argument.
|
should be placed. Any primitive value can be used as an argument.
|
||||||
@ -268,6 +269,22 @@ should be placed. Any primitive value can be used as an argument.
|
|||||||
"https://@:@/" % (host, port)
|
"https://@:@/" % (host, port)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
A slightly more complex form starts with a string followed by the `%` operator and
|
||||||
|
an expression. the template string can then reference the result of the expression
|
||||||
|
in expressions embedded within the format string. The expressions result can be referenced using the special name `item` in the embedded expression. The result
|
||||||
|
of the expression will be rendered as the default string representation in the
|
||||||
|
resulting string.
|
||||||
|
|
||||||
|
```
|
||||||
|
let tpl = {
|
||||||
|
foo = {
|
||||||
|
bar = [0, 1, 2],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
"foo.bar.1 == @{item.foo.bar.1}" % tpl;
|
||||||
|
```
|
||||||
|
|
||||||
Range Expression
|
Range Expression
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
@ -132,7 +132,9 @@ call_expr: bareword, lparen, [arglist], rparen ;
|
|||||||
#### Format Expression
|
#### Format Expression
|
||||||
|
|
||||||
```
|
```
|
||||||
format_expr: str, percent, lparen, [arglist], rparen ;
|
format_arg_list: lparen, [arglist], rparen ;
|
||||||
|
foramt_expr_arg: expression ;
|
||||||
|
format_expr: str, percent, (format_arg_list | format_expr_arg) ;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Functional processing expressions
|
### Functional processing expressions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user