Skip to content

Commit 490285d

Browse files
committed
small improvement to variable subst code
1 parent 40c9fb1 commit 490285d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

ppx_regexp/transformations.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ module Regexp = struct
3131
let to_string ~ctx =
3232
let p_alt, p_seq, p_suffix, p_atom = 0, 1, 2, 3 in
3333
let delimit_if b s = if b then "(?:" ^ s ^ ")" else s in
34+
let get_parsed ~loc idr =
35+
let var_name = idr.txt in
36+
let content =
37+
match Util.Ctx.find var_name ctx with
38+
| Some value -> value
39+
| None -> Util.error ~loc "Variable '%s' not found. %%pcre and %%mik only support global let bindings for substitution." var_name
40+
in
41+
content
42+
in
3443
let rec recurse p (e' : _ Location.loc) =
3544
let loc = e'.Location.loc in
36-
let get_parsed idr =
37-
let var_name = idr.txt in
38-
let content =
39-
match Util.Ctx.find var_name ctx with
40-
| Some value -> value
41-
| None -> Util.error ~loc "Variable '%s' not found. %%pcre and %%mik only support global let bindings for substitution." var_name
42-
in
43-
content
44-
in
4545
match e'.Location.txt with
4646
| Code s ->
4747
(* Delimiters not needed as Regexp.parse_exn only returns single
@@ -60,10 +60,10 @@ module Regexp = struct
6060
| Capture _ -> Util.error ~loc "Unnamed capture is not allowed for %%pcre and %%mik."
6161
| Capture_as (_, _, e) -> "(" ^ recurse p_alt e ^ ")"
6262
| Named_subs (idr, _, _, _) ->
63-
let content = get_parsed idr in
63+
let content = get_parsed ~loc idr in
6464
"(" ^ recurse p_alt content ^ ")"
6565
| Unnamed_subs (idr, _) ->
66-
let content = get_parsed idr in
66+
let content = get_parsed ~loc idr in
6767
recurse p_atom content
6868
| Pipe_all (_, _, e) -> recurse p_alt e
6969
| Call _ -> Util.error ~loc "(&...) is not implemented for %%pcre and %%mik."

0 commit comments

Comments
 (0)