Merge pull request #114 from rtfeldman/tag-patterns

Fix parsing global tag patterns
This commit is contained in:
Richard Feldman 2020-01-05 14:36:04 -05:00 committed by GitHub
commit 1706e24fd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -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>> {

View File

@ -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();