diff --git a/src/term/parser/parser.rs b/src/term/parser/parser.rs index 31fba38cc..6eae0d173 100644 --- a/src/term/parser/parser.rs +++ b/src/term/parser/parser.rs @@ -413,16 +413,18 @@ where }) .labelled(""); - 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("+") .boxed(); - choice((succ_ctr, num_ctr, var, ctr, list, tup)) + let chr_pat = select!(Token::Char(c) => Pattern::Num(NumCtr::Num(c))).labelled("").boxed(); + + choice((succ_pat, num_pat, chr_pat, var, ctr, list, tup)) }) } diff --git a/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.hvm b/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.hvm index 7348be00b..6db64f927 100644 --- a/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.hvm +++ b/tests/golden_tests/encode_pattern_match/match_num_adt_tup_parser.hvm @@ -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)) diff --git a/tests/golden_tests/run_file/match_num_adt_tup_parser.hvm b/tests/golden_tests/run_file/match_num_adt_tup_parser.hvm index 7348be00b..6db64f927 100644 --- a/tests/golden_tests/run_file/match_num_adt_tup_parser.hvm +++ b/tests/golden_tests/run_file/match_num_adt_tup_parser.hvm @@ -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)) diff --git a/tests/snapshots/compile_file__missing_pat.hvm.snap b/tests/snapshots/compile_file__missing_pat.hvm.snap index 856adeea6..e9780f8dc 100644 --- a/tests/snapshots/compile_file__missing_pat.hvm.snap +++ b/tests/snapshots/compile_file__missing_pat.hvm.snap @@ -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 '(', '#', '$', , '[', '{', 'λ', 'let', 'match', '*', '|', +, or +At tests/golden_tests/compile_file/missing_pat.hvm:2:3: found ':' expected '(', '#', '$', , '[', '{', 'λ', 'let', 'match', '*', '|', +, , or  2 | : * diff --git a/tests/snapshots/encode_pattern_match__match_num_adt_tup_parser.hvm.snap b/tests/snapshots/encode_pattern_match__match_num_adt_tup_parser.hvm.snap index 95d979f91..f148075a0 100644 --- a/tests/snapshots/encode_pattern_match__match_num_adt_tup_parser.hvm.snap +++ b/tests/snapshots/encode_pattern_match__match_num_adt_tup_parser.hvm.snap @@ -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) diff --git a/tests/snapshots/run_file__match_num_adt_tup_parser.hvm.snap b/tests/snapshots/run_file__match_num_adt_tup_parser.hvm.snap index 24e9b5fb5..c775db59d 100644 --- a/tests/snapshots/run_file__match_num_adt_tup_parser.hvm.snap +++ b/tests/snapshots/run_file__match_num_adt_tup_parser.hvm.snap @@ -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 ("+", *)))