ede-grammar.el 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ;;; semantic/ede-grammar.el --- EDE support for Semantic Grammar Files
  2. ;; Copyright (C) 2003-2004, 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: project, make
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; Handle .by or .wy files.
  19. (require 'semantic)
  20. (require 'ede/proj)
  21. (require 'ede/pmake)
  22. (require 'ede/pconf)
  23. (require 'ede/proj-elisp)
  24. (require 'semantic/grammar)
  25. ;;; Code:
  26. (defclass semantic-ede-proj-target-grammar (ede-proj-target-makefile)
  27. ((menu :initform nil)
  28. (keybindings :initform nil)
  29. (phony :initform t)
  30. (sourcetype :initform
  31. (semantic-ede-source-grammar-wisent
  32. semantic-ede-source-grammar-bovine
  33. ))
  34. (availablecompilers :initform
  35. (semantic-ede-grammar-compiler-wisent
  36. semantic-ede-grammar-compiler-bovine
  37. ))
  38. )
  39. "This target consists of a group of grammar files.
  40. A grammar target consists of grammar files that build Emacs Lisp programs for
  41. parsing different languages.")
  42. (defvar semantic-ede-source-grammar-wisent
  43. (ede-sourcecode "semantic-ede-grammar-source-wisent"
  44. :name "Wisent Grammar"
  45. :sourcepattern "\\.wy$"
  46. )
  47. "Semantic Grammar source code definition for wisent.")
  48. (defclass semantic-ede-grammar-compiler-class (ede-compiler)
  49. nil
  50. "Specialized compiler for semantic grammars.")
  51. (defvar semantic-ede-grammar-compiler-wisent
  52. (semantic-ede-grammar-compiler-class
  53. "ede-emacs-wisent-compiler"
  54. :name "emacs"
  55. :variables '(("EMACS" . "emacs"))
  56. :commands
  57. '(
  58. "@echo \"(add-to-list 'load-path nil)\" > grammar-make-script"
  59. "@for loadpath in . ${LOADPATH}; do \\"
  60. " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> grammar-make-script; \\"
  61. "done;"
  62. "@echo \"(require 'semantic/load)\" >> grammar-make-script"
  63. "@echo \"(require 'semantic/grammar)\" >> grammar-make-script"
  64. ;; "@echo \"(setq debug-on-error t)\" >> grammar-make-script"
  65. "\"$(EMACS)\" -batch --no-site-file -l grammar-make-script -f semantic-grammar-batch-build-packages $^"
  66. )
  67. ;; :autoconf '("AM_PATH_LISPDIR")
  68. :sourcetype '(semantic-ede-source-grammar-wisent)
  69. :objectextention "-wy.elc"
  70. )
  71. "Compile Emacs Lisp programs.")
  72. (defvar semantic-ede-source-grammar-bovine
  73. (ede-sourcecode "semantic-ede-grammar-source-bovine"
  74. :name "Bovine Grammar"
  75. :sourcepattern "\\.by$"
  76. )
  77. "Semantic Grammar source code definition for the bovinator.")
  78. (defvar semantic-ede-grammar-compiler-bovine
  79. (semantic-ede-grammar-compiler-class
  80. "ede-emacs-wisent-compiler"
  81. :name "emacs"
  82. :variables '(("EMACS" . "emacs"))
  83. :commands
  84. '(
  85. "@echo \"(add-to-list 'load-path nil)\" > grammar-make-script"
  86. "@for loadpath in . ${LOADPATH}; do \\"
  87. " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> grammar-make-script; \\"
  88. "done;"
  89. "@echo \"(require 'semantic/load)\" >> grammar-make-script"
  90. "@echo \"(require 'semantic/grammar)\" >> grammar-make-script"
  91. ;; "@echo \"(setq debug-on-error t)\" >> grammar-make-script"
  92. "\"$(EMACS)\" -batch --no-site-file -l grammar-make-script -f semantic-grammar-batch-build-packages $^"
  93. )
  94. ;; :autoconf '("AM_PATH_LISPDIR")
  95. :sourcetype '(semantic-ede-source-grammar-bovine)
  96. :objectextention "-by.elc"
  97. )
  98. "Compile Emacs Lisp programs.")
  99. ;;; Target options.
  100. (defmethod ede-buffer-mine ((this semantic-ede-proj-target-grammar) buffer)
  101. "Return t if object THIS lays claim to the file in BUFFER.
  102. Lays claim to all -by.el, and -wy.el files."
  103. ;; We need to be a little more careful than this, but at the moment it
  104. ;; is common to have only one target of this class per directory.
  105. (if (string-match "-[bw]y\\.elc?$" (buffer-file-name buffer))
  106. t
  107. (call-next-method) ; The usual thing.
  108. ))
  109. (defmethod project-compile-target ((obj semantic-ede-proj-target-grammar))
  110. "Compile all sources in a Lisp target OBJ."
  111. (let* ((cb (current-buffer))
  112. (proj (ede-target-parent obj))
  113. (default-directory (oref proj directory)))
  114. (mapc (lambda (src)
  115. (with-current-buffer (find-file-noselect src)
  116. (save-excursion
  117. (semantic-grammar-create-package))
  118. (save-buffer)
  119. (byte-recompile-file (concat (semantic-grammar-package) ".el") nil 0)))
  120. (oref obj source)))
  121. (message "All Semantic Grammar sources are up to date in %s" (object-name obj)))
  122. ;;; Makefile generation functions
  123. ;;
  124. (defmethod ede-proj-makefile-sourcevar ((this semantic-ede-proj-target-grammar))
  125. "Return the variable name for THIS's sources."
  126. (cond ((ede-proj-automake-p)
  127. (error "No Automake support for Semantic Grammars"))
  128. (t (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR"))))
  129. (defmethod ede-proj-makefile-insert-variables :AFTER ((this semantic-ede-proj-target-grammar))
  130. "Insert variables needed by target THIS."
  131. (ede-proj-makefile-insert-loadpath-items
  132. (ede-proj-elisp-packages-to-loadpath
  133. (list "eieio" "semantic" "inversion" "ede")))
  134. ;; eieio for object system needed in ede
  135. ;; semantic because it is
  136. ;; Inversion for versioning system.
  137. ;; ede for project regeneration
  138. (ede-pmake-insert-variable-shared
  139. (concat (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL")
  140. (insert
  141. (mapconcat (lambda (src)
  142. (with-current-buffer (find-file-noselect src)
  143. (concat (semantic-grammar-package) ".el")))
  144. (oref this source)
  145. " ")))
  146. )
  147. (defmethod ede-proj-makefile-insert-rules ((this semantic-ede-proj-target-grammar))
  148. "Insert rules needed by THIS target."
  149. ;; Add in some dependencies.
  150. ;; (mapc (lambda (src)
  151. ;; (let ((nm (file-name-sans-extension src)))
  152. ;; (insert nm "-wy.el: " src "\n"
  153. ;; nm "-wy.elc: " nm "-wy.el\n\n")
  154. ;; ))
  155. ;; (oref this source))
  156. ;; Call the normal insertion of rules.
  157. (call-next-method)
  158. )
  159. (defmethod ede-proj-makefile-insert-dist-dependencies ((this semantic-ede-proj-target-grammar))
  160. "Insert dist dependencies, or intermediate targets.
  161. This makes sure that all grammar lisp files are created before the dist
  162. runs, so they are always up to date.
  163. Argument THIS is the target that should insert stuff."
  164. (call-next-method)
  165. (insert " $(" (ede-pmake-varname this) "_SEMANTIC_GRAMMAR_EL)")
  166. )
  167. ;; (autoload 'ede-proj-target-elisp "ede/proj-elisp"
  168. ;; "Target class for Emacs/Semantic grammar files." nil nil)
  169. (ede-proj-register-target "semantic grammar"
  170. semantic-ede-proj-target-grammar)
  171. (provide 'semantic/ede-grammar)
  172. ;;; semantic/ede-grammar.el ends here