mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix(parse): rename function in test case
like Grant remarked, the chaining function is actually right-associative, not left-associative
This commit is contained in:
parent
322b15d757
commit
e7dad1b54a
1 changed files with 3 additions and 3 deletions
|
|
@ -91,15 +91,15 @@ open CCShims_
|
||||||
let integer =
|
let integer =
|
||||||
P.chars1_if (function '0'..'9'->true|_->false) >|= int_of_string in
|
P.chars1_if (function '0'..'9'->true|_->false) >|= int_of_string in
|
||||||
|
|
||||||
let chainl1 e op =
|
let chainr1 e op =
|
||||||
P.fix (fun r ->
|
P.fix (fun r ->
|
||||||
e >>= fun x -> (op <*> P.return x <*> r) <|> P.return x) in
|
e >>= fun x -> (op <*> P.return x <*> r) <|> P.return x) in
|
||||||
|
|
||||||
let expr : int P.t =
|
let expr : int P.t =
|
||||||
P.fix (fun expr ->
|
P.fix (fun expr ->
|
||||||
let factor = parens expr <|> integer in
|
let factor = parens expr <|> integer in
|
||||||
let term = chainl1 factor (mul <|> div) in
|
let term = chainr1 factor (mul <|> div) in
|
||||||
chainl1 term (add <|> sub)) in
|
chainr1 term (add <|> sub)) in
|
||||||
|
|
||||||
assert_equal (Ok 6) (P.parse_string expr "4*1+2");
|
assert_equal (Ok 6) (P.parse_string expr "4*1+2");
|
||||||
assert_equal (Ok 12) (P.parse_string expr "4*(1+2)");
|
assert_equal (Ok 12) (P.parse_string expr "4*(1+2)");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue