mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-11-04 01:20:56 +03:00
[sc-441] Fix encoding of string patterns
This commit is contained in:
parent
7b859fc41e
commit
fb8f3fefc7
@ -104,11 +104,11 @@ impl Pattern {
|
||||
}
|
||||
|
||||
fn encode_str(str: &str) -> Pattern {
|
||||
let lnil = Pattern::Ctr(Name::from(LNIL), vec![]);
|
||||
let lnil = Pattern::Ctr(Name::from(SNIL), vec![]);
|
||||
|
||||
str.chars().rfold(lnil, |tail, head| {
|
||||
let head = Pattern::Num(NumCtr::Num(head as u64));
|
||||
Pattern::Ctr(Name::from(LCONS), vec![head, tail])
|
||||
Pattern::Ctr(Name::from(SCONS), vec![head, tail])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
9
tests/golden_tests/run_file/match_str.hvm
Normal file
9
tests/golden_tests/run_file/match_str.hvm
Normal file
@ -0,0 +1,9 @@
|
||||
(is_as "As") = 2
|
||||
(is_as "as") = 2
|
||||
(is_as "") = 1
|
||||
(is_as *) = 0
|
||||
|
||||
map f (List.cons x xs) = (List.cons (f x) (map f xs))
|
||||
map f [] = []
|
||||
|
||||
main = (map is_as ["As" "as" "" "Asd" "qwerty" "AAs"])
|
5
tests/snapshots/run_file__match_str.hvm.snap
Normal file
5
tests/snapshots/run_file__match_str.hvm.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/run_file/match_str.hvm
|
||||
---
|
||||
[2, 2, 1, 0, 0, 0]
|
@ -2,6 +2,6 @@
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/simplify_matches/match_str.hvm
|
||||
---
|
||||
(is_as) = λa match a { (List.cons b c): (match b { 65: λd (match d { (List.cons f g): λh (match f { 115: λ* λj (match j { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } h g); (List.nil): λ* 0 } *); 97: λhb (match hb { (List.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (List.nil): λ* 0 } *); *: λ* 0 } c); (List.nil): 1 }
|
||||
(is_as) = λa match a { (String.cons b c): (match b { 65: λd (match d { (String.cons f g): λh (match f { 115: λ* λj (match j { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } h g); (String.nil): λ* 0 } *); 97: λhb (match hb { (String.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (String.nil): λ* 0 } *); *: λ* 0 } c); (String.nil): 1 }
|
||||
|
||||
(main) = *
|
||||
|
Loading…
Reference in New Issue
Block a user