Function: define-lex-analyzer

define-lex-analyzer is a macro defined in lex.el.gz.

Signature

(define-lex-analyzer NAME DOC CONDITION &rest FORMS)

Documentation

Create a single lexical analyzer NAME with DOC.

When an analyzer is called, the current buffer and point are positioned in a buffer at the location to be analyzed. CONDITION is an expression which returns t if FORMS should be run. Within the bounds of CONDITION and FORMS, the use of backquote can be used to evaluate expressions at compile time. While forms are running, the following variables will be locally bound:
  semantic-lex-analysis-bounds - The bounds of the current analysis.
                  of the form (START . END)
  semantic-lex-maximum-depth - The maximum depth of semantic-list
                  for the current analysis.
  semantic-lex-current-depth - The current depth of semantic-list that has
                  been descended.
  semantic-lex-end-point - End Point after match.
                   Analyzers should set this to a buffer location if their
                   match string does not represent the end of the matched text.
  semantic-lex-token-stream - The token list being collected.
                   Add new lexical tokens to this list.
Proper action in FORMS is to move the value of semantic-lex-end-point to after the location of the analyzed entry, and to add any discovered tokens at the beginning of semantic-lex-token-stream. This can be done by using semantic-lex-push-token.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/lex.el.gz
(defmacro define-lex-analyzer (name doc condition &rest forms)
  "Create a single lexical analyzer NAME with DOC.
When an analyzer is called, the current buffer and point are
positioned in a buffer at the location to be analyzed.
CONDITION is an expression which returns t if FORMS should be run.
Within the bounds of CONDITION and FORMS, the use of backquote
can be used to evaluate expressions at compile time.
While forms are running, the following variables will be locally bound:
  `semantic-lex-analysis-bounds' - The bounds of the current analysis.
                  of the form (START . END)
  `semantic-lex-maximum-depth' - The maximum depth of semantic-list
                  for the current analysis.
  `semantic-lex-current-depth' - The current depth of `semantic-list' that has
                  been descended.
  `semantic-lex-end-point' - End Point after match.
                   Analyzers should set this to a buffer location if their
                   match string does not represent the end of the matched text.
  `semantic-lex-token-stream' - The token list being collected.
                   Add new lexical tokens to this list.
Proper action in FORMS is to move the value of `semantic-lex-end-point' to
after the location of the analyzed entry, and to add any discovered tokens
at the beginning of `semantic-lex-token-stream'.
This can be done by using `semantic-lex-push-token'."
  (declare (debug (&define name stringp form def-body)) (indent 1))
  `(eval-and-compile
     ;; This is the real info used by `define-lex' (via semantic-lex-one-token).
     (defconst ,name '(,condition ,@forms) ,doc)
     ;; Build a single lexical analyzer function, so the doc for
     ;; function help is automatically provided, and perhaps the
     ;; function could be useful for testing and debugging one
     ;; analyzer.
     (defun ,name ()
       ,doc
       (let ((semantic-lex-token-stream nil)
	     (semantic-lex-end-point (point))
	     (semantic-lex-analysis-bounds (cons (point) (point-max)))
	     (semantic-lex-current-depth 0)
	     (semantic-lex-maximum-depth semantic-lex-depth))
	 (when ,condition nil ,@forms)  ; `nil' avoids an empty-body warning.
	 semantic-lex-token-stream))))