aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/extraction
diff options
context:
space:
mode:
authorGravatar Paul Steckler <psteck@mit.edu>2017-11-22 12:33:02 -0500
committerGravatar Paul Steckler <psteck@mit.edu>2017-11-22 12:33:02 -0500
commitecfb73d655601e9aed736b0083a6f6b4682a2083 (patch)
treee75639ee9ef587f09c0766f571a9579da50fcf40 /plugins/extraction
parenteb91ccaf236bc9a60a1e216b76a0a42980c072a7 (diff)
use OCaml criteria for infix ops, #6212
Diffstat (limited to 'plugins/extraction')
-rw-r--r--plugins/extraction/ocaml.ml26
1 files changed, 24 insertions, 2 deletions
diff --git a/plugins/extraction/ocaml.ml b/plugins/extraction/ocaml.ml
index 9cbc3fd71..eea5968ce 100644
--- a/plugins/extraction/ocaml.ml
+++ b/plugins/extraction/ocaml.ml
@@ -100,11 +100,33 @@ let pp_global k r = str (str_global k r)
let pp_modname mp = str (Common.pp_module mp)
+(* grammar from OCaml 4.06 manual, "Prefix and infix symbols" *)
+
+let infix_symbols =
+ ['=' ; '<' ; '>' ; '@' ; '^' ; ';' ; '&' ; '+' ; '-' ; '*' ; '/' ; '$' ; '%' ]
+let operator_chars =
+ [ '!' ; '$' ; '%' ; '&' ; '*' ; '+' ; '-' ; '.' ; '/' ; ':' ; '<' ; '=' ; '>' ; '?' ; '@' ; '^' ; '|' ; '~' ]
+
+let substring_all_opchars s start stop =
+ let rec check_char i =
+ if i >= stop then true
+ else
+ List.mem s.[i] operator_chars && check_char (i+1)
+ in
+ check_char start
+
let is_infix r =
is_inline_custom r &&
(let s = find_custom r in
- let l = String.length s in
- l >= 2 && s.[0] == '(' && s.[l-1] == ')')
+ let len = String.length s in
+ len >= 3 &&
+ (* parenthesized *)
+ (s.[0] == '(' && s.[len-1] == ')' &&
+ (* either, begins with infix symbol, any remainder is all operator chars *)
+ (List.mem s.[1] infix_symbols && substring_all_opchars s 2 (len-1))
+ ||
+ (* or, starts with #, at least one more char, all are operator chars *)
+ (s.[1] == '#' && len >= 4 && substring_all_opchars s 2 (len-1))))
let get_infix r =
let s = find_custom r in