@@ -43,8 +43,18 @@ See: [lexer.rs](./src/lexer.rs)
4343
4444The parser takes a stream of tokens from the lexer and constructs an AST (Abstract Syntax Tree) in the form of a tree of ` Expr ` nodes.
4545
46+ ### Usage
47+
48+ ``` rust
49+ let source = " (eq (type `Hello`) (type `World`))" ;
50+
51+ let ast : Expr = parse (& source )? ;
52+ ```
53+
4654### Expr
4755
56+ All values in the language are parsed in to an expression: ` Expr ` .
57+
4858``` rust
4959pub enum Expr {
5060 Bool (Box <ExprBool >),
@@ -55,9 +65,13 @@ pub enum Expr {
5565}
5666```
5767
68+ #### Error
69+
70+ Expressions that can't be parsed are represented in the AST as an ` Expr::Error ` .
71+
5872#### Span Information
5973
60- ` Expr ` that contain sub expressions e.g. ` ExprCall ` store those expressions as ` (Expr, Range<usize>) ` .
74+ Expressions that contain sub expressions ( e.g. ` ExprCall ` ) store those subexpressions and their location in the source as ` (Expr, Range<usize>) ` .
6175
6276The expression ` (and true false) ` would parse to this.
6377
@@ -75,7 +89,10 @@ Span information `1..4`, `5..9`, `10..15` is stored next to the subexpressions `
7589
7690#### ExprCall
7791
78- A call to a builtin (referenced by identifier) with N expressions passed as arguments.`
92+ A call to a builtin (referenced by identifier) with N expressions passed as arguments.
93+
94+ - `` (contains `foo`, `foobar`) ``
95+ - `` (eq `foo` (trim ` foo `)) ``
7996
8097``` rust
8198pub struct ExprCall {
@@ -88,6 +105,12 @@ pub struct ExprCall {
88105
89106An identifier referencing a builtin, variable, prompt, secret, or client value.
90107
108+ - ` builtin_name `
109+ - ` :var_name `
110+ - ` ?prompt_name `
111+ - ` !secret_name `
112+ - ` @client_value `
113+
91114``` rust
92115pub struct ExprIdentifier (pub String , pub IdentifierKind , pub Option <Type >);
93116
@@ -133,24 +156,21 @@ The type of the identifier is added in two passes:
133156
134157A string literal of text.
135158
159+ - `` `Hello World!` ``
160+
136161``` rust
137162pub struct ExprString (pub String );
138163```
139164
140165#### ExprBool
141166
142- A boolean literal: ` true ` or ` false `
167+ A boolean literal.
143168
144- ``` rust
145- pub struct ExprBool (pub bool );
146- ```
147-
148- ### Usage
169+ - ` true `
170+ - ` false `
149171
150172``` rust
151- let source = " (noop)" ;
152-
153- let ast : Expr = parse (& source )? ;
173+ pub struct ExprBool (pub bool );
154174```
155175
156176See: [ parser.rs] ( ./src/parser.rs ) , [ grammar.lalrpop] ( ./src/grammar.lalrpop ) , [ ast.rs] ( ./src/ast.rs )
0 commit comments