;; This file is to be used with mupad.el where further explanations ;; may be found. See also the file mupad.el-info. ;; Should be accompanied by the file mupad-with-syntax.el. This latter ;; contains an example as to how to write a "translating" file. ;; Created November 22 1998 by Olivier Ramare (ramare@gat.univ-lille1.fr) ;; It contains functions used for writing translating eLisp-modules ;; that translate a program given in a langage into something comprehensible ;; by the MuPAD calculator. ;; Add ;; /*@ (load-file "Name-of-the-translating-file") ;; (setq mupad-input-filter-hook (list 'translate)) */ ;; to the file to translate. 'translate is the translation function. ;; The file has to be currently edited for this command to be taken ;; into account. ;; ;; The first command of 'translate is either ;; (mupad-translate-on-other-file) and the file to be translated ;; will not be changed. ;; (mupad-translate-on-same-file) and the file to be translated ;; will be actually changed. (provide 'mupad-translator) (defun mupad-translate-on-other-file nil "This function contains the command that should be executed to translate a file onto another one. The file to translate is in the currently editted (and set) buffer. The translated file is editted in another buffer which is the selected one at the end of this command." (goto-char (point-min)) (get-buffer-create "*translation*") (save-excursion (set-buffer "*translation*") (erase-buffer)) (copy-to-buffer "*translation*" (point-min) (point-max)) (set-buffer "*translation*") ;; 'mupad-temp-file is a variable of mupad.el: (set-visited-file-name mupad-temp-file t) ;; The preceding function has changed the buffer-name! (rename-buffer "*translation*") ;; To limit the translation to this file: (setq mupad-input-filter-hook nil)) (defun mupad-translate-on-same-file nil "This function contains the command that should be executed to translate a file onto another one. The file to translate is in the currently editted (and set) buffer." (goto-char (point-min)) ;; To limit the translation to this file: (setq mupad-input-filter-hook nil)) ;;-------------------- ;; Expression finders ;;-------------------- ;; mupad.el already contains ;; 'mupad-within-comment ;; 'mupad-within-string ;; 'mupad-find-closing-end_proc (defconst mupad-regexp-identifier "[a-zA-Z_][a-zA-Z_0-9]*" "Regexp to match identifiers in mupad.") (defun mupad-looking-at-identifierp nil "T if point is located at the beginning of a mupad-identifier." (if (looking-at mupad-regexp-identifier) (if (bobp) t (save-excursion (forward-char -1) (looking-at "[^a-zA-Z_0-9]"))) nil)) (defun mupad-looking-at-identifier nil "Return end of identifier if mupad-looking-at-identifier is T, nil otherwise." (if (mupad-looking-at-identifierp) (save-excursion (skip-chars-forward "a-zA-Z_0-9") (point)) nil)) (defun mupad-looking-at-fn-call nil "Return end of fn-call if point is located at the beginning of a fn-call, and nil otherwise." (if (mupad-looking-at-identifierp) (save-excursion (goto-char (mupad-looking-at-identifier)) (if (not (looking-at "[ \t\n]*(")) nil (goto-char (- (match-end 0) 1)) (forward-sexp) ;; Error if expression is unbalanced. (point))) nil)) (defun mupad-skip-comments nil (while (mupad-within-comment) (re-search-forward (concat "$\\|#\\|\\*/" (regexp-quote mupad-exclude-str-end) nil t)) (goto-char (match-end 0)))) (defun mupad-find-fn-def-start nil "Returns beginning of next proc-name definition." (if (re-search-forward mupad-fn-def-start nil t) (goto-char (match-beginning 2)) nil)) ;; mupad-translator.el ends here.