Function: define-lex-block-analyzer
define-lex-block-analyzer is a macro defined in lex.el.gz.
Signature
(define-lex-block-analyzer NAME DOC SPEC1 &rest SPECS)
Documentation
Create a lexical analyzer NAME for paired delimiters blocks.
It detects a paired delimiters block or the corresponding open or
close delimiter depending on the value of the variable
semantic-lex-current-depth. DOC is the documentation string of the lexical
analyzer. SPEC1 and SPECS specify the token symbols and open, close
delimiters used. Each SPEC has the form:
(BLOCK-SYM (OPEN-DELIM OPEN-SYM) (CLOSE-DELIM CLOSE-SYM))
where BLOCK-SYM is the symbol returned in a block token. OPEN-DELIM and CLOSE-DELIM are respectively the open and close delimiters identifying a block. OPEN-SYM and CLOSE-SYM are respectively the symbols returned in open and close tokens.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/lex.el.gz
(defmacro define-lex-block-analyzer (name doc spec1 &rest specs)
"Create a lexical analyzer NAME for paired delimiters blocks.
It detects a paired delimiters block or the corresponding open or
close delimiter depending on the value of the variable
`semantic-lex-current-depth'. DOC is the documentation string of the lexical
analyzer. SPEC1 and SPECS specify the token symbols and open, close
delimiters used. Each SPEC has the form:
\(BLOCK-SYM (OPEN-DELIM OPEN-SYM) (CLOSE-DELIM CLOSE-SYM))
where BLOCK-SYM is the symbol returned in a block token. OPEN-DELIM
and CLOSE-DELIM are respectively the open and close delimiters
identifying a block. OPEN-SYM and CLOSE-SYM are respectively the
symbols returned in open and close tokens."
(declare (debug (&define name stringp form (&rest form)))
(indent 1))
(let ((specs (cons spec1 specs))
spec open olist clist)
(while specs
(setq spec (car specs)
specs (cdr specs)
open (nth 1 spec)
;; build alist ((OPEN-DELIM OPEN-SYM BLOCK-SYM) ...)
olist (cons (list (car open) (cadr open) (car spec)) olist)
;; build alist ((CLOSE-DELIM CLOSE-SYM) ...)
clist (cons (nth 2 spec) clist)))
`(define-lex-analyzer ,name
,doc
(and
(looking-at "\\(\\s(\\|\\s)\\)")
(let ((text (match-string 0)) match)
(cond
((setq match (assoc text ',olist))
(if (or (not semantic-lex-maximum-depth)
(< semantic-lex-current-depth semantic-lex-maximum-depth))
(progn
(setq semantic-lex-current-depth (1+ semantic-lex-current-depth))
(semantic-lex-push-token
(semantic-lex-token
(nth 1 match)
(match-beginning 0) (match-end 0))))
(semantic-lex-push-token
(semantic-lex-token
(nth 2 match)
(match-beginning 0)
(save-excursion
(semantic-lex-unterminated-syntax-protection (nth 2 match)
(forward-list 1)
(point)))
))
))
((setq match (assoc text ',clist))
(if (> semantic-lex-current-depth 0)
(progn
(setq semantic-lex-current-depth (1- semantic-lex-current-depth))
(semantic-lex-push-token
(semantic-lex-token
(nth 1 match)
(match-beginning 0) (match-end 0)))))))))
)))