It seems format-time-string uses the same format as strftime(3), and strptime(3) is the reverse of strftime(3), so I wrote an Emacs dynamic module just for strptime(3), for example,
(strptime "2020-04-01" "%Y-%m-%d")
;; => (0 0 0 1 4 2020 3 nil 0)
The result is (SEC MINUTE HOUR DAY MONTH YEAR DOW DST UTCOFF), you can feed it to encode-time
A combination of regexp-quote and format-spec should help in your case. Especially, format-spec works with format specifiers of the format sequences consisting of one % character and one letter.
(defun my-format-spec-to-regexp (format)
"Convert FORMAT with placeholders %Y, %m, and %d into a regexp."
(format-spec (regexp-quote format)
'((?Y . "...
Thanks, Stefan, it seems to work like a charm! I.e. the parser state is exactly as expected, and e.g. forward-sexp now jumps over 'McDonald''s', which it did not do without the syntax propertizing.
I am unsure where parse-sexp-lookup-properties, which must obviously be t for syntax table properties to be actually used, is set. pascal.el does not set it, ...
The syntax tables themselves can't handle this right, but Emacs offers syntax-propertize to circumvent this kind of limitation by giving special syntax to specific occurrences of characters in buffers.
E.g. pascal-mode (where the same escaping is used in strings as the one you describe) has: