elisp: Low-Level Parsing

 
 34.6.4 Low-Level Parsing
 ------------------------
 
 The most basic way to use the expression parser is to tell it to start
 at a given position with a certain state, and parse up to a specified
 end position.
 
  -- Function: parse-partial-sexp start limit &optional target-depth
           stop-before state stop-comment
      This function parses a sexp in the current buffer starting at
      START, not scanning past LIMIT.  It stops at position LIMIT or when
      certain criteria described below are met, and sets point to the
      Parser State::) describing the status of the parse at the point
      where it stops.
 
      If the third argument TARGET-DEPTH is non-‘nil’, parsing stops if
      the depth in parentheses becomes equal to TARGET-DEPTH.  The depth
      starts at 0, or at whatever is given in STATE.
 
      If the fourth argument STOP-BEFORE is non-‘nil’, parsing stops when
      it comes to any character that starts a sexp.  If STOP-COMMENT is
      non-‘nil’, parsing stops when it comes to the start of a comment.
      If STOP-COMMENT is the symbol ‘syntax-table’, parsing stops after
      the start of a comment or a string, or the end of a comment or a
      string, whichever comes first.
 
      If STATE is ‘nil’, START is assumed to be at the top level of
      parenthesis structure, such as the beginning of a function
      definition.  Alternatively, you might wish to resume parsing in the
      middle of the structure.  To do this, you must provide a STATE
      argument that describes the initial status of parsing.  The value
      returned by a previous call to ‘parse-partial-sexp’ will do nicely.