Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parsing even further #153

Merged
merged 38 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1dab6f1
move the Variable names etc into a grammar module
nikomatsakis Nov 4, 2023
51ccd0c
start an example
nikomatsakis Nov 4, 2023
7292feb
eg: tests
nikomatsakis Nov 5, 2023
44abbf2
refactor parsing of modes to be more extensible
nikomatsakis Nov 5, 2023
edc9d48
introduce delimited lists
nikomatsakis Nov 5, 2023
38f6fee
use `$<>` form in Rust grammar
nikomatsakis Nov 5, 2023
01d59dd
don't print `<>` if no variables are bound
nikomatsakis Nov 5, 2023
f5d4a2c
use language's binder character
nikomatsakis Nov 5, 2023
60b2cae
remove unused imports
nikomatsakis Nov 5, 2023
4a5e917
use `$()` for parameter listing
nikomatsakis Nov 5, 2023
8fe05f9
rename from Delimited to DelimitedVec
nikomatsakis Nov 5, 2023
f7dbc28
refactor parsing codegen
nikomatsakis Nov 5, 2023
5136925
refactor debug codegen
nikomatsakis Nov 5, 2023
c30ff77
use guarded bindings for optional where-clauses
nikomatsakis Nov 5, 2023
1dc3bda
accept defaulted binders in traits, remove `<>`
nikomatsakis Nov 5, 2023
af41c9a
refactor Parser API to use `multi_variant`
nikomatsakis Nov 5, 2023
2dc6a97
refactor tracing for clearer printouts
nikomatsakis Nov 5, 2023
1df4375
introduce left-recursive parsing
nikomatsakis Nov 5, 2023
ba6ebaf
improve variant names
nikomatsakis Nov 5, 2023
c732d22
add parser torture testing framework
nikomatsakis Nov 5, 2023
cf3141c
introduce cast variant reduction suppression
nikomatsakis Nov 5, 2023
3cf2831
fix subtle bug in `is_preferable`
nikomatsakis Nov 5, 2023
96f7077
document and add some more tests
nikomatsakis Nov 5, 2023
d7946b6
modify `{:#?}` to print the traditional debug
nikomatsakis Nov 6, 2023
a88c9cf
fix test to parse `a + b + c`
nikomatsakis Nov 6, 2023
0f04609
fix doctest
nikomatsakis Nov 7, 2023
901d2e1
refactor out a general `reject` method
nikomatsakis Nov 7, 2023
606a240
automatically reject variable names
nikomatsakis Nov 7, 2023
e95500c
move precedence into `SuccessfulParse`
nikomatsakis Nov 7, 2023
ac30d3b
adopt final_fn crate
nikomatsakis Nov 7, 2023
f7fe8f9
track the current state when we recurse
nikomatsakis Nov 7, 2023
afa8d89
track current text in current state
nikomatsakis Nov 7, 2023
165cb7c
introduce Precedence struct with associativity
nikomatsakis Nov 7, 2023
2b49e23
use reduction prefix to decide between variants
nikomatsakis Nov 7, 2023
61226f9
the default is now MAX priority
nikomatsakis Nov 7, 2023
0b1120a
introduce proper precedence, associativity
nikomatsakis Nov 7, 2023
13fe33c
more thorough testing around associativity
nikomatsakis Nov 9, 2023
ae6c33c
document ambiguity and precedence a bit more
nikomatsakis Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
don't print <> if no variables are bound
  • Loading branch information
nikomatsakis committed Nov 5, 2023
commit 01d59ddd55312eb673d7ee93c6a1bd145b7e01b0
14 changes: 8 additions & 6 deletions crates/formality-core/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,16 @@ where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "<")?;
for (kind, i) in self.kinds.iter().zip(0..) {
if i > 0 {
write!(f, ", ")?;
if !self.kinds.is_empty() {
write!(f, "<")?;
for (kind, i) in self.kinds.iter().zip(0..) {
if i > 0 {
write!(f, ", ")?;
}
write!(f, "{:?}", kind)?;
}
write!(f, "{:?}", kind)?;
write!(f, "> ")?;
}
write!(f, "> ")?;
write!(f, "{:?}", &self.term)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/formality-eg/grammar/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{Expr, StructDecl, Ty};
fn test_struct_decl() {
let r: StructDecl = term("struct Point { x: integer, y: integer }");
expect_test::expect![[r#"
struct Point <> { x : integer, y : integer }
struct Point { x : integer, y : integer }
"#]]
.assert_debug_eq(&r);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/coherence_overlap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn test_overlap_normalize_alias_to_LocalType() {

expect_test::expect![[r#"
Err(
"impls may overlap:\nimpl <ty> LocalTrait for ^ty0_0 where [^ty0_0 : Iterator] { }\nimpl <> LocalTrait for <LocalType as Mirror>::T where [] { }",
"impls may overlap:\nimpl <ty> LocalTrait for ^ty0_0 where [^ty0_0 : Iterator] { }\nimpl LocalTrait for <LocalType as Mirror>::T where [] { }",
)
"#]]
.assert_debug_eq(&test_program_ok(&gen_program(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: orphan_check(impl <> CoreTrait for CoreStruct where [] { })
Error: orphan_check(impl CoreTrait for CoreStruct where [] { })

Caused by:
failed to prove {@ IsLocal(CoreTrait(CoreStruct))} given {}, got {}
2 changes: 1 addition & 1 deletion tests/ui/coherence_orphan/alias_to_unit.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: orphan_check(impl <> CoreTrait for <FooStruct as Unit>::Assoc where [] { })
Error: orphan_check(impl CoreTrait for <FooStruct as Unit>::Assoc where [] { })

Caused by:
failed to prove {@ IsLocal(CoreTrait(<FooStruct as Unit>::Assoc))} given {}, got {}
2 changes: 1 addition & 1 deletion tests/ui/coherence_orphan/mirror_CoreStruct.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: orphan_check(impl <> CoreTrait for <CoreStruct as Mirror>::Assoc where [] { })
Error: orphan_check(impl CoreTrait for <CoreStruct as Mirror>::Assoc where [] { })

Caused by:
failed to prove {@ IsLocal(CoreTrait(<CoreStruct as Mirror>::Assoc))} given {}, got {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: orphan_check_neg(impl <> ! CoreTrait for CoreStruct where [] {})
Error: orphan_check_neg(impl ! CoreTrait for CoreStruct where [] {})

Caused by:
failed to prove {@ IsLocal(CoreTrait(CoreStruct))} given {}, got {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error: impls may overlap:
impl <ty> FooTrait for ^ty0_0 where [^ty0_0 : CoreTrait] { }
impl <> FooTrait for CoreStruct where [] { }
impl FooTrait for CoreStruct where [] { }
2 changes: 1 addition & 1 deletion tests/ui/coherence_overlap/u32_T_impls.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error: impls may overlap:
impl <> Foo for u32 where [] { }
impl Foo for u32 where [] { }
impl <ty> Foo for ^ty0_0 where [] { }
2 changes: 1 addition & 1 deletion tests/ui/coherence_overlap/u32_T_where_T_Is_impls.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error: impls may overlap:
impl <> Foo for u32 where [] { }
impl Foo for u32 where [] { }
impl <ty> Foo for ^ty0_0 where [^ty0_0 : Is] { }
2 changes: 1 addition & 1 deletion tests/ui/coherence_overlap/u32_not_u32_impls.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: check_trait_impl(impl <> Foo for u32 where [] { })
Error: check_trait_impl(impl Foo for u32 where [] { })

Caused by:
failed to disprove
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coherence_overlap/u32_u32_impls.stderr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error: duplicate impl in current crate: impl <> Foo for u32 where [] { }
Error: duplicate impl in current crate: impl Foo for u32 where [] { }
2 changes: 1 addition & 1 deletion tests/ui/consts/mismatch.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: check_trait_impl(impl <> Foo <const value(42, u32)> for u32 where [] { })
Error: check_trait_impl(impl Foo <const value(42, u32)> for u32 where [] { })

Caused by:
failed to prove {Foo(u32, const value(42, u32))} given {}, got {}