123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051openPpxliblettag="b"letmk_expression~ctxt:_expr=tryletloc=expr.pexp_locinmatchexpr.pexp_descwith|Pexp_constant(Pconst_string(value,_,_))->letbytepattern=Bytepattern.parse~locvalueinBytepattern.to_transient_builder~locbytepattern|Pexp_match(data,cases)->letcases=List.map(fun(case:case)->matchcase.pc_lhswith|{ppat_desc=Ppat_constant(Pconst_string(value,_,_));_}->letbytepattern=Bytepattern.parse~locvalueinletbody=case.pc_rhsinletguard=case.pc_guardin(bytepattern,guard,body)|_->Location.raise_errorf~loc"%s"{| Bytestrings in match expressions are only valie when the patterns are constant strings, like:
match%b data with
| \{| ... |\} -> ...
|})casesinBytepattern.to_match_expression~loc~datacases|_->Location.raise_errorf~loc"%s"{|Bytestrings are only supported when constructing new values with
tagged with `%b and when pattern matching against values in
`match` expressions.
|}withBytepattern.Error{loc;error}->letext=Location.error_extensionf~loc"%s"errorinAst_builder.Default.pexp_extension~locextletexpression_rule=Extension.V3.declaretagExtension.Context.expressionAst_pattern.(single_expr_payload__)mk_expression|>Context_free.Rule.extensionlet()=Driver.register_transformationtag~rules:[expression_rule]