Source

semantic / semantic-c.el

Diff from to

File semantic-c.el

   `((bovine-toplevel
      ( include)
      ( macro)
-     ( comment)
+     ( type)
      ( function)
      ( variable)
      ( prototype)
-     ( type)
      ( define)
-     ) ; end bovine-toplevel
+     )					; end declaration
     (include
-     ( punctuation "#" symbol "include" punctuation "<" filename punctuation ">"
-		   ,(lambda (vals start end)
-		      (append  (nth 3 vals) (list 'include 't nil)
-			       (list start end))))
-     ( punctuation "#" symbol "include" string
-		   ,(lambda (vals start end)
-		      (append  (list ( read (nth 2 vals)) 'include nil nil)
-			       (list start end))))
-     ) ; end include
+     ( punctuation "\\b#\\b" INCLUDE punctuation "<" filename punctuation ">"
+		   ,(semantic-lambda
+		     (nth 3 vals) (list 'include 't nil)))
+     ( punctuation "\\b#\\b" INCLUDE string
+		   ,(semantic-lambda
+		     (list ( read (nth 2 vals)) 'include nil nil)))
+     )					; end include
     (filename
-     ( symbol punctuation "\\." symbol
-	      ,(lambda (vals start end)
-		 (append  (list ( concat (nth 0 vals) (nth 1 vals) (nth 2 vals)))
-			  (list start end))))
+     ( symbol punctuation "\\b\\.\\b" symbol
+	      ,(semantic-lambda
+		(list ( concat (nth 0 vals) (nth 1 vals) (nth 2 vals)))))
      ( symbol punctuation "/" filename
-	      ,(lambda (vals start end)
-		 (append  (list ( concat (nth 0 vals) (nth 1 vals) ( car (nth 2 vals))))
-			  (list start end))))
-     ) ; end filename
+	      ,(semantic-lambda
+		(list ( concat (nth 0 vals) (nth 1 vals) ( car (nth 2 vals))))))
+     )					; end filename
     (structparts
      ( semantic-list
-       ,(lambda (vals start end)
-	  (append 
-	   (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'structsubparts)
-	   
-	   (list start end))))
-     ) ; end structparts
+       ,(semantic-lambda
+
+	 (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'structsubparts)
+	 ))
+     )					; end structparts
     (structsubparts
      ( variable)
      ( define)
-     ) ; end structsubparts
+     )					; end structsubparts
     (enumparts
      ( semantic-list
-       ,(lambda (vals start end)
-	  (append 
-	   (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'enumsubparts)
-	   
-	   (list start end))))
-     ) ; end enumparts
+       ,(semantic-lambda
+
+	 (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'enumsubparts)
+	 ))
+     )					; end enumparts
     (enumsubparts
      ( symbol opt-assign
-	      ,(lambda (vals start end)
-		 (append  (list (nth 0 vals))
-			  (list start end))))
-     ) ; end enumsubparts
+	      ,(semantic-lambda
+		(list (nth 0 vals))))
+     )					; end enumsubparts
     (opt-name
      ( symbol)
      (
-      ,(lambda (vals start end)
-	 (append  (list nil)
-		  (list start end))))
-     ) ; end opt-name
+      ,(semantic-lambda
+	(list nil)))
+     )					; end opt-name
     (typesimple
-     ( symbol "struct\\|union" opt-name structparts
-	      ,(lambda (vals start end)
-		 (append  (nth 1 vals) (list 'type (nth 0 vals) (nth 2 vals) nil nil nil)
-			  (list start end))))
-     ( symbol "enum" opt-name enumparts
-	      ,(lambda (vals start end)
-		 (append  (nth 1 vals) (list 'type (nth 0 vals) (nth 2 vals) nil nil nil)
-			  (list start end))))
-     ( symbol "typedef" typeform symbol
-	      ,(lambda (vals start end)
-		 (append  (list (nth 2 vals) 'type (nth 0 vals) nil (nth 1 vals) nil nil)
-			  (list start end))))
-     ) ; end typesimple
+     ( STRUCT opt-name structparts
+	      ,(semantic-lambda
+		(nth 1 vals) (list 'type (nth 0 vals) (nth 2 vals) nil nil nil)))
+     ( UNION opt-name structparts
+	     ,(semantic-lambda
+	       (nth 1 vals) (list 'type (nth 0 vals) (nth 2 vals) nil nil nil)))
+     ( ENUM opt-name enumparts
+	    ,(semantic-lambda
+	      (nth 1 vals) (list 'type (nth 0 vals) (nth 2 vals) nil nil nil)))
+     ( TYPEDEF typeform symbol
+	       ,(semantic-lambda
+		 (list (nth 2 vals) 'type (nth 0 vals) nil (nth 1 vals) nil nil)))
+     )					; end typesimple
     (type
-     ( typesimple punctuation ";"
-		  ,(lambda (vals start end)
-		     (append  (nth 0 vals)
-			      (list start end))))
-     ) ; end type
+     ( typesimple punctuation "\\b;\\b"
+		  ,(semantic-lambda
+		    (nth 0 vals)))
+     )					; end type
     (opt-stars
-     ( punctuation "*" opt-stars
-		   ,(lambda (vals start end)
-		      (append  (list ( 1+ ( car (nth 1 vals))))
-			       (list start end))))
+     ( punctuation "\\b\\*\\b" opt-stars
+		   ,(semantic-lambda
+		     (list ( 1+ ( car (nth 1 vals))))))
      (
-      ,(lambda (vals start end)
-	 (append  (list 0)
-		  (list start end))))
-     ) ; end opt-stars
+      ,(semantic-lambda
+	(list 0)))
+     )					; end opt-stars
     (declmods
      ( symbol "\\(_+\\)?\\(extern\\|static\\|const\\|volitile\\|signed\\|unsigned\\)" declmods
-	      ,(lambda (vals start end)
-		 (append  ( cons (nth 0 vals) (nth 1 vals))
-			  (list start end))))
+	      ,(semantic-lambda
+		( cons (nth 0 vals) (nth 1 vals))))
      ( symbol "\\(_+\\)?\\(extern\\|static\\|const\\|volitile\\|signed\\|unsigned\\)"
-	      ,(lambda (vals start end)
-		 (append  (list (nth 0 vals))
-			  (list start end))))
+	      ,(semantic-lambda
+		(list (nth 0 vals))))
      (
-      ,(lambda (vals start end)
-	 (append 
-	  (list start end))))
-     ) ; end declmods
+      ,(semantic-lambda
+	))
+     )					; end declmods
     (typeform
      ( typeformbase opt-stars
-		    ,(lambda (vals start end)
-		       (append  (nth 0 vals)
-				(list start end))))
-     ) ; end typeform
+		    ,(semantic-lambda
+		      (nth 0 vals)))
+     )					; end typeform
     (typeformbase
      ( typesimple
-       ,(lambda (vals start end)
-	  (append  (nth 0 vals)
-		   (list start end))))
-     ( symbol "struct\\|union\\|enum" symbol
-	      ,(lambda (vals start end)
-		 (append  (list (nth 1 vals) 'type (nth 0 vals))
-			  (list start end))))
+       ,(semantic-lambda
+	 (nth 0 vals)))
+     ( STRUCT symbol
+	      ,(semantic-lambda
+		(list (nth 1 vals) 'type (nth 0 vals))))
+     ( UNION symbol
+	     ,(semantic-lambda
+	       (list (nth 1 vals) 'type (nth 0 vals))))
+     ( ENUM symbol
+	    ,(semantic-lambda
+	      (list (nth 1 vals) 'type (nth 0 vals))))
      ( symbol
-       ,(lambda (vals start end)
-	  (append  (list (nth 0 vals))
-		   (list start end))))
-     ) ; end typeformbase
+       ,(semantic-lambda
+	 (list (nth 0 vals))))
+     )					; end typeformbase
     (opt-bits
-     ( punctuation ":" symbol
-		   ,(lambda (vals start end)
-		      (append  (list (nth 1 vals))
-			       (list start end))))
+     ( punctuation "\\b:\\b" symbol
+		   ,(semantic-lambda
+		     (list (nth 1 vals))))
      (
-      ,(lambda (vals start end)
-	 (append  (list nil)
-		  (list start end))))
-     ) ; end opt-bits
+      ,(semantic-lambda
+	(list nil)))
+     )					; end opt-bits
     (opt-array
      ( semantic-list "^\\[.*\\]$" opt-array
-		     ,(lambda (vals start end)
-			(append  (list ( cons 1 ( car (nth 1 vals))))
-				 (list start end))))
+		     ,(semantic-lambda
+		       (list ( cons 1 ( car (nth 1 vals))))))
      (
-      ,(lambda (vals start end)
-	 (append  (list nil)
-		  (list start end))))
-     ) ; end opt-array
+      ,(semantic-lambda
+	(list nil)))
+     )					; end opt-array
     (opt-assign
-     ( punctuation "=" expression
-		   ,(lambda (vals start end)
-		      (append  (list (nth 1 vals))
-			       (list start end))))
+     ( punctuation "\\b=\\b" expression
+		   ,(semantic-lambda
+		     (list (nth 1 vals))))
      (
-      ,(lambda (vals start end)
-	 (append  (list nil)
-		  (list start end))))
-     ) ; end opt-assign
+      ,(semantic-lambda
+	(list nil)))
+     )					; end opt-assign
     (macro
-     ( punctuation "#" symbol "define" symbol opt-expression
-		   ,(lambda (vals start end)
-		      (append  (list (nth 2 vals) 'variable nil 't (nth 3 vals) nil nil)
-			       (list start end))))
-     ) ; end macro
+     ( punctuation "\\b#\\b" DEFINE symbol opt-expression
+		   ,(semantic-lambda
+		     (list (nth 2 vals) 'variable nil 't (nth 3 vals) nil nil)))
+     )					; end macro
     (variable
-     ( variabledef punctuation ";"
-		   ,(lambda (vals start end)
-		      (append  (nth 0 vals)
-			       (list start end))))
-     ) ; end variable
+     ( variabledef punctuation "\\b;\\b"
+		   ,(semantic-lambda
+		     (nth 0 vals)))
+     )					; end variable
     (variabledef
      ( declmods typeform varnamelist
-		,(lambda (vals start end)
-		   (append  (list (nth 2 vals) 'variable (nth 1 vals) ( if (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) nil ( if ( and (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) ( cdr (nth 0 vals)) (nth 0 vals)) nil)
-			    (list start end))))
-     ) ; end variabledef
+		,(semantic-lambda
+		  (list (nth 2 vals) 'variable (nth 1 vals) ( if (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) nil ( if ( and (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) ( cdr (nth 0 vals)) (nth 0 vals)) nil)))
+     )					; end variabledef
     (opt-restrict
-     ( symbol "\\(__\\)?restrict")
+     ( symbol "\\<\\(__\\)?restrict\\>")
      ()
-     ) ; end opt-restrict
+     )					; end opt-restrict
     (varname
      ( opt-stars opt-restrict symbol opt-bits opt-array opt-assign
-		 ,(lambda (vals start end)
-		    (append  (list (nth 2 vals)) (nth 0 vals) (nth 3 vals) (nth 4 vals) (nth 5 vals)
-			     (list start end))))
-     ) ; end varname
+		 ,(semantic-lambda
+		   (list (nth 2 vals)) (nth 0 vals) (nth 3 vals) (nth 4 vals) (nth 5 vals)))
+     )					; end varname
     (variablearg
      ( declmods typeform varname
-		,(lambda (vals start end)
-		   (append  (list ( car (nth 2 vals)) 'variable (nth 1 vals) ( if (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) nil ( if ( and (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) ( cdr (nth 0 vals)) (nth 0 vals)) nil)
-			    (list start end))))
-     ) ; end variablearg
+		,(semantic-lambda
+		  (list ( car (nth 2 vals)) 'variable (nth 1 vals) ( if (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) nil ( if ( and (nth 0 vals) ( string-match "const" ( car (nth 0 vals)))) ( cdr (nth 0 vals)) (nth 0 vals)) nil)))
+     )					; end variablearg
     (varnamelist
-     ( varname punctuation "," varnamelist
-	       ,(lambda (vals start end)
-		  (append  ( cons (nth 0 vals) (nth 2 vals))
-			   (list start end))))
+     ( varname punctuation "\\b,\\b" varnamelist
+	       ,(semantic-lambda
+		 ( cons (nth 0 vals) (nth 2 vals))))
      ( varname
-       ,(lambda (vals start end)
-	  (append  (list (nth 0 vals))
-		   (list start end))))
-     ) ; end varnamelist
+       ,(semantic-lambda
+	 (list (nth 0 vals))))
+     )					; end varnamelist
     (arg-list
-     ( symbol "__P" semantic-list
+     ( symbol "\\<__?P\\>" semantic-list
 	      ,(lambda (vals start end)
-		 
+
 		 (semantic-bovinate-from-nonterminal (car (nth 1 vals)) (cdr (nth 1 vals)) 'arg-list-p)
 		 ))
      ( semantic-list knr-arguments
-		     ,(lambda (vals start end)
-			(append  (nth 1 vals)
-				 (list start end))))
+		     ,(semantic-lambda
+		       (nth 1 vals)))
      ( semantic-list
-       ,(lambda (vals start end)
-	  (append 
-	   (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'arg-sub-list)
-	   
-	   (list start end))))
-     ) ; end arg-list
+       ,(semantic-lambda
+
+	 (semantic-bovinate-from-nonterminal-full (car (nth 0 vals)) (cdr (nth 0 vals)) 'arg-sub-list)
+	 ))
+     )					; end arg-list
     (knr-arguments
-     ( variablearg punctuation ";" knr-arguments
-		   ,(lambda (vals start end)
-		      (append  ( cons (nth 0 vals) (nth 2 vals))
-			       (list start end))))
-     ( variablearg punctuation ";"
-		   ,(lambda (vals start end)
-		      (append  (list (nth 0 vals))
-			       (list start end))))
-     ) ; end knr-arguments
+     ( variablearg punctuation "\\b;\\b" knr-arguments
+		   ,(semantic-lambda
+		     ( cons (nth 0 vals) (nth 2 vals))))
+     ( variablearg punctuation "\\b;\\b"
+		   ,(semantic-lambda
+		     (list (nth 0 vals))))
+     )					; end knr-arguments
     (arg-list-p
      ( open-paren "(" semantic-list close-paren ")"
-		  ,(lambda (vals start end)
-		     (append 
-		      (semantic-bovinate-from-nonterminal-full (car (nth 1 vals)) (cdr (nth 1 vals)) 'arg-sub-list)
-		      
-		      (list start end))))
-     ) ; end arg-list-p
+		  ,(semantic-lambda
+
+		    (semantic-bovinate-from-nonterminal-full (car (nth 1 vals)) (cdr (nth 1 vals)) 'arg-sub-list)
+		    ))
+     )					; end arg-list-p
     (arg-sub-list
      ( variablearg
-       ,(lambda (vals start end)
-	  (append  (nth 0 vals)
-		   (list start end))))
-     ( punctuation "\\." punctuation "\\." punctuation "\\." close-paren ")"
-		   ,(lambda (vals start end)
-		      (append  (list "...")
-			       (list start end))))
-     ) ; end arg-sub-list
+       ,(semantic-lambda
+	 (nth 0 vals)))
+     ( punctuation "\\b\\.\\b" punctuation "\\b\\.\\b" punctuation "\\b\\.\\b" close-paren ")"
+		   ,(semantic-lambda
+		     (list "...")))
+     )					; end arg-sub-list
     (functiondef
      ( declmods typeform symbol arg-list
-		,(lambda (vals start end)
-		   (append  (list (nth 2 vals) 'function (nth 1 vals) (nth 3 vals) (nth 0 vals) nil)
-			    (list start end))))
-     ) ; end functiondef
+		,(semantic-lambda
+		  (list (nth 2 vals) 'function (nth 1 vals) (nth 3 vals) (nth 0 vals) nil)))
+     )					; end functiondef
     (prototype
-     ( functiondef punctuation ";"
-		   ,(lambda (vals start end)
-		      (append  (nth 0 vals)
-			       (list start end))))
-     ) ; end prototype
+     ( functiondef punctuation "\\b;\\b"
+		   ,(semantic-lambda
+		     (nth 0 vals)))
+     )					; end prototype
     (function
      ( functiondef semantic-list
-		   ,(lambda (vals start end)
-		      (append  (nth 0 vals)
-			       (list start end))))
-     ) ; end function
+		   ,(semantic-lambda
+		     (nth 0 vals)))
+     )					; end function
     (opt-expression
      ( expression)
      (
-      ,(lambda (vals start end)
-	 (append  (list nil)
-		  (list start end))))
-     ) ; end opt-expression
+      ,(semantic-lambda
+	(list nil)))
+     )					; end opt-expression
     (expression
      ( symbol
-       ,(lambda (vals start end)
-	  (append  (list nil)
-		   (list start end))))
+       ,(semantic-lambda
+	 (list nil)))
      ( punctuation "[!*&~]" symbol
-		   ,(lambda (vals start end)
-		      (append  (list nil)
-			       (list start end))))
+		   ,(semantic-lambda
+		     (list nil)))
      ( semantic-list
-       ,(lambda (vals start end)
-	  (append  (list nil)
-		   (list start end))))
-     ) ; end expression
+       ,(semantic-lambda
+	 (list nil)))
+     )					; end expression
     )
-"C language specification.")
+  "C language specification.")
 
 (defvar semantic-flex-c-extensions
   '(("^#\\(if\\(def\\)?\\|else\\|endif\\)" . semantic-flex-c-if))
 				      mods
 				      suffix
 				      (semantic-token-docstring nonterm)
-				      (semantic-token-start nonterm)
-				      (semantic-token-end nonterm))
+				      (semantic-token-overlay nonterm))
 				vl))
 		 (setq lst (cdr lst)))
 	       vl))
   :group 'c
   :type '(repeat (string :tag "Type")))
 
+(defvar semantic-c-keyword-table
+  (semantic-flex-make-keyword-table 
+   `( ("include" . INCLUDE)
+      ("define" . DEFINE)
+      ("struct" . STRUCT)
+      ("union" . UNION)
+      ("enum" . ENUM)
+      ("typedef" . TYPEDEF)
+      ))
+  "Some keywords used in C.")
+
 (defun semantic-default-c-setup ()
   "Set up a buffer for semantic parsing of the C language."
-   (setq semantic-toplevel-bovine-table semantic-toplevel-c-bovine-table
-	 semantic-expand-nonterminal 'semantic-expand-c-nonterminal
-	 semantic-flex-extensions semantic-flex-c-extensions
-	 semantic-dependency-include-path semantic-default-c-path
-	 semantic-default-built-in-types semantic-default-c-built-in-types
-	 imenu-create-index-function 'semantic-create-imenu-index
-	 ;; For documentation
-	 document-comment-start "/*"
-	 document-comment-line-prefix " *"
-	 document-comment-end " */"
-	 ))
+  (setq semantic-default-built-in-types semantic-default-c-built-in-types)
+  ;; Code generated from c.bnf
+  (setq semantic-toplevel-bovine-table semantic-toplevel-c-bovine-table)
+  (setq semantic-flex-keywords-obarray semantic-c-keyword-table)
+  (setq semantic-expand-nonterminal 'semantic-expand-c-nonterminal
+	semantic-flex-extensions semantic-flex-c-extensions
+	semantic-dependency-include-path semantic-default-c-path
+	imenu-create-index-function 'semantic-create-imenu-index
+	document-comment-start "/*"
+	document-comment-line-prefix " *"
+	document-comment-end " */"
+	)
+
+ ;; End code generated from c.bnf
+)
 
 (add-hook 'c-mode-hook 'semantic-default-c-setup)