semantic / semantic-scm.el

andyp 52135bf 

andyp d7c5549 
andyp 52135bf 

andyp d7c5549 
andyp 52135bf 

andyp d7c5549 
andyp 52135bf 

;;; semantic-scm.el --- Semantic details for Scheme (guile)

;;; Copyright (C) 2001 Eric M. Ludlam

;; Author: Eric M. Ludlam <>
;; X-RCS: $Id$

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:
;; Use the Semantic Bovinator for Scheme (guile)

(require 'semantic)
(require 'backquote)

  (require 'document))

;;; Code:
(defvar semantic-toplevel-scheme-bovine-table
 ( semantic-list
 ,(lambda (vals start end)
 (semantic-bovinate-from-nonterminal (car (nth 0 vals)) (cdr (nth 0 vals)) 'scheme-list)
 ) ; end scheme
 ( open-paren "(" scheme-in-list
  (nth 1 vals)))
 ) ; end scheme-list
 ( DEFINE symbol expression
  (list (nth 1 vals) 'variable nil (nth 2 vals) nil)))
 ( DEFINE name-args opt-doc
  (list ( car (nth 1 vals)) 'function ( cdr (nth 1 vals)) nil) (nth 2 vals)))
 ( DEFINE-MODULE name-args
  (list ( nth ( length (nth 1 vals)) (nth 1 vals)) 'provide nil)))
 ( LOAD string
  (list ( file-name-nondirectory ( read (nth 1 vals))) 'require ( read (nth 1 vals)))))
 ( symbol
  (list (nth 0 vals) 'code)))
 ) ; end scheme-in-list
 ( semantic-list
 ,(lambda (vals start end)
 (semantic-bovinate-from-nonterminal (car (nth 0 vals)) (cdr (nth 0 vals)) 'name-arg-expand)
 ) ; end name-args
 ( open-paren name-arg-expand
  (nth 1 vals)))
 ( symbol name-arg-expand
  ( cons (nth 0 vals) (nth 1 vals))))
 ) ; end name-arg-expand
 ( string)
 ) ; end opt-doc
 ( symbol)
 ( semantic-list)
 ( string)
 ) ; end expression
 "Top level bovination table for scheme.")

(defvar semantic-scheme-keyword-table
   `( ("define" . DEFINE)
      ("define-module" . DEFINE-MODULE)
      ("load" . LOAD)
     ("define" summary "Function: (define symbol expression)")
     ("define-module" summary "Function: (define-module (name arg1 ...)) ")
     ("load" summary "Function: (load \"filename\")")
  "Some keywords used in scheme.")

(defcustom semantic-default-scheme-path '("/usr/share/guile/")
  "Default set of include paths for scheme (guile) code.
Used by `semantic-inc' to define an include path.  This should
probably do some sort of search to see what is actually on the local
  :group 'scheme
  :type '(repeat (string :tag "Path")))

(defun semantic-scheme-prototype-nonterminal (token)
  "Return a prototype for the Emacs Lisp nonterminal TOKEN."
  (let* ((tok (semantic-token-token token))
	 (args (semantic-nonterminal-children token))
    (if (eq tok 'function)
	(concat (semantic-token-name token) " ("
		(mapconcat (lambda (a) a) args " ")
      (semantic-prototype-nonterminal-default token))))

(defun semantic-scheme-find-documentation (token &optional nosnarf)
  "Return the documentation string for TOKEN.
Optional argument NOSNARF is ignored."
  (let ((d (semantic-token-docstring token)))
    (if (and d (> (length d) 0) (= (aref d 0) ?*))
	(substring d 1)

(defun semantic-scheme-insert-foreign-token (token tokenfile)
  "Insert TOKEN from TOKENFILE at point.
Attempts a simple prototype for calling or using TOKEN."
  (cond ((eq (semantic-token-token token) 'function)
	 (insert "(" (semantic-token-name token) " )")
	 (forward-char -1))
	 (insert (semantic-token-name token)))))

(defun semantic-default-scheme-setup ()
  "Setup hook function for Emacs Lisp files and Semantic."
 ;; Code generated from scheme.bnf
  (setq semantic-toplevel-bovine-table semantic-toplevel-scheme-bovine-table
	semantic-toplevel-bovine-table-source "scheme.bnf")
  (setq semantic-flex-keywords-obarray semantic-scheme-keyword-table)
  (setq semantic-symbol->name-assoc-list '( (variable . "Variables")
					    ;;(type     . "Types")
					    (function . "Functions")
					    (include  . "Loads")
					    (package  . "DefinModule"))
	semantic-number-expression nil
	imenu-create-index-function 'semantic-create-imenu-index
	semantic-dependency-include-path semantic-default-scheme-path
	imenu-create-index-function 'semantic-create-imenu-index
	document-comment-start ";;"
	document-comment-line-prefix ";;"
	document-comment-end "\n"
 ;; End code generated from scheme.bnf

(add-hook 'scheme-mode-hook 'semantic-default-scheme-setup)

(provide 'semantic-scm)

;;; semantic-scm.el ends here