[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}
From: |
Arash Esbati |
Subject: |
bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \} |
Date: |
Fri, 23 Feb 2024 13:07:51 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Ihor Radchenko, 2024/02/19
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \},
Arash Esbati <=
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Roland Winkler, 2024/02/23
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Ihor Radchenko, 2024/02/24
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Roland Winkler, 2024/02/24
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Arash Esbati, 2024/02/25
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Roland Winkler, 2024/02/25
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Arash Esbati, 2024/02/26
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Ihor Radchenko, 2024/02/26
- bug#69266: 30.0.50; bibtex-parse-entry misreads escaped \}, Roland Winkler, 2024/02/26