Commit 9dcf5998 authored by Alan Mackenzie's avatar Alan Mackenzie

Amend parse-partial-sexp correctly to handle two character comment delimiters

Do this by adding a new field to the parser state: the syntax of the last
character scanned, should that be the first char of a (potential) two char
construct, nil otherwise.
This should make the parser state complete.
Also document element 9 of the parser state.  Also refactor the code a bit.

* src/syntax.c (struct lisp_parse_state): Add a new field.
(SYNTAX_FLAGS_COMSTARTEND_FIRST): New function.
(internalize_parse_state): New function, extracted from scan_sexps_forward.
(back_comment): Call internalize_parse_state.
(forw_comment): Return the syntax of the last character scanned to the caller
when that character might be the first of a two character construct.
(Fforward_comment, scan_lists): New dummy variables, passed to forw_comment.
(scan_sexps_forward): Remove a redundant state parameter.  Access all `state'
information via the address parameter `state'.  Remove the code which converts
from external to internal form of `state'.  Access buffer contents only from
`from' onwards.  Reformulate code at the top of the main loop correctly to
recognize comment openers when starting in the middle of one.  Call
forw_comment with extra argument (for return of syntax value of possible first
char of a two char construct).
(Fparse_partial_sexp): Document elements 9, 10 of the parser state in the
doc string.  Clarify the doc string in general.  Call
internalize_parse_state.  Take account of the new elements when consing up the
output parser state.

* doc/lispref/syntax.texi: (Parser State): Document element 9 and the new
element 10.  Minor wording corrections (remove reference to "trivial
cases").
(Low Level Parsing): Minor corrections.

* etc/NEWS: Note new element 10, and documentation of element 9 of parser
state.
parent 565df726
......@@ -791,10 +791,10 @@ Hooks}).
@subsection Parser State
@cindex parser state
A @dfn{parser state} is a list of ten elements describing the state
of the syntactic parser, after it parses the text between a specified
starting point and a specified end point in the buffer. Parsing
functions such as @code{syntax-ppss}
A @dfn{parser state} is a list of (currently) eleven elements
describing the state of the syntactic parser, after it parses the text
between a specified starting point and a specified end point in the
buffer. Parsing functions such as @code{syntax-ppss}
@ifnottex
(@pxref{Position Parse})
@end ifnottex
......@@ -851,15 +851,20 @@ position where the string began. When outside of strings and comments,
this element is @code{nil}.
@item
Internal data for continuing the parsing. The meaning of this
data is subject to change; it is used if you pass this list
as the @var{state} argument to another call.
The list of the positions of the currently open parentheses, starting
with the outermost.
@item
When the last buffer position scanned was the (potential) first
character of a two character construct (comment delimiter or
escaped/char-quoted character pair), the @var{syntax-code}
(@pxref{Syntax Table Internals}) of that position. Otherwise
@code{nil}.
@end enumerate
Elements 1, 2, and 6 are ignored in a state which you pass as an
argument to continue parsing, and elements 8 and 9 are used only in
trivial cases. Those elements are mainly used internally by the
parser code.
argument to continue parsing. Elements 9 and 10 are mainly used
internally by the parser code.
One additional piece of useful information is available from a
parser state using this function:
......@@ -898,11 +903,11 @@ The depth starts at 0, or at whatever is given in @var{state}.
If the fourth argument @var{stop-before} is non-@code{nil}, parsing
stops when it comes to any character that starts a sexp. If
@var{stop-comment} is non-@code{nil}, parsing stops when it comes to the
start of an unnested comment. If @var{stop-comment} is the symbol
@var{stop-comment} is non-@code{nil}, parsing stops after the start of
an unnested comment. If @var{stop-comment} is the symbol
@code{syntax-table}, parsing stops after the start of an unnested
comment or a string, or the end of an unnested comment or a string,
whichever comes first.
comment or a string, or after the end of an unnested comment or a
string, whichever comes first.
If @var{state} is @code{nil}, @var{start} is assumed to be at the top
level of parenthesis structure, such as the beginning of a function
......
......@@ -175,6 +175,18 @@ a new window when opening man pages when there's already one, use
(inhibit-same-window . nil)
(mode . Man-mode))))
+++
** `parse-partial-sexp' state has a new element. Element 10 is
non-nil when the last character scanned might be the first character
of a two character construct, i.e. a comment delimiter or escaped
character. Its value is the syntax of that last character.
+++
** `parse-partial-sexp''s state, element 9, has now been confirmed as
permanent and documented, and may be used by Lisp programs. Its value
is a list of currently open parenthesis positions, starting with the
outermost parenthesis.
* Changes in Emacs 25.2 on Non-Free Operating Systems
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment