[BACK]Return to pari-translator.el CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / pari-2.2 / emacs

Annotation of OpenXM_contrib/pari-2.2/emacs/pari-translator.el, Revision 1.1.1.1

1.1       noro        1: ;; This file is to be used with pari.el where further explanations
                      2: ;; may be found. See also the file pariemacs.txt.
                      3: ;; Should be accompanied by the file with-syntax.el. This latter
                      4: ;; contains an example as to how to write a "translating" file.
                      5:
                      6: ;; Created November 22 1998 by Olivier Ramare (ramare@gat.univ-lille1.fr)
                      7:
                      8: ;; It contains functions used for writing translating eLisp-modules
                      9: ;; that translate a program given in a langage into something comprehensible
                     10: ;; by the gp calculator.
                     11:
                     12: ;; Add
                     13: ;; /*@ (load-file "Name-of-the-translating-file")
                     14: ;;     (setq gp-input-filter-hook (list 'translate)) */
                     15: ;; to the file to translate. 'translate is the translation function.
                     16: ;; The file has to be currently edited for this command to be taken
                     17: ;; into account.
                     18: ;;
                     19: ;; The first command of 'translate is either
                     20: ;;    (gp-translate-on-other-file) and the file to be translated
                     21: ;;                                 will not be changed.
                     22: ;;    (gp-translate-on-same-file) and the file to be translated
                     23: ;;                                will be actually changed.
                     24:
                     25: (provide 'pari-translator)
                     26:
                     27: (defun gp-translate-on-other-file nil
                     28:   "This function contains the command that should be executed
                     29: to translate a file onto another one. The file to translate is in the
                     30: currently editted (and set) buffer. The translated file is editted in
                     31: another buffer which is the selected one at the end of this command."
                     32:
                     33:   (goto-char (point-min))
                     34:   (get-buffer-create "*translation*")
                     35:   (save-excursion (set-buffer "*translation*") (erase-buffer))
                     36:   (copy-to-buffer "*translation*" (point-min) (point-max))
                     37:   (set-buffer "*translation*")
                     38:   ;; 'gp-temp-file is a variable of pari.el:
                     39:   (set-visited-file-name gp-temp-file t)
                     40:   ;; The preceding function has changed the buffer-name!
                     41:   (rename-buffer "*translation*")
                     42:
                     43:   ;; To limit the translation to this file:
                     44:   (setq gp-input-filter-hook nil))
                     45:
                     46: (defun gp-translate-on-same-file nil
                     47:   "This function contains the command that should be executed
                     48: to translate a file onto another one. The file to translate is in the
                     49: currently editted (and set) buffer."
                     50:
                     51:   (goto-char (point-min))
                     52:
                     53:   ;; To limit the translation to this file:
                     54:   (setq gp-input-filter-hook nil))
                     55:
                     56:
                     57: ;;--------------------
                     58: ;; Expression finders
                     59: ;;--------------------
                     60:
                     61: ;; An inner full expression in gp is one of these two:
                     62: ;; fn-call :: identifier(...matching-)
                     63: ;; identifier
                     64: ;; preceded and followed by any number of comments, spaces, newline
                     65: ;; or tabulation-character.
                     66: ;; Its end delimitation is "," or ";" or "}"
                     67: ;; Thus, we do not detect full expression located at the end of
                     68: ;; a one line function definition, not surrounded by "{}",
                     69: ;; not followed by ";"
                     70:
                     71: ;; pari.el already contains 'gp-find-comment, 'gp-find-global-var
                     72: ;; and 'gp-search-forward-string-delimiter.
                     73:
                     74: (defconst gp-regexp-identifier  "[a-zA-Z_][a-zA-Z_0-9]*"
                     75: "Regexp to match identifiers in gp.")
                     76:
                     77: (defconst gp-regexp-comment "\\\\\\\\$\\|/\\*\\([^\\*]\\|\\*[^/]\\)*\\*/"
                     78: "Regexp to match comments in gp")
                     79:
                     80: (defun gp-looking-at-identifierp nil
                     81: "T if point is located at the beginning of a gp-identifier."
                     82:   (if (looking-at gp-regexp-identifier)
                     83:       (if (bobp)
                     84:           t
                     85:           (save-excursion
                     86:             (forward-char -1)
                     87:             (looking-at "[^a-zA-Z_0-9]")))
                     88:       nil))
                     89:
                     90: (defun gp-looking-at-identifier nil
                     91: "Return end of identifier if gp-looking-at-identifier is T,
                     92: nil otherwise."
                     93:   (if (gp-looking-at-identifierp)
                     94:       (save-excursion (skip-chars-forward "a-zA-Z_0-9") (point))
                     95:       nil))
                     96:
                     97: (defun gp-looking-at-fn-call nil
                     98: "Return end of fn-call if point is located at the beginning of a
                     99: fn-call, and nil otherwise."
                    100:   (if (gp-looking-at-identifierp)
                    101:       (save-excursion
                    102:         (goto-char (gp-looking-at-identifier))
                    103:         (if (not (looking-at "[ \t\n\\\\]*("))
                    104:             nil
                    105:             (goto-char (- (match-end 0) 1))
                    106:             (forward-sexp)  ;; Error if expression is unbalanced.
                    107:             (point)))
                    108:       nil))
                    109:
                    110: (defun gp-skip-comments nil
                    111:   (while (looking-at gp-regexp-comment)
                    112:          (goto-char (match-end 0))))
                    113:
                    114: (defun gp-looking-at-term nil
                    115: "Return end of term if point is located at the beginning of a
                    116: fn-call, and nil otherwise.
                    117:   A `term' is either an identifier, either a fn-call, surrounded by
                    118: any number of parenthesis/space/newline/tab-char/backslash. It may
                    119: also start by a comment."
                    120:   (gp-skip-comments)
                    121:   (if (looking-at "[ \t\n\\\\]*(")
                    122:       (let ((p-end (save-excursion
                    123:                      (forward-sexp)
                    124:                      (gp-skip-comments)
                    125:                      (point))))
                    126:            (forward-char 1)
                    127:            (if (gp-looking-at-term) p-end nil))
                    128:       (let ((p-end (gp-looking-at-fn-call)))
                    129:            (if p-end p-end
                    130:                (if (gp-looking-at-identifierp)
                    131:                    (gp-looking-at-identifier)
                    132:                    nil)))))
                    133:
                    134: (defun gp-looking-at-rat-exp nil
                    135: "Return end of rational expression if point is located at the beginning
                    136: of one, nil otherwise.
                    137:   A rational expression for gp is a succession of terms separated by one
                    138: of the operators +-*%/."
                    139:   (save-excursion
                    140:     (let ((first-term (gp-looking-at-term)))
                    141:          (if (not first-term)
                    142:              nil
                    143:              (goto-char first-term)
                    144:              (if (looking-at "[ \t\n\\\\]*[+-*%/]")
                    145:                  (progn (goto-char (match-end 0))
                    146:                         (gp-looking-at-rat-exp))
                    147:                  first-term)))))
                    148:
                    149: ;; pari-translator.el ends here.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>