Function: neocaml--syntax-propertize
neocaml--syntax-propertize is a natively compiled function defined in
neocaml.el.
Signature
(neocaml--syntax-propertize START END)
Documentation
Apply syntax properties to OCaml char literals and quoted strings.
Operates between START and END. See the commentary above for why this
is needed. This avoids calling syntax-ppss (which would be re-entrant,
since syntax-propertize runs from within it); quoted strings are
matched whole from their opening delimiter.
Source Code
;; Defined in /nix/store/ahssdx4rwzyxhyhavpn0bkznk13xrggi-emacs-packages-deps/share/emacs/site-lisp/elpa/neocaml-20260907.2015/neocaml.el
;;;; Syntax propertization
;;
;; A static syntax table can't classify OCaml's character literals and
;; quoted strings correctly, because they may contain characters that the
;; table would otherwise read as a string quote (`"'), a paren (`(' / `)'),
;; or a comment opener (`(*'). We fix this with a `syntax-propertize-function'
;; that marks those lexemes so the syntactic layer (sexp motion,
;; `electric-pair-mode', `delete-pair', `syntax-ppss') agrees with the parse
;; tree. Font-lock is handled by tree-sitter and is unaffected.
(defun neocaml--syntax-propertize (start end)
"Apply syntax properties to OCaml char literals and quoted strings.
Operates between START and END. See the commentary above for why this
is needed. This avoids calling `syntax-ppss' (which would be re-entrant,
since `syntax-propertize' runs from within it); quoted strings are
matched whole from their opening delimiter."
(goto-char start)
(funcall
(syntax-propertize-rules
;; Character literals: 'a', '\\n', '\\xFF', '"', '(', etc. Mark both
;; quotes as string delimiters so the contents are inert. A closing
;; quote is required, so type variables (e.g. 'a) are left untouched.
("\\_<\\('\\)\\(?:[^'\\\n]\\|\\\\.[^\\'\n \")]*\\)\\('\\)"
(1 "\"") (2 "\""))
;; Quoted strings {tag|...|tag}. Mark the opening brace as a generic
;; string fence and, if the matching |tag} is found, the closing brace
;; too, so the contents are inert.
("\\({\\)\\([[:lower:]_]*\\)|"
(1 (let* ((tag (match-string 2))
(close-pos (save-excursion
(when (search-forward (concat "|" tag "}") end t)
(point)))))
(when close-pos
(put-text-property (1- close-pos) close-pos
'syntax-table (string-to-syntax "|")))
(string-to-syntax "|")))))
(point) end))