mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-11-05 04:51:40 +03:00
[sc-441] Add char patterns
This commit is contained in:
parent
39ffe05d72
commit
5f2d835a77
@ -413,16 +413,18 @@ where
|
||||
})
|
||||
.labelled("<Num>");
|
||||
|
||||
let num_ctr = num.map(|n| Pattern::Num(NumCtr::Num(n)));
|
||||
let num_pat = num.map(|n| Pattern::Num(NumCtr::Num(n)));
|
||||
|
||||
let succ_ctr = num
|
||||
let succ_pat = num
|
||||
.then_ignore(just(Token::Add))
|
||||
.then(name_or_era().or_not())
|
||||
.map(|(num, nam)| Pattern::Num(NumCtr::Succ(num, nam)))
|
||||
.labelled("<Num>+")
|
||||
.boxed();
|
||||
|
||||
choice((succ_ctr, num_ctr, var, ctr, list, tup))
|
||||
let chr_pat = select!(Token::Char(c) => Pattern::Num(NumCtr::Num(c))).labelled("<Char>").boxed();
|
||||
|
||||
choice((succ_pat, num_pat, chr_pat, var, ctr, list, tup))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Testing various forms of pattern matching
|
||||
data Result = (Ok val) | (Err err)
|
||||
|
||||
Parse state (String.cons 40 xs) = (Ok (40, xs, state))
|
||||
Parse state (String.cons 41 xs) = (Ok (41, xs, state))
|
||||
Parse state (String.cons 10 xs) = (Ok (0, xs, state))
|
||||
Parse state (String.cons '(' xs) = (Ok ('(', xs, state))
|
||||
Parse state (String.cons ')' xs) = (Ok (')', xs, state))
|
||||
Parse state (String.cons '\n' xs) = (Ok (0, xs, state))
|
||||
Parse state xs = (Err (xs, state))
|
||||
|
||||
main =
|
||||
let str = (String.cons 40 (String.cons 50 String.nil));
|
||||
let str = "(+";
|
||||
let state = *;
|
||||
match (Parse state str) {
|
||||
(Ok (val, xs, state)): (val, (Parse state xs))
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Testing various forms of pattern matching
|
||||
data Result = (Ok val) | (Err err)
|
||||
|
||||
Parse state (String.cons 40 xs) = (Ok (40, xs, state))
|
||||
Parse state (String.cons 41 xs) = (Ok (41, xs, state))
|
||||
Parse state (String.cons 10 xs) = (Ok (0, xs, state))
|
||||
Parse state (String.cons '(' xs) = (Ok ('(', xs, state))
|
||||
Parse state (String.cons ')' xs) = (Ok (')', xs, state))
|
||||
Parse state (String.cons '\n' xs) = (Ok (0, xs, state))
|
||||
Parse state xs = (Err (xs, state))
|
||||
|
||||
main =
|
||||
let str = (String.cons 40 (String.cons 50 String.nil));
|
||||
let str = "(+";
|
||||
let state = *;
|
||||
match (Parse state str) {
|
||||
(Ok (val, xs, state)): (val, (Parse state xs))
|
||||
|
@ -2,5 +2,5 @@
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/compile_file/missing_pat.hvm
|
||||
---
|
||||
At tests/golden_tests/compile_file/missing_pat.hvm:2:3: found ':' expected '(', '#', '$', <Name>, '[', '{', 'λ', 'let', 'match', '*', '|', <Num>+, or <Num>
|
||||
At tests/golden_tests/compile_file/missing_pat.hvm:2:3: found ':' expected '(', '#', '$', <Name>, '[', '{', 'λ', 'let', 'match', '*', '|', <Num>+, <Num>, or <Char>
|
||||
[0m 2 | [4m[31m:[0m *[0m
|
||||
|
@ -5,7 +5,7 @@ input_file: tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.hvm
|
||||
TaggedScott:
|
||||
(Parse) = λa λb (#String (b #String.String.cons.head λc #String.String.cons.tail λd λe (match (- c 40) { 0: λf λg (Ok (40, (g, f))); 1+: λk match k { 0: λl λm (Ok (41, (m, l))); 1+: λq match (- q 18446744073709551584) { 0: λr λs (Ok (0, (s, r))); 1+: λw λy λz (Err ((String.cons (+ w 11) z), y)) } } } e d) λeb (Err (String.nil, eb))) a)
|
||||
|
||||
(main) = #Result ((Parse * (String.cons 40 (String.cons 50 String.nil))) #Result.Ok.val λd let (e, f) = d; (let (g, h) = f; λi (i, (Parse h g)) e) #Result.Err.err λm (Err m))
|
||||
(main) = #Result ((Parse * (String.cons 40 (String.cons 43 String.nil))) #Result.Ok.val λd let (e, f) = d; (let (g, h) = f; λi (i, (Parse h g)) e) #Result.Err.err λm (Err m))
|
||||
|
||||
(String.cons) = λa λb #String λc #String λ* #String.String.cons.tail (#String.String.cons.head (c a) b)
|
||||
|
||||
@ -18,7 +18,7 @@ TaggedScott:
|
||||
Scott:
|
||||
(Parse) = λa λb (b λc λd λe (match (- c 40) { 0: λf λg (Ok (40, (g, f))); 1+: λk match k { 0: λl λm (Ok (41, (m, l))); 1+: λq match (- q 18446744073709551584) { 0: λr λs (Ok (0, (s, r))); 1+: λw λy λz (Err ((String.cons (+ w 11) z), y)) } } } e d) λeb (Err (String.nil, eb)) a)
|
||||
|
||||
(main) = (Parse * (String.cons 40 (String.cons 50 String.nil)) λd let (e, f) = d; (let (g, h) = f; λi (i, (Parse h g)) e) λm (Err m))
|
||||
(main) = (Parse * (String.cons 40 (String.cons 43 String.nil)) λd let (e, f) = d; (let (g, h) = f; λi (i, (Parse h g)) e) λm (Err m))
|
||||
|
||||
(String.cons) = λa λb λc λ* (c a b)
|
||||
|
||||
|
@ -2,4 +2,4 @@
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/run_file/match_num_adt_tup_parser.hvm
|
||||
---
|
||||
(40, (Err ("2", *)))
|
||||
(40, (Err ("+", *)))
|
||||
|
Loading…
Reference in New Issue
Block a user