Skip to content

Commit 60d8ee7

Browse files
committed
Update usage with Expr structs
1 parent 20206e8 commit 60d8ee7

1 file changed

Lines changed: 50 additions & 8 deletions

File tree

USAGE.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,56 @@ See: [lexer.rs](./src/lexer.rs)
4141

4242
## Parser
4343

44-
The parser takes a stream of tokens from the lexer and constructs an AST (Abstract Syntax Tree).
45-
46-
| Expression | Description |
47-
| ------------ | ------------------------------------------------------------------------------------- |
48-
| `Call` | A call to a builtin (referenced by identifier) with N expressions passed as arguments |
49-
| `Identifier` | An identifier referencing a builtin, variable, prompt, or secret |
50-
| `String` | A string literal of text |
51-
| `Bool` | A string literal of text |
44+
The 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.
45+
46+
### Expr
47+
48+
```rust
49+
pub enum Expr {
50+
Bool(Box<ExprBool>),
51+
Identifier(Box<ExprIdentifier>),
52+
Call(Box<ExprCall>),
53+
String(Box<ExprString>),
54+
Error,
55+
}
56+
```
57+
58+
#### ExprCall
59+
60+
A call to a builtin (referenced by identifier) with N expressions passed as arguments.`
61+
62+
```rust
63+
pub struct ExprCall {
64+
pub callee: ExprS,
65+
pub args: Vec<ExprS>,
66+
}
67+
```
68+
69+
#### ExprIdentifier
70+
71+
An identifier referencing a builtin, variable, prompt, or secret.
72+
73+
```rust
74+
pub struct ExprIdentifier(pub String, pub IdentifierKind, pub Option<Type>);
75+
76+
let expr = ExprIdentifier::new("print").into();
77+
```
78+
79+
#### ExprString
80+
81+
A string literal of text.
82+
83+
```rust
84+
pub struct ExprString(pub String);
85+
```
86+
87+
#### ExprBool
88+
89+
A boolean literal: `true` or `false`
90+
91+
```rust
92+
pub struct ExprBool(pub bool);
93+
```
5294

5395
### Usage
5496

0 commit comments

Comments
 (0)