Spelling fixes.
[bpt/emacs.git] / lisp / cedet / semantic / lex.el
index c4335d9..dab5c44 100644 (file)
@@ -1,7 +1,6 @@
-;;; lex.el --- Lexical Analyzer builder
+;;; semantic/lex.el --- Lexical Analyzer builder
 
-;;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;;; 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2011  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 
 ;; the lexical analysis.
 ;;
 ;; In the lexical analyzer created with `define-lex', each condition
-;; is tested for a given point.  When the conditin is true, the forms
+;; is tested for a given point.  When the condition is true, the forms
 ;; run.
 ;;
 ;; The forms can push a lexical token onto the token stream.  The
 ;; analyzer forms also must move the current analyzer point.  If the
-;; analyzer point is moved without pushing a token, then tne matched
+;; analyzer point is moved without pushing a token, then the matched
 ;; syntax is effectively ignored, or skipped.
 ;;
 ;; Thus, starting at the beginning of a region to be analyzed, each
@@ -61,7 +60,7 @@
 ;;
 ;; The `define-lex' macro accepts a list of lexical analyzers.  Each
 ;; analyzer is created with `define-lex-analyzer', or one of the
-;; derivitive macros.  A single analyzer defines a regular expression
+;; derivative macros.  A single analyzer defines a regular expression
 ;; to match text in a buffer, and a short segment of code to create
 ;; one lexical token.
 ;;
 ;;           Keywords are used by `semantic-lex-symbol-or-keyword'
 ;;           to create lexical tokens based on the keyword.
 ;;
-;;   Lexical type table - A table of symbols declared in a grammer
+;;   Lexical type table - A table of symbols declared in a grammar
 ;;           file with the %type declaration.
 ;;           The grammar compiler uses the type table to create new
 ;;           lexical analyzers.  These analyzers are then used to when
 ;;
 ;; A lexical type defines a kind of lexical analyzer that will be
 ;; automatically generated from a grammar file based on some
-;; predetermined attributes. For now these two attributes are
+;; predetermined attributes.  For now these two attributes are
 ;; recognized :
 ;;
-;; * matchdatatype : define the kind of lexical analyzer. That is :
+;; * matchdatatype : define the kind of lexical analyzer.  That is :
 ;;
 ;;   - regexp : define a regexp analyzer (see
 ;;     `define-lex-regex-type-analyzer')
 ;;     `define-lex-keyword-type-analyzer')
 ;;
 ;; * syntax : define the syntax that matches a syntactic
-;;   expression. When syntax is matched the corresponding type
+;;   expression.  When syntax is matched the corresponding type
 ;;   analyzer is entered and the resulting match data will be
 ;;   interpreted based on the kind of analyzer (see matchdatatype
 ;;   above).
 ;;
 ;; %type  <punctuation> syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
 ;;
-;; ;; Some punctuations based on the type defines above
+;; ;; Some punctuation based on the type defines above
 ;;
 ;; %token <punctuation> NOT         "!"
 ;; %token <punctuation> NOTEQ       "!="
 ;; eliminate unneeded if statements to speed the lexer.
 
 (require 'semantic/fw)
+
 ;;; Code:
 
-;;; Compatibility
-;;
-(eval-and-compile
-  (if (not (fboundp 'with-syntax-table))
-
-;; Copied from Emacs 21 for compatibility with released Emacses.
-(defmacro with-syntax-table (table &rest body)
-  "With syntax table of current buffer set to a copy of TABLE, evaluate BODY.
-The syntax table of the current buffer is saved, BODY is evaluated, and the
-saved table is restored, even in case of an abnormal exit.
-Value is what BODY returns."
-  (let ((old-table (make-symbol "table"))
-       (old-buffer (make-symbol "buffer")))
-    `(let ((,old-table (syntax-table))
-          (,old-buffer (current-buffer)))
-       (unwind-protect
-          (progn
-            (set-syntax-table (copy-syntax-table ,table))
-            ,@body)
-        (save-current-buffer
-          (set-buffer ,old-buffer)
-          (set-syntax-table ,old-table))))))
-
-))
-\f
 ;;; Semantic 2.x lexical analysis
 ;;
 (defun semantic-lex-map-symbols (fun table &optional property)
@@ -516,7 +491,7 @@ For compatibility with Semantic 1.x it defaults to `semantic-flex'.")
     (symbol)
     (whitespace)
     )
-  "An alist of of semantic token types.
+  "An alist of semantic token types.
 As of December 2001 (semantic 1.4beta13), this variable is not used in
 any code.  The only use is to refer to the doc-string from elsewhere.
 
@@ -600,7 +575,7 @@ See also `semantic-lex-syntax-modifications'.")
 (defvar semantic-lex-comment-regex nil
   "Regular expression for identifying comment start during lexical analysis.
 This may be automatically set when semantic initializes in a mode, but
-may need to be overriden for some special languages.")
+may need to be overridden for some special languages.")
 (make-variable-buffer-local 'semantic-lex-comment-regex)
 
 (defvar semantic-lex-number-expression
@@ -693,38 +668,6 @@ If universal argument ARG, then try the whole buffer."
     (goto-char (point-min))
     ))
 
-(defun semantic-lex-test-full-depth (arg)
-  "Test the semantic lexer in the current buffer parsing through lists.
-Usually the lexer parses
-If universal argument ARG, then try the whole buffer."
-  (interactive "P")
-  (let* ((start (current-time))
-        (result (semantic-lex
-                 (if arg (point-min) (point))
-                 (point-max)
-                 100))
-        (end (current-time)))
-    (message "Elapsed Time: %.2f seconds."
-            (semantic-elapsed-time start end))
-    (pop-to-buffer "*Lexer Output*")
-    (require 'pp)
-    (erase-buffer)
-    (insert (pp-to-string result))
-    (goto-char (point-min))
-    ))
-
-(defun semantic-lex-test-region (beg end)
-  "Test the semantic lexer in the current buffer.
-Analyze the area between BEG and END."
-  (interactive "r")
-  (let ((result (semantic-lex beg end)))
-    (pop-to-buffer "*Lexer Output*")
-    (require 'pp)
-    (erase-buffer)
-    (insert (pp-to-string result))
-    (goto-char (point-min))
-    ))
-
 (defvar semantic-lex-debug nil
   "When non-nil, debug the local lexical analyzer.")
 
@@ -786,7 +729,7 @@ Argument ANALYZERS is the list of analyzers being used."
   "The current depth as tracked through lexical functions.")
 
 (defvar semantic-lex-maximum-depth nil
-  "The maximum depth of parenthisis as tracked through lexical functions.")
+  "The maximum depth of parenthesis as tracked through lexical functions.")
 
 (defvar semantic-lex-token-stream nil
   "The current token stream we are collecting.")
@@ -801,9 +744,10 @@ start position of the block, and STREAM is the list of tokens in that
 block.")
 
 (defvar semantic-lex-reset-hooks nil
-  "List of hooks major-modes use to reset lexical analyzers.
-Hooks are called with START and END values for the current lexical pass.
-Should be set with `add-hook'specifying a LOCAL option.")
+  "Abnormal hook used by major-modes to reset lexical analyzers.
+Hook functions are called with START and END values for the
+current lexical pass.  Should be set with `add-hook', specifying
+a LOCAL option.")
 
 ;; Stack of nested blocks.
 (defvar semantic-lex-block-stack nil)
@@ -820,7 +764,7 @@ 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 numbe analyzer in front of a symbol
+example, it is good to put a number analyzer in front of a symbol
 analyzer which might mistake a number for as a symbol."
   `(defun ,name  (start end &optional depth length)
      ,(concat doc "\nSee `semantic-lex' for more information.")
@@ -952,10 +896,10 @@ The collapsed tokens are saved in `semantic-lex-block-streams'."
   "Create a lexical token.
 SYMBOL is a symbol representing the class of syntax found.
 START and END define the bounds of the token in the current buffer.
-Optional STR is the string for the token iff the the bounds
-in the buffer do not cover the string they represent.  (As from
+Optional STR is the string for the token only if the bounds in
+the buffer do not cover the string they represent.  (As from
 macro expansion.)"
-  ;; This if statement checks the existance of a STR argument at
+  ;; This if statement checks the existence of a STR argument at
   ;; compile time, where STR is some symbol or constant.  If the
   ;; variable STr (runtime) is nil, this will make an incorrect decision.
   ;;
@@ -1121,7 +1065,7 @@ Only in effect if `debug-on-error' is also non-nil."
   "For SYNTAX, execute FORMS with protection for unterminated syntax.
 If FORMS throws an error, treat this as a syntax problem, and
 execute the unterminated syntax code.  FORMS should return a position.
-Irreguardless of an error, the cursor should be moved to the end of
+Irregardless of an error, the cursor should be moved to the end of
 the desired syntax, and a position returned.
 If `debug-on-error' is set, errors are not caught, so that you can
 debug them.
@@ -1148,7 +1092,7 @@ While forms are running, the following variables will be locally bound:
   `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 decended.
+                  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.
@@ -1304,7 +1248,7 @@ they are comment end characters) AND when you want whitespace tokens."
   (if (eq (semantic-lex-token-class (car semantic-lex-token-stream))
          'whitespace)
       ;; Merge whitespace tokens together if they are adjacent.  Two
-      ;; whitespace tokens may be sperated by a comment which is not in
+      ;; whitespace tokens may be separated by a comment which is not in
       ;; the token stream.
       (setcdr (semantic-lex-token-bounds (car semantic-lex-token-stream))
               (match-end 0))
@@ -1327,7 +1271,7 @@ they are comment end characters)."
   (if (eq (semantic-lex-token-class (car semantic-lex-token-stream))
          'whitespace)
       ;; Merge whitespace tokens together if they are adjacent.  Two
-      ;; whitespace tokens may be sperated by a comment which is not in
+      ;; whitespace tokens may be separated by a comment which is not in
       ;; the token stream.
       (progn
         (setq semantic-lex-end-point (match-end 0))
@@ -1369,7 +1313,7 @@ and number formats."
 
 (define-lex-analyzer semantic-lex-punctuation-type
   "Detect and create a punctuation type token.
-Recognized punctuations are defined in the current table of lexical
+Recognized punctuation is defined in the current table of lexical
 types, as the value of the `punctuation' token type."
   (and (looking-at "\\(\\s.\\|\\s$\\|\\s'\\)+")
        (let* ((key (match-string 0))
@@ -1418,11 +1362,11 @@ Return either a paren token or a semantic list token depending on
     ))
 
 (define-lex-simple-regex-analyzer semantic-lex-open-paren
-  "Detect and create an open parenthisis token."
+  "Detect and create an open parenthesis token."
   "\\s(" 'open-paren 0  (setq semantic-lex-current-depth (1+ semantic-lex-current-depth)))
 
 (define-lex-simple-regex-analyzer semantic-lex-close-paren
-  "Detect and create a close paren token."
+  "Detect and create a close parenthesis token."
   "\\s)" 'close-paren 0 (setq semantic-lex-current-depth (1- semantic-lex-current-depth)))
 
 (define-lex-regex-analyzer semantic-lex-string
@@ -1482,10 +1426,7 @@ Return either a paren token or a semantic list token depending on
        ;; to work properly.  Lets try and move over
        ;; whatever white space we matched to begin
        ;; with.
-       (skip-syntax-forward "-.'"
-                            (save-excursion
-                              (end-of-line)
-                              (point)))
+       (skip-syntax-forward "-.'" (point-at-eol))
       ;; We may need to back up so newlines or whitespace is generated.
       (if (bolp)
          (backward-char 1)))
@@ -1496,7 +1437,7 @@ Return either a paren token or a semantic list token depending on
 ;;; Comment lexer
 ;;
 ;; Predefined lexers that could be used instead of creating new
-;; analyers.
+;; analyzers.
 
 (define-lex semantic-comment-lexer
   "A simple lexical analyzer that handles comments.
@@ -1736,7 +1677,7 @@ When the lexer encounters the open-paren delimiter \"(\":
 ;;; Lexical Safety
 ;;
 ;; The semantic lexers, unlike other lexers, can throw errors on
-;; unbalanced syntax.  Since editing is all about changeging test
+;; unbalanced syntax.  Since editing is all about changing text
 ;; we need to provide a convenient way to protect against syntactic
 ;; inequalities.
 
@@ -1807,17 +1748,17 @@ If there is no error, then the last value of FORMS is returned."
 ;;
 ;; NOTE: DELETE THIS SOMEDAY SOON
 
-(semantic-alias-obsolete 'semantic-flex-start 'semantic-lex-token-start)
-(semantic-alias-obsolete 'semantic-flex-end 'semantic-lex-token-end)
-(semantic-alias-obsolete 'semantic-flex-text 'semantic-lex-token-text)
-(semantic-alias-obsolete 'semantic-flex-make-keyword-table 'semantic-lex-make-keyword-table)
-(semantic-alias-obsolete 'semantic-flex-keyword-p 'semantic-lex-keyword-p)
-(semantic-alias-obsolete 'semantic-flex-keyword-put 'semantic-lex-keyword-put)
-(semantic-alias-obsolete 'semantic-flex-keyword-get 'semantic-lex-keyword-get)
-(semantic-alias-obsolete 'semantic-flex-map-keywords 'semantic-lex-map-keywords)
-(semantic-alias-obsolete 'semantic-flex-keywords 'semantic-lex-keywords)
-(semantic-alias-obsolete 'semantic-flex-buffer 'semantic-lex-buffer)
-(semantic-alias-obsolete 'semantic-flex-list   'semantic-lex-list)
+(semantic-alias-obsolete 'semantic-flex-start 'semantic-lex-token-start "23.2")
+(semantic-alias-obsolete 'semantic-flex-end 'semantic-lex-token-end "23.2")
+(semantic-alias-obsolete 'semantic-flex-text 'semantic-lex-token-text "23.2")
+(semantic-alias-obsolete 'semantic-flex-make-keyword-table 'semantic-lex-make-keyword-table "23.2")
+(semantic-alias-obsolete 'semantic-flex-keyword-p 'semantic-lex-keyword-p "23.2")
+(semantic-alias-obsolete 'semantic-flex-keyword-put 'semantic-lex-keyword-put "23.2")
+(semantic-alias-obsolete 'semantic-flex-keyword-get 'semantic-lex-keyword-get "23.2")
+(semantic-alias-obsolete 'semantic-flex-map-keywords 'semantic-lex-map-keywords "23.2")
+(semantic-alias-obsolete 'semantic-flex-keywords 'semantic-lex-keywords "23.2")
+(semantic-alias-obsolete 'semantic-flex-buffer 'semantic-lex-buffer "23.2")
+(semantic-alias-obsolete 'semantic-flex-list 'semantic-lex-list "23.2")
 
 ;; This simple scanner uses the syntax table to generate a stream of
 ;; simple tokens of the form:
@@ -1828,7 +1769,7 @@ If there is no error, then the last value of FORMS is returned."
 ;; objects boundary.
 
 (defvar semantic-flex-tokens semantic-lex-tokens
-  "An alist of of semantic token types.
+  "An alist of semantic token types.
 See variable `semantic-lex-tokens'.")
 
 (defvar semantic-flex-unterminated-syntax-end-function
@@ -1865,8 +1806,8 @@ what syntax class CHAR has.")
 
 (defvar semantic-ignore-comments t
   "Default comment handling.
-t means to strip comments when flexing.  Nil means to keep comments
-as part of the token stream.")
+The value t means to strip comments when flexing; nil means
+to keep comments as part of the token stream.")
 (make-variable-buffer-local 'semantic-ignore-comments)
 
 (defvar semantic-flex-enable-newlines nil
@@ -2052,10 +1993,7 @@ return LENGTH tokens."
                     ;; to work properly.  Lets try and move over
                     ;; whatever white space we matched to begin
                     ;; with.
-                    (skip-syntax-forward "-.'"
-                                         (save-excursion
-                                           (end-of-line)
-                                           (point)))
+                    (skip-syntax-forward "-.'" (point-at-eol))
                   ;;(forward-comment 1)
                   ;; Generate newline token if enabled
                   (if (and semantic-flex-enable-newlines
@@ -2101,8 +2039,7 @@ return LENGTH tokens."
 
 ;; Local variables:
 ;; generated-autoload-file: "loaddefs.el"
-;; generated-autoload-feature: semantic/loaddefs
 ;; generated-autoload-load-name: "semantic/lex"
 ;; End:
 
-;;; semantic-lex.el ends here
+;;; semantic/lex.el ends here