Skip to content

Commit

Permalink
Merge pull request #676 from HigherOrderCO/675-error-on-eraser-program
Browse files Browse the repository at this point in the history
Allow era term to be surrounded by parens
  • Loading branch information
imaqtkatt authored Aug 16, 2024
2 parents d6a1995 + 1daf6c5 commit 425cdaa
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project does not currently adhere to a particular versioning scheme.
- Expand references to functions generated by the `float_combinators` pass inside the main function. ([#642][gh-642])
- Expand references inside constructors in the main function. ([#643][gh-643])
- Fix readback when hvm net has `a{n}` or `x{n}` vars. ([#659][gh-659])
- Fix imported constructors not being updated to Constructor expression. ([#674][gh-674])
- Fix parse error on parenthesized eraser. ([#675][gh-675])

### Added

Expand Down Expand Up @@ -420,4 +422,6 @@ and this project does not currently adhere to a particular versioning scheme.
[gh-648]: https://github.com/HigherOrderCO/Bend/issues/648
[gh-657]: https://github.com/HigherOrderCO/Bend/issues/657
[gh-659]: https://github.com/HigherOrderCO/Bend/pull/659
[gh-674]: https://github.com/HigherOrderCO/Bend/issues/674
[gh-675]: https://github.com/HigherOrderCO/Bend/issues/675
[Unreleased]: https://github.com/HigherOrderCO/Bend/compare/0.2.36...HEAD
4 changes: 4 additions & 0 deletions src/fun/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ impl<'a> TermParser<'a> {
return Ok(Term::Fan { fan: FanKind::Tup, tag: tag.unwrap_or(Tag::Static), els });
}

if opr == Op::MUL && self.try_consume(")") {
return Ok(Term::Era);
}

// Opr
unexpected_tag(self)?;
let fst = self.parse_term()?;
Expand Down
3 changes: 3 additions & 0 deletions src/imports/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl ParseBook {
let adts = std::mem::take(&mut self.adts);
let mut new_adts = IndexMap::new();
let mut ctrs_map = IndexMap::new();
let mut new_ctrs = IndexMap::new();

// Rename the ADTs and constructors to their canonical name,
// starting with `__` if not imported by the main book.
Expand All @@ -182,6 +183,7 @@ impl ParseBook {
ctr_name = Name::new(format!("__{}", ctr_name));
}

new_ctrs.insert(ctr_name.clone(), name.clone());
ctrs_map.insert(ctr, ctr_name.clone());
adt.ctrs.insert(ctr_name, f);
}
Expand All @@ -201,6 +203,7 @@ impl ParseBook {
}

self.adts = new_adts;
self.ctrs = new_ctrs;
}

/// Apply the necessary naming transformations to the book definitions,
Expand Down
3 changes: 3 additions & 0 deletions tests/golden_tests/import_system/import_ctr_syntax.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from lib/ctr_type import Ctr

main = (Ctr/Foo 2 3)
6 changes: 6 additions & 0 deletions tests/golden_tests/import_system/lib/ctr_type.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Test issue #674
type Ctr:
Foo { x, y }

def Ctr/wrap(x):
return Ctr/Foo { x: x, y: 0 }
1 change: 1 addition & 0 deletions tests/golden_tests/parse_file/era.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Main) = (*)
5 changes: 5 additions & 0 deletions tests/snapshots/import_system__import_ctr_syntax.bend.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/import_system/import_ctr_syntax.bend
---
λa (a lib/ctr_type/Ctr/Foo/tag 2 3)
5 changes: 5 additions & 0 deletions tests/snapshots/parse_file__era.bend.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/parse_file/era.bend
---
(Main) = *

0 comments on commit 425cdaa

Please sign in to comment.