String patterns

This commit is contained in:
greg 2018-10-31 01:45:16 -07:00
parent bfbc1580aa
commit ec5a9d457e
2 changed files with 22 additions and 1 deletions

View File

@ -569,6 +569,15 @@ if a { is 15 -> "x", is 10 -> "y" }
test_in_fresh_env!(source, "\"y\""); test_in_fresh_env!(source, "\"y\"");
} }
#[test]
fn string_pattern() {
let source = r#"
let a = "foo"
if a { is "foo" -> "x", is _ -> "y" }
"#;
test_in_fresh_env!(source, "\"x\"");
}
#[test] #[test]
fn boolean_pattern() { fn boolean_pattern() {
let source = r#" let source = r#"

View File

@ -292,7 +292,19 @@ impl PatternLiteral {
bound_vars: vec![], bound_vars: vec![],
} }
}, },
StringPattern(_s) => unimplemented!(), StringPattern(s) => {
let guard = Some(Expr::Call {
f: Box::new(Expr::Func(Func::BuiltIn(Rc::new("==".to_string())))),
args: vec![Expr::Lit(Lit::StringLit(s.clone())), Expr::ConditionalTargetSigilValue]
});
Subpattern {
tag: None,
subpatterns: vec![],
guard,
bound_vars: vec![],
}
},
BoolPattern(b) => { BoolPattern(b) => {
let guard = Some(if *b { let guard = Some(if *b {
Expr::ConditionalTargetSigilValue Expr::ConditionalTargetSigilValue