DOCS: Reflect the changes in import expressions.

Update the docs to remove the import statement and add the import
expression.

adds: #28
This commit is contained in:
Jeremy Wall 2019-01-13 14:09:18 -06:00
parent 54faeede5e
commit cacb345000
3 changed files with 25 additions and 18 deletions

View File

@ -210,6 +210,22 @@ let copiedtpl = nestedtpl{
};
```
Import Expressions
------------------
Import expressions bring in a ucg file and expose their bound values as a tuple
in the current file. Import expressions are idempotent and cached so you can
use them than once in a file safely. Import expressions start with the `import`
keyword and are followed by a string containing the path of the file to import.
```
// You can import an entire file into the namespace.
let imported = import "some_file.ucg";
// Or you can just import a single value from that file.
let imported_val = (import "some_file.ucg").val;
```
Format Expressions
----------

View File

@ -153,11 +153,17 @@ range_expr: expr, ':', [int, ':'], expr ;
include_expr: include_keyword, bareword, str ;
```
#### Import expression
```
import_expr: import_keyword, str ;
```
#### Non Operator Expression
```
non_operator_expr: literal
| grouped
| import_expr
| macrodef
| module_def
| format_expr
@ -195,13 +201,11 @@ expr: binary_expr | non_operator_expr ;
```
let_statement: let_keyword, bareword, equal, expr ;
import_statement: import_keyword, str, as_keyword, bareword ;
out_statement: out_keyword, bareword, str ;
assert_statement: assert_keyword, pipe, { statement }, pipe ;
simple_statement: expr ;
statement: ( let_statement
| import_statement
| out_statement
| assert_statement
| simple_statement ), semicolon ;

View File

@ -25,27 +25,14 @@ Named Value Statements
### Let statements
There are two statements that can introduce a named value for a given UCG file. Let
statements and import statements. Any collisions in binding names inside a file are
treated as compile errors. Bindings are immutable and once bound they can't be
modified.
There is one statement that can introduce a named value for a given UCG file,
the let statement. Any collisions in binding names inside a file are treated as
compile errors. Bindings are immutable and once bound they can't be modified.
```
let name = "foo";
```
### Import Statement
The import statement imports the contents of another UCG file into the current file
with a name. The imported file's named values are exposed as a tuple in the referencing
file. It starts with the `import` keyword and is followed by a quoted path to the UCG
file, the keyword `as`, and a name for the imported values.
```
import "dbconfigs.ucg" as dbconfigs;
let mysqlconf = dbconfigs.mysql;
```
Output Statements
-----------