diff --git a/docsite/site/content/reference/expressions.md b/docsite/site/content/reference/expressions.md index ef43d80..271afae 100644 --- a/docsite/site/content/reference/expressions.md +++ b/docsite/site/content/reference/expressions.md @@ -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 ---------- diff --git a/docsite/site/content/reference/grammar.md b/docsite/site/content/reference/grammar.md index 2fdda06..ee3d9e0 100644 --- a/docsite/site/content/reference/grammar.md +++ b/docsite/site/content/reference/grammar.md @@ -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 ; diff --git a/docsite/site/content/reference/statements.md b/docsite/site/content/reference/statements.md index 54d1ebe..d413b91 100644 --- a/docsite/site/content/reference/statements.md +++ b/docsite/site/content/reference/statements.md @@ -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 -----------