Merge pull request #326 from HigherOrderCO/feature/sc-700/fix-empty-map-parsing

[sc-700] Fix empty map parsing
This commit is contained in:
Nicolas Abril 2024-05-17 18:10:30 +02:00 committed by GitHub
commit 8a137b0d87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 0 deletions

View File

@ -109,6 +109,19 @@ It's possible to assign to a pattern, like a tuple or superposition, which will
(first, second) = (1, 2)
```
### Use
```rust
use x = 2 + 3
return x + x
```
Inline copies of the declared bind, it is equivalent to this code:
```rust
return ((2 + 3) + (2 + 3))
```
### In-Place Operation
```python
@ -538,6 +551,16 @@ A List literal is surrounded by `[` `]`. The elements must be separated by `,`.
It is desugared to constructor calls of the built-in type List, `List/cons(head, ~tail)` and `List/nil` .
### Map Literals
```python
{ 0: 4, `hi`: "bye", 'c': 2 + 3 }
x[0] = 5 # Assigns the key 0 to the value 5
return x[0] # Gets the value of the key 0
```
Bend has a built-in binary tree map data structure where the key is a `u24`, meaning you can use numbers, characters, and symbols as keys.
### List Comprehension
```python
@ -749,6 +772,19 @@ The let term will expects a binding value followed by a `next` term.
Using `;` is optional.
### Use
```rust
use x = (+ 2 3)
(+ x x)
```
Inline copies of the declared bind, it is equivalent to this code:
```rust
(+ (+ 2 3) (+ 2 3))
```
### Switch
```rust

View File

@ -116,6 +116,10 @@ impl<'a> PyParser<'a> {
}
'{' => {
self.advance_one();
self.skip_trivia();
if self.try_consume_exactly("}") {
return Ok(Expr::MapInit { entries: Vec::new() });
}
let head = self.parse_expr(false)?;
self.skip_trivia();
if self.starts_with(":") { self.parse_map_init(head)? } else { self.parse_sup(head)? }
@ -127,6 +131,10 @@ impl<'a> PyParser<'a> {
let val = STRINGS.get(str);
Expr::Str { val }
}
'\'' => {
let chr = self.parse_quoted_char()?;
Expr::Num { val: Num::U24(chr as u32 & 0x00ff_ffff) }
}
'$' => {
self.advance_one();
let nam = self.parse_bend_name()?;