Function: semantic-lex-end-block

semantic-lex-end-block is a byte-compiled function defined in lex.el.gz.

Signature

(semantic-lex-end-block SYNTAX)

Documentation

Process the end of a previously marked SYNTAX block.

That is, collapse the tokens inside that block, including the beginning and end of block tokens, into a high level block token of class SYNTAX. The token at beginning of block is the one marked by a previous call to semantic-lex-start-block. The current token is the end of block. The collapsed tokens are saved in semantic-lex-block-streams.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/lex.el.gz
(defun semantic-lex-end-block (syntax)
  "Process the end of a previously marked SYNTAX block.
That is, collapse the tokens inside that block, including the
beginning and end of block tokens, into a high level block token of
class SYNTAX.
The token at beginning of block is the one marked by a previous call
to `semantic-lex-start-block'.  The current token is the end of block.
The collapsed tokens are saved in `semantic-lex-block-streams'."
  (if (null semantic-lex-block-stack)
      (setq semantic-lex-current-depth (1- semantic-lex-current-depth))
    (let* ((stream semantic-lex-token-stream)
           (blk (pop semantic-lex-block-stack))
           (bstream (cdr blk))
           (first (car bstream))
           (last (pop stream)) ;; The current token mark the EOBLK
           tok)
      (if (not (eq (car blk) syntax))
          ;; SYNTAX doesn't match the syntax of the current block in
          ;; the stack. So we encountered the end of the SYNTAX block
          ;; before the end of the current one in the stack which is
          ;; signaled unterminated.
          (semantic-lex-unterminated-syntax-detected (car blk))
        ;; Move tokens found inside the block from the main stream
        ;; into a separate block stream.
        (while (and stream (not (eq (setq tok (pop stream)) first)))
          (push tok bstream))
        ;; The token marked as beginning of block was not encountered.
        ;; This should not happen!
        (or (eq tok first)
            (error "Token %S not found at beginning of block `%s'"
                   first syntax))
        ;; Save the block stream for future reuse, to avoid to redo
        ;; the lexical analysis of the block content!
        ;; Anchor the block stream with its start position, so we can
        ;; use: (cdr (assq start semantic-lex-block-streams)) to
        ;; quickly retrieve the lexical stream associated to a block.
        (setcar blk (semantic-lex-token-start first))
        (setcdr blk (nreverse bstream))
        (push blk semantic-lex-block-streams)
        ;; In the main stream, replace the tokens inside the block by
        ;; a high level block token of class SYNTAX.
        (setq semantic-lex-token-stream stream)
        (semantic-lex-push-token
         (semantic-lex-token
          syntax (car blk) (semantic-lex-token-end last)))
        ))))