From: Arash Esbati <arash@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: 69266@debbugs.gnu.org, Roland Winkler <winkler@gnu.org>
Subject: bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}
Date: Fri, 23 Feb 2024 13:07:51 +0100 [thread overview]
Message-ID: <m28r3bl6y0.fsf@macmutant.fritz.box> (raw)
In-Reply-To: <87cysshl3j.fsf@localhost> (Ihor Radchenko's message of "Mon, 19 Feb 2024 09:14:24 +0000")
Ihor Radchenko <yantar92@posteo.net> writes:
> Consider the following bibtex entry:
>
> @InCollection{Geyer2011,
> title = {Introduction to Markov Chain Monte \} Carlo},
> pages = 45,
> }
>
> According to https://www.bibtex.org/SpecialSymbols/, characters that
> conflict with Bibtex format description can be \-escaped.
>
> In the above, with point at the beginning of the entry, M-:
> (bibtex-parse-entry t), yields
>
> ("=type=" . "InCollection")
> ("=key=" . "Geyer2011")
> ("title" . "Introduction to Markov Chain Monte \\")
>
> The escaped \} is treated as closing }, which is incorrect.
>
> Expected: escaping is properly processed.
I think the issue is that `bibtex-parse-entry' calls
`bibtex-text-in-field-bounds' which calls `bibtex-parse-field-string'
which is defined like this:
--8<---------------cut here---------------start------------->8---
(defun bibtex-parse-field-string ()
"Parse a BibTeX field string enclosed by braces or quotes.
If a syntactically correct string is found, a pair containing the start and
end position of the field string is returned, nil otherwise.
Do not move point."
(let ((end-point
(or (and (eq (following-char) ?\")
(save-excursion
(with-syntax-table bibtex-quoted-string-syntax-table
(forward-sexp 1))
(point)))
(and (eq (following-char) ?\{)
(save-excursion
(with-syntax-table bibtex-braced-string-syntax-table
(forward-sexp 1))
(point))))))
(if end-point
(cons (point) end-point))))
--8<---------------cut here---------------end--------------->8---
`bibtex-braced-string-syntax-table' is defined as:
--8<---------------cut here---------------start------------->8---
(defconst bibtex-braced-string-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\{ "(}" st)
(modify-syntax-entry ?\} "){" st)
(modify-syntax-entry ?\[ "." st)
(modify-syntax-entry ?\] "." st)
(modify-syntax-entry ?\( "." st)
(modify-syntax-entry ?\) "." st)
(modify-syntax-entry ?\\ "." st)
(modify-syntax-entry ?\" "." st)
st)
"Syntax-table to parse matched braces.")
--8<---------------cut here---------------end--------------->8---
where the backslash gets the punctuation class. Hence, the
(forward-sexp 1) call above goes wrong. You can eval this in scratch
--8<---------------cut here---------------start------------->8---
(defconst bibtex-braced-string-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\{ "(}" st)
(modify-syntax-entry ?\} "){" st)
(modify-syntax-entry ?\[ "." st)
(modify-syntax-entry ?\] "." st)
(modify-syntax-entry ?\( "." st)
(modify-syntax-entry ?\) "." st)
;; "." changed to "\\"
(modify-syntax-entry ?\\ "\\" st)
(modify-syntax-entry ?\" "." st)
st)
"Syntax-table to parse matched braces.")
--8<---------------cut here---------------end--------------->8---
and try your test case again -- it should give the expected result. I
can't tell why the backslash doesn't get the escape-char syntax, it
would make sense IMO, but that's something Roland W. (CC'ed) has to
decide.
Best, Arash
next prev parent reply other threads:[~2024-02-23 12:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 9:14 bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \} Ihor Radchenko
2024-02-23 12:07 ` Arash Esbati [this message]
2024-02-23 15:25 ` Roland Winkler
2024-02-24 12:19 ` Ihor Radchenko
2024-02-24 16:05 ` Roland Winkler
2024-02-25 17:50 ` Arash Esbati
2024-02-26 0:50 ` Roland Winkler
2024-02-26 14:42 ` Arash Esbati
2024-02-26 17:08 ` Ihor Radchenko
2024-02-26 18:56 ` Roland Winkler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m28r3bl6y0.fsf@macmutant.fritz.box \
--to=arash@gnu.org \
--cc=69266@debbugs.gnu.org \
--cc=winkler@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).