elisp: Parser State
34.6.3 Parser State
-------------------
A “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 ‘syntax-ppss’ (Position Parse) return a parser state as the
value. Some parsing functions accept a parser state as an argument, for
resuming parsing.
Here are the meanings of the elements of the parser state:
0. The depth in parentheses, counting from 0. *Warning:* this can be
negative if there are more close parens than open parens between
the parser’s starting point and end point.
1. The character position of the start of the innermost parenthetical
grouping containing the stopping point; ‘nil’ if none.
2. The character position of the start of the last complete
subexpression terminated; ‘nil’ if none.
3. Non-‘nil’ if inside a string. More precisely, this is the
character that will terminate the string, or ‘t’ if a generic
string delimiter character should terminate it.
Syntax Flags::); or the comment nesting level if inside a comment
that can be nested.
5. ‘t’ if the end point is just after a quote character.
6. The minimum parenthesis depth encountered during this scan.
7. What kind of comment is active: ‘nil’ if not in a comment or in a
comment of style ‘a’; 1 for a comment of style ‘b’; 2 for a comment
of style ‘c’; and ‘syntax-table’ for a comment that should be ended
by a generic comment delimiter character.
8. The string or comment start position. While inside a comment, this
is the position where the comment began; while inside a string,
this is the position where the string began. When outside of
strings and comments, this element is ‘nil’.
9. 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 STATE
argument to another call.
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.
One additional piece of useful information is available from a parser
state using this function:
-- Function: syntax-ppss-toplevel-pos state
This function extracts, from parser state STATE, the last position
scanned in the parse which was at top level in grammatical
structure. “At top level” means outside of any parentheses,
comments, or strings.
The value is ‘nil’ if STATE represents a parse which has arrived at
a top level position.