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