mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 16:30:04 +03:00
Merge pull request #114 from rtfeldman/tag-patterns
Fix parsing global tag patterns
This commit is contained in:
commit
1706e24fd1
@ -760,10 +760,7 @@ fn parse_closure_param<'a>(
|
||||
char(')')
|
||||
),
|
||||
// The least common, but still allowed, e.g. \Foo -> ...
|
||||
loc!(one_of!(
|
||||
map!(private_tag(), Pattern::PrivateTag),
|
||||
map!(global_tag(), Pattern::GlobalTag)
|
||||
))
|
||||
loc!(tag_pattern())
|
||||
)
|
||||
.parse(arena, state)
|
||||
}
|
||||
@ -1410,10 +1407,7 @@ fn private_tag<'a>() -> impl Parser<'a, &'a str> {
|
||||
|
||||
/// This is mainly for matching tags in closure params, e.g. \Foo -> ...
|
||||
fn global_tag<'a>() -> impl Parser<'a, &'a str> {
|
||||
skip_first!(
|
||||
char('@'),
|
||||
global_tag_or_ident(|first_char| first_char.is_uppercase())
|
||||
)
|
||||
global_tag_or_ident(|first_char| first_char.is_uppercase())
|
||||
}
|
||||
|
||||
pub fn string_literal<'a>() -> impl Parser<'a, Expr<'a>> {
|
||||
|
@ -680,6 +680,20 @@ mod test_parse {
|
||||
// assert_eq!(Ok(expected), actual);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn tag_pattern() {
|
||||
let arena = Bump::new();
|
||||
let pattern = Located::new(0, 0, 1, 6, Pattern::GlobalTag("Thing"));
|
||||
let patterns = bumpalo::vec![in &arena; pattern];
|
||||
let expected = Closure(
|
||||
arena.alloc(patterns),
|
||||
arena.alloc(Located::new(0, 0, 10, 12, Int("42"))),
|
||||
);
|
||||
let actual = parse_with(&arena, "\\Thing -> 42");
|
||||
|
||||
assert_eq!(Ok(expected), actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn private_qualified_tag() {
|
||||
let arena = Bump::new();
|
||||
|
Loading…
Reference in New Issue
Block a user