-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And a few more tests along the way for others. Note that it is important here that we try to parse for a 'Pair' BEFORE we try to parse for a constructor pattern. Because the latter would swallow any Pair pattern.
- Loading branch information
1 parent
91a7e77
commit 5c59b81
Showing
13 changed files
with
374 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{ | ||
ast::UntypedPattern, | ||
builtins::PAIR, | ||
parser::{error::ParseError, token::Token}, | ||
}; | ||
use chumsky::prelude::*; | ||
|
||
pub fn parser( | ||
pattern: Recursive<'_, Token, UntypedPattern, ParseError>, | ||
) -> impl Parser<Token, UntypedPattern, Error = ParseError> + '_ { | ||
select! {Token::UpName { name } if name == PAIR => name} | ||
.ignore_then(choice(( | ||
just(Token::LeftParen), | ||
just(Token::NewLineLeftParen), | ||
))) | ||
.then(pattern.clone()) | ||
.then_ignore(just(Token::Comma)) | ||
.then(pattern.clone()) | ||
.then_ignore(just(Token::RightParen)) | ||
.map_with_span(|((_name, fst), snd), location| UntypedPattern::Pair { | ||
fst: Box::new(fst), | ||
snd: Box::new(snd), | ||
location, | ||
}) | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/aiken-lang/src/parser/pattern/snapshots/pattern_constructor_labels.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nFoo { a, b }" | ||
--- | ||
Constructor { | ||
is_record: true, | ||
location: 0..12, | ||
name: "Foo", | ||
arguments: [ | ||
CallArg { | ||
label: Some( | ||
"a", | ||
), | ||
location: 6..7, | ||
value: Var { | ||
location: 6..7, | ||
name: "a", | ||
}, | ||
}, | ||
CallArg { | ||
label: Some( | ||
"b", | ||
), | ||
location: 9..10, | ||
value: Var { | ||
location: 9..10, | ||
name: "b", | ||
}, | ||
}, | ||
], | ||
module: None, | ||
constructor: (), | ||
with_spread: false, | ||
tipo: (), | ||
} |
31 changes: 31 additions & 0 deletions
31
crates/aiken-lang/src/parser/pattern/snapshots/pattern_constructor_no_labels.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nFoo(a, b)" | ||
--- | ||
Constructor { | ||
is_record: false, | ||
location: 0..9, | ||
name: "Foo", | ||
arguments: [ | ||
CallArg { | ||
label: None, | ||
location: 4..5, | ||
value: Var { | ||
location: 4..5, | ||
name: "a", | ||
}, | ||
}, | ||
CallArg { | ||
label: None, | ||
location: 7..8, | ||
value: Var { | ||
location: 7..8, | ||
name: "b", | ||
}, | ||
}, | ||
], | ||
module: None, | ||
constructor: (), | ||
with_spread: false, | ||
tipo: (), | ||
} |
44 changes: 44 additions & 0 deletions
44
crates/aiken-lang/src/parser/pattern/snapshots/pattern_constructor_pair_interleaved.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nFoo(a, Pair(1, 2))" | ||
--- | ||
Constructor { | ||
is_record: false, | ||
location: 0..18, | ||
name: "Foo", | ||
arguments: [ | ||
CallArg { | ||
label: None, | ||
location: 4..5, | ||
value: Var { | ||
location: 4..5, | ||
name: "a", | ||
}, | ||
}, | ||
CallArg { | ||
label: None, | ||
location: 7..17, | ||
value: Pair { | ||
location: 7..17, | ||
fst: Int { | ||
location: 12..13, | ||
value: "1", | ||
base: Decimal { | ||
numeric_underscore: false, | ||
}, | ||
}, | ||
snd: Int { | ||
location: 15..16, | ||
value: "2", | ||
base: Decimal { | ||
numeric_underscore: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
module: None, | ||
constructor: (), | ||
with_spread: false, | ||
tipo: (), | ||
} |
25 changes: 25 additions & 0 deletions
25
crates/aiken-lang/src/parser/pattern/snapshots/pattern_constructor_spread.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nFoo { a, .. }" | ||
--- | ||
Constructor { | ||
is_record: true, | ||
location: 0..13, | ||
name: "Foo", | ||
arguments: [ | ||
CallArg { | ||
label: Some( | ||
"a", | ||
), | ||
location: 6..7, | ||
value: Var { | ||
location: 6..7, | ||
name: "a", | ||
}, | ||
}, | ||
], | ||
module: None, | ||
constructor: (), | ||
with_spread: true, | ||
tipo: (), | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/aiken-lang/src/parser/pattern/snapshots/pattern_discard_named.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\n_foo" | ||
--- | ||
Discard { | ||
name: "_foo", | ||
location: 0..4, | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/aiken-lang/src/parser/pattern/snapshots/pattern_discard_unnamed.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\n_" | ||
--- | ||
Discard { | ||
name: "_", | ||
location: 0..1, | ||
} |
19 changes: 19 additions & 0 deletions
19
crates/aiken-lang/src/parser/pattern/snapshots/pattern_list_spread.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\n[head, ..]" | ||
--- | ||
List { | ||
location: 0..10, | ||
elements: [ | ||
Var { | ||
location: 1..5, | ||
name: "head", | ||
}, | ||
], | ||
tail: Some( | ||
Discard { | ||
name: "_", | ||
location: 9..10, | ||
}, | ||
), | ||
} |
15 changes: 15 additions & 0 deletions
15
crates/aiken-lang/src/parser/pattern/snapshots/pattern_pair_discards.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nPair(_, _)" | ||
--- | ||
Pair { | ||
location: 0..10, | ||
fst: Discard { | ||
name: "_", | ||
location: 5..6, | ||
}, | ||
snd: Discard { | ||
name: "_", | ||
location: 8..9, | ||
}, | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/aiken-lang/src/parser/pattern/snapshots/pattern_pair_explicit_depth_1.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
source: crates/aiken-lang/src/parser/pattern/mod.rs | ||
description: "Code:\n\nPair(14, True)" | ||
--- | ||
Pair { | ||
location: 0..14, | ||
fst: Int { | ||
location: 5..7, | ||
value: "14", | ||
base: Decimal { | ||
numeric_underscore: false, | ||
}, | ||
}, | ||
snd: Constructor { | ||
is_record: false, | ||
location: 9..13, | ||
name: "True", | ||
arguments: [], | ||
module: None, | ||
constructor: (), | ||
with_spread: false, | ||
tipo: (), | ||
}, | ||
} |
Oops, something went wrong.