Function: define-lex
define-lex is a macro defined in lex.el.gz.
Signature
(define-lex NAME DOC &rest ANALYZERS)
Documentation
Create a new lexical analyzer with NAME.
DOC is a documentation string describing this analyzer.
ANALYZERS are small code snippets of analyzers to use when
building the new NAMED analyzer. Only use analyzers which
are written to be used in define-lex.
Each analyzer should be an analyzer created with define-lex-analyzer.
Note: The order in which analyzers are listed is important.
If two analyzers can match the same text, it is important to order the
analyzers so that the one you want to match first occurs first. For
example, it is good to put a number analyzer in front of a symbol
analyzer which might mistake a number for a symbol.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/lex.el.gz
(defmacro define-lex (name doc &rest analyzers)
"Create a new lexical analyzer with NAME.
DOC is a documentation string describing this analyzer.
ANALYZERS are small code snippets of analyzers to use when
building the new NAMED analyzer. Only use analyzers which
are written to be used in `define-lex'.
Each analyzer should be an analyzer created with `define-lex-analyzer'.
Note: The order in which analyzers are listed is important.
If two analyzers can match the same text, it is important to order the
analyzers so that the one you want to match first occurs first. For
example, it is good to put a number analyzer in front of a symbol
analyzer which might mistake a number for a symbol."
(declare (debug (&define name stringp (&rest symbolp))))
`(defun ,name (start end &optional depth length)
,(concat doc "\nSee `semantic-lex' for more information.")
;; Make sure the state of block parsing starts over.
(setq semantic-lex-block-streams nil)
;; Allow specialty reset items.
(run-hook-with-args 'semantic-lex-reset-functions start end)
;; Lexing state.
(let* (;(starttime (current-time))
(starting-position (point))
(semantic-lex-token-stream nil)
(semantic-lex-block-stack nil)
(tmp-start start)
(semantic-lex-end-point start)
(semantic-lex-current-depth 0)
;; Use the default depth when not specified.
(semantic-lex-maximum-depth
(or depth semantic-lex-depth))
;; Bounds needed for unterminated syntax
(semantic-lex-analysis-bounds (cons start end))
;; This entry prevents text properties from
;; confusing our lexical analysis. See Emacs 22 (CVS)
;; version of C++ mode with template hack text properties.
(parse-sexp-lookup-properties nil)
)
;; Maybe REMOVE THIS LATER.
;; Trying to find incremental parser bug.
(when (> end (point-max))
(error ,(format "%s: end (%%d) > point-max (%%d)" name)
end (point-max)))
(with-syntax-table semantic-lex-syntax-table
(goto-char start)
(while (and (< (point) end)
(or (not length)
(<= (length semantic-lex-token-stream) length)))
(semantic-lex-one-token ,analyzers)
(when (eq semantic-lex-end-point tmp-start)
(error ,(format "%s: endless loop at %%d, after %%S" name)
tmp-start (car semantic-lex-token-stream)))
(setq tmp-start semantic-lex-end-point)
(goto-char semantic-lex-end-point)
;;(when (> (semantic-elapsed-time starttime nil)
;; semantic-lex-timeout)
;; (error "Timeout during lex at char %d" (point)))
(semantic-throw-on-input 'lex)
(semantic-lex-debug-break (car semantic-lex-token-stream))
))
;; Check that there is no unterminated block.
(when semantic-lex-block-stack
(let* ((last (pop semantic-lex-block-stack))
(blk last))
(while blk
(message
,(format "%s: `%%s' block from %%S is unterminated" name)
(car blk) (cadr blk))
(setq blk (pop semantic-lex-block-stack)))
(semantic-lex-unterminated-syntax-detected (car last))))
;; Return to where we started.
;; Do not wrap in protective stuff so that if there is an error
;; thrown, the user knows where.
(goto-char starting-position)
;; Return the token stream
(nreverse semantic-lex-token-stream))))