Function: semantic-grammar-create-package
semantic-grammar-create-package is an interactive and byte-compiled
function defined in grammar.el.gz.
Signature
(semantic-grammar-create-package &optional FORCE UPTODATE)
Documentation
Create package Lisp code from grammar in current buffer.
If the Lisp code seems up to date, do nothing (if UPTODATE is non-nil, return nil in such cases). If optional argument FORCE is non-nil, unconditionally re-generate the Lisp code.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/grammar.el.gz
(defun semantic-grammar-create-package (&optional force uptodate)
"Create package Lisp code from grammar in current buffer.
If the Lisp code seems up to date, do nothing (if UPTODATE
is non-nil, return nil in such cases).
If optional argument FORCE is non-nil, unconditionally re-generate the
Lisp code."
(interactive "P")
(unless (semantic-active-p)
(error "You have to activate semantic-mode to create a package"))
(setq force (or force current-prefix-arg))
(semantic-fetch-tags)
(let* (
;; Values of the following local variables are obtained from
;; the grammar parsed tree in current buffer, that is before
;; switching to the output file.
(semantic--grammar-package (semantic-grammar-package))
(semantic--grammar-provide (semantic-grammar-first-tag-name 'provide))
(output (concat (or semantic--grammar-provide
semantic--grammar-package)
".el"))
(semantic--grammar-input-buffer (current-buffer))
(semantic--grammar-output-buffer
(find-file-noselect
(file-name-nondirectory output)))
(header (semantic-grammar-header))
(prologue (semantic-grammar-prologue))
(epilogue (semantic-grammar-epilogue))
(footer (semantic-grammar-footer))
)
(if (and (not force)
(not (buffer-modified-p))
(file-newer-than-file-p
(buffer-file-name semantic--grammar-output-buffer)
(buffer-file-name semantic--grammar-input-buffer)))
(progn
(message "Package `%s' is up to date." semantic--grammar-package)
;; It would be better if this were always the case, IMO,
;; but the (unspecified) return value of this function is
;; assumed to be non-nil in some places, it seems.
(if uptodate (setq output nil)))
;; Create the package
(set-buffer semantic--grammar-output-buffer)
;; Use Unix EOLs, so that the file is portable to all platforms.
(setq buffer-file-coding-system 'raw-text-unix)
(erase-buffer)
(unless (derived-mode-p 'emacs-lisp-mode)
(emacs-lisp-mode))
;;;; Header + Prologue
(insert header
"\n;;; Prologue\n;;\n"
prologue
)
;; Evaluate the prologue now, because it might provide definition
;; of grammar macro expanders.
(eval-region (point-min) (point))
(save-excursion
;;;; Declarations
(insert "\n;;; Declarations\n;;\n")
(semantic-grammar-insert-defconst-with-eval
(concat semantic--grammar-package "--expected-conflicts")
(with-current-buffer semantic--grammar-input-buffer
(format "%s\n" (car (semantic-grammar-expected-conflicts))))
"The number of expected shift/reduce conflicts in this grammar.")
;; `eval-defun' is not necessary to reset `defconst' values.
(semantic-grammar-insert-defconst
(semantic-grammar-keywordtable)
(with-current-buffer semantic--grammar-input-buffer
(semantic-grammar-keyword-data))
"Table of language keywords.")
(semantic-grammar-insert-defconst
(semantic-grammar-tokentable)
(with-current-buffer semantic--grammar-input-buffer
(semantic-grammar-token-data))
"Table of lexical tokens.")
(semantic-grammar-insert-defconst
(semantic-grammar-parsetable)
(with-current-buffer semantic--grammar-input-buffer
(semantic-grammar-parser-data))
"Parser table.")
(semantic-grammar-insert-defun
(semantic-grammar-setupfunction)
(with-current-buffer semantic--grammar-input-buffer
(semantic-grammar-setup-data))
"Setup the Semantic Parser.")
;;;; Analyzers
(insert "\n;;; Analyzers\n;;\n")
(semantic-grammar-insert-defanalyzers)
;;;; Epilogue & Footer
(insert "\n;;; Epilogue\n;;\n"
epilogue
footer
)
)
(save-buffer 16)
;; If running in batch mode, there is nothing more to do.
;; Save the generated file and quit.
(if noninteractive
(let ((version-control t)
(delete-old-versions t)
(make-backup-files t)
(vc-make-backup-files t))
(kill-buffer (current-buffer)))
;; If running interactively, eval declarations and epilogue
;; code, then pop to the buffer visiting the generated file.
(eval-region (point) (point-max))
;; Loop over the defvars and eval them explicitly to force
;; them to be evaluated and ready to use.
(goto-char (point-min))
(while (re-search-forward "(defvar " nil t)
(eval-defun nil))
;; Move cursor to a logical spot in the generated code.
(goto-char (point-min))
(pop-to-buffer (current-buffer))
;; The generated code has been evaluated and updated into
;; memory. Now find all buffers that match the major modes we
;; have created this language for, and force them to call our
;; setup function again, refreshing all semantic data, and
;; enabling them to work with the new code just created.
;;;; FIXME?
;; At this point, I don't know any user's defined setup code :-(
;; At least, what I can do for now, is to run the generated
;; parser-install function.
(semantic-map-mode-buffers
(semantic-grammar-setupfunction)
(semantic-grammar-languagemode)))
)
;; Return the name of the generated package file.
output))