Ihor Radchenko <[email protected]> writes:
> Unfortunately, I do not see an easy solution without hitting parser
> performance. Our general approach is to avoid forward-parsing as much as
> possible with an exception to paired brackets (because Elisp allows
> parsing paired brackets fast using C-level code). However, AFAIK, there
> is no easy way to parse brackets that are not single symbols. "\(" is
> impossible to match using `scan-lists'.
One interesting idea to consider is using PEG (third-party ELPA package).
The above examples with paired parenthesis can be parsed using the
following PEG:
(with-peg-rules
((no-paren (not "\\(") (not "\\)") (any))
(no-paren-expr (+ no-paren))
(paren-expr "\\(" (* (or no-paren-expr paren-expr)) "\\)"))
(peg-run (peg paren-expr)))
PEG is not built-in though, so we cannot use it in Org.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>