ocaml / tuareg

Emacs OCaml mode
GNU General Public License v3.0
363 stars 79 forks source link

Fix highlight hyphen leading operators #313

Open gengar opened 8 months ago

gengar commented 8 months ago

The "-" case always matches on "[^0-9>]" and never on latter.

monnier commented 8 months ago

The "-" case always matches on "[^0-9>]" and never on latter.

Could you show some example of the problem?

AFAICT your patch changes the regexp such that subgroup 2 is always matched, which doesn't seem right.

gengar commented 8 months ago

OK, here is a example:

(let ((operator-char     "[-!$%&*+./:<=>?@^|~]")
      (operator-char-no> "[-!$%&*+./:<=?@^|~]"))
  (let ((reg1 (concat "\\(-\\)\\(?:[^0-9>]\\|\\("
                      operator-char-no> operator-char "*\\)\\)"))
        (reg2 (concat "\\(-\\)\\("
                      operator-char-no>
                      operator-char "*\\|\\(?:[^0-9>]\\)\\)"))
        (str "-$$$"))
    (string-match reg1 str)
    (print (match-string 0 str)) ; => "-$"
    (print (match-string 2 str)) ; => nil

    (string-match reg2 str)
    (print (match-string 0 str)) ; => "-$$$"
    (print (match-string 2 str)) ; => "$$$"
    nil))

I would expect to tuareg-mode highlights the whole symbol like -$$$.