;;; semantic/grammar.el --- Major mode framework for Semantic grammars
-;; Copyright (C) 2002-2005, 2007-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2005, 2007-2015 Free Software Foundation, Inc.
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;;; Code:
(require 'semantic)
+(require 'semantic/wisent)
(require 'semantic/ctxt)
(require 'semantic/format)
+;; FIXME this is a generated file, but we need to load this file to
+;; generate it!
(require 'semantic/grammar-wy)
(require 'semantic/idle)
+(require 'help-fns)
+
(declare-function semantic-momentary-highlight-tag "semantic/decorate")
(declare-function semantic-analyze-context "semantic/analyze")
(declare-function semantic-analyze-tags-of-class-list
(eval-when-compile
(require 'eldoc)
(require 'semantic/edit)
- (require 'semantic/find))
+ (require 'semantic/find)
+ (require 'semantic/db))
+
+(declare-function semantic-grammar-wy--install-parser "semantic/grammar-wy")
\f
;;;;
;; regexp match semicolons inside strings!
semantic-lex-ignore-comments
;; Must detect prefixed list before punctuation because prefix chars
- ;; are also punctuations!
+ ;; are also punctuation!
semantic-grammar-wy--<qlist>-sexp-analyzer
- ;; Must detect punctuations after comments because the semicolon can
- ;; be a punctuation or a comment start!
+ ;; Must detect punctuation after comments because the semicolon can
+ ;; be punctuation or a comment start!
semantic-grammar-wy--<punctuation>-string-analyzer
semantic-grammar-wy--<block>-block-analyzer
semantic-grammar-wy--<sexp>-sexp-analyzer)
',(semantic-grammar-keyword-properties keywords))))
(define-overloadable-function semantic-grammar-keywordtable-builder ()
- "Return the keyword table table value.")
+ "Return the keyword table value.")
;;; Token table builder
;;
;;;;
(defvar semantic--grammar-input-buffer nil)
(defvar semantic--grammar-output-buffer nil)
+(defvar semantic--grammar-package nil)
+(defvar semantic--grammar-provide nil)
(defsubst semantic-grammar-keywordtable ()
"Return the variable name of the keyword table."
- (concat (file-name-sans-extension
- (semantic-grammar-buffer-file
- semantic--grammar-output-buffer))
+ (concat semantic--grammar-package
"--keyword-table"))
(defsubst semantic-grammar-tokentable ()
"Return the variable name of the token table."
- (concat (file-name-sans-extension
- (semantic-grammar-buffer-file
- semantic--grammar-output-buffer))
+ (concat semantic--grammar-package
"--token-table"))
(defsubst semantic-grammar-parsetable ()
"Return the variable name of the parse table."
- (concat (file-name-sans-extension
- (semantic-grammar-buffer-file
- semantic--grammar-output-buffer))
+ (concat semantic--grammar-package
"--parse-table"))
(defsubst semantic-grammar-setupfunction ()
"Return the name of the parser setup function."
- (concat (file-name-sans-extension
- (semantic-grammar-buffer-file
- semantic--grammar-output-buffer))
+ (concat semantic--grammar-package
"--install-parser"))
(defmacro semantic-grammar-as-string (object)
;;
;;; Code:
+
+(require 'semantic/lex)
+(eval-when-compile (require 'semantic/bovine))
")
"Generated header template.
The symbols in the template are local variables in
\(provide '" libr ")
+;; Local Variables:
+;; version-control: never
+;; no-update-autoloads: t
+;; End:
+
;;; " file " ends here
")
"Generated footer template.
"Return text of a generated standard footer."
(let* ((file (semantic-grammar-buffer-file
semantic--grammar-output-buffer))
- (libr (file-name-sans-extension file))
+ (libr (or semantic--grammar-provide
+ semantic--grammar-package))
(out ""))
(dolist (S semantic-grammar-footer-template)
(cond ((stringp S)
;; explicitly declared in a %type statement, and if at least the
;; syntax property has been provided.
(when (and declared syntax)
- (setq prefix (file-name-sans-extension
- (semantic-grammar-buffer-file
- semantic--grammar-output-buffer))
+ (setq prefix semantic--grammar-package
mtype (or (get type 'matchdatatype) 'regexp)
name (intern (format "%s--<%s>-%s-analyzer" prefix type mtype))
doc (format "%s analyzer for <%s> tokens." mtype type))
(with-current-buffer semantic--grammar-input-buffer
(setq tokens (semantic-grammar-tokens)
props (semantic-grammar-token-properties tokens)))
- (insert "(require 'semantic/lex)\n\n")
(let ((semantic-lex-types-obarray
(semantic-lex-make-type-table tokens props))
semantic-grammar--lex-block-specs)
(noninteractive)
noninteractive))
-(defun semantic-grammar-create-package (&optional force)
+(defun semantic-grammar-create-package (&optional force uptodate)
"Create package Lisp code from grammar in current buffer.
-Does nothing if the Lisp code seems up to date.
+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.
- (package (semantic-grammar-package))
- (output (concat package ".el"))
+ (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 output))
+ (semantic--grammar-output-buffer
+ (find-file-noselect
+ (file-name-nondirectory output)))
(header (semantic-grammar-header))
(prologue (semantic-grammar-prologue))
(epilogue (semantic-grammar-epilogue))
(file-newer-than-file-p
(buffer-file-name semantic--grammar-output-buffer)
(buffer-file-name semantic--grammar-input-buffer)))
- (message "Package `%s' is up to date." package)
+ (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 (eq major-mode 'emacs-lisp-mode)
+ (unless (derived-mode-p 'emacs-lisp-mode)
(emacs-lisp-mode))
;;;; Header + Prologue
(let ((packagename
(condition-case err
(with-current-buffer (find-file-noselect file)
- (semantic-grammar-create-package))
+ (let ((semantic-new-buffer-setup-functions nil)
+ (vc-handled-backends nil))
+ (setq semanticdb-new-database-class 'semanticdb-project-database)
+ (semantic-mode 1)
+ (semantic-grammar-create-package)))
(error
(message "%s" (error-message-string err))
nil))))
;; Remove vc from find-file-hook. It causes bad stuff to
;; happen in Emacs 20.
(find-file-hook (delete 'vc-find-file-hook find-file-hook)))
- (message "Compiling Grammars from: %s" (locate-library "semantic-grammar"))
(dolist (arg command-line-args-left)
(unless (and arg (file-exists-p arg))
(error "Argument %s is not a valid file name" arg))
;;;; Define major mode
;;;;
-(defvar semantic-grammar-syntax-table
+(define-obsolete-variable-alias 'semantic-grammar-syntax-table
+ 'semantic-grammar-mode-syntax-table "24.1")
+(defvar semantic-grammar-mode-syntax-table
(let ((table (make-syntax-table (standard-syntax-table))))
(modify-syntax-entry ?\: "." table) ;; COLON
(modify-syntax-entry ?\> "." table) ;; GT
(defvar semantic-grammar-mode-keywords-2
(append semantic-grammar-mode-keywords-1
- lisp-font-lock-keywords-1)
+ (if (boundp 'lisp-font-lock-keywords-1)
+ lisp-font-lock-keywords-1
+ lisp-el-font-lock-keywords-1))
"Font Lock keywords used to highlight Semantic grammar buffers.")
(defvar semantic-grammar-mode-keywords-3
(append semantic-grammar-mode-keywords-1
- lisp-font-lock-keywords-2)
+ (if (boundp 'lisp-font-lock-keywords-2)
+ lisp-font-lock-keywords-2
+ lisp-el-font-lock-keywords-2))
"Font Lock keywords used to highlight Semantic grammar buffers.")
(defvar semantic-grammar-mode-keywords
semantic-grammar-mode-keywords-1
"Font Lock keywords used to highlight Semantic grammar buffers.")
-(defvar semantic-grammar-map
+(define-obsolete-variable-alias 'semantic-grammar-map
+ 'semantic-grammar-mode-map "24.1")
+(defvar semantic-grammar-mode-map
(let ((km (make-sparse-keymap)))
(define-key km "|" 'semantic-grammar-electric-punctuation)
(semantic-tag-start outer)
(semantic-tag-end outer)))))
-(defun semantic-grammar-mode ()
+(define-derived-mode semantic-grammar-mode
+ fundamental-mode "Semantic Grammar Framework"
"Initialize a buffer for editing Semantic grammars.
-\\{semantic-grammar-map}"
- (interactive)
- (kill-all-local-variables)
- (setq major-mode 'semantic-grammar-mode
- mode-name "Semantic Grammar Framework")
+\\{semantic-grammar-mode-map}"
(set (make-local-variable 'parse-sexp-ignore-comments) t)
(set (make-local-variable 'comment-start) ";;")
;; Look within the line for a ; following an even number of backslashes
;; after either a non-backslash or the line beginning.
(set (make-local-variable 'comment-start-skip)
"\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
- (set-syntax-table semantic-grammar-syntax-table)
- (use-local-map semantic-grammar-map)
(set (make-local-variable 'indent-line-function)
'semantic-grammar-indent)
(set (make-local-variable 'fill-paragraph-function)
semantic-grammar-mode-keywords-3)
nil ;; perform string/comment fontification
nil ;; keywords are case sensitive.
- ;; This puts _ & - as a word constituant,
+ ;; This puts _ & - as a word constituent,
;; simplifying our keywords significantly
((?_ . "w") (?- . "w"))))
;; Setup Semantic to parse grammar
(add-hook 'before-change-functions
'semantic--grammar-clear-macros-regexp-2 nil t)
;; Handle safe re-parse of grammar rules.
- (semantic-make-local-hook 'semantic-edits-new-change-hooks)
- (add-hook 'semantic-edits-new-change-hooks
+ (semantic-make-local-hook 'semantic-edits-new-change-functions)
+ (add-hook 'semantic-edits-new-change-functions
'semantic-grammar-edits-new-change-hook-fcn
- nil t)
- (semantic-run-mode-hooks 'semantic-grammar-mode-hook))
+ nil t))
\f
;;;;
;;;; Useful commands
;;;;
(defvar semantic-grammar-skip-quoted-syntax-table
- (let ((st (copy-syntax-table semantic-grammar-syntax-table)))
+ (let ((st (copy-syntax-table semantic-grammar-mode-syntax-table)))
(modify-syntax-entry ?\' "$" st)
st)
"Syntax table to skip a whole quoted expression in grammar code.
(interactive)
(if (semantic-grammar-in-lisp-p)
;; We are in lisp code. Do lisp completion.
- (lisp-complete-symbol)
+ (let ((completion-at-point-functions
+ (append '(lisp-completion-at-point)
+ completion-at-point-functions)))
+ (completion-at-point))
;; We are not in lisp code. Do rule completion.
(let* ((nonterms (semantic-find-tags-by-class 'nonterminal (current-buffer)))
(sym (car (semantic-ctxt-current-symbol)))
)
"Association of syntax elements, and the corresponding help.")
+(declare-function eldoc-function-argstring "eldoc")
+(declare-function eldoc-docstring-format-sym-doc "eldoc")
+(declare-function eldoc-last-data-store "eldoc")
+(declare-function eldoc-get-fnsym-args-string "eldoc")
+(declare-function eldoc-get-var-docstring "eldoc")
+
(defun semantic-grammar-eldoc-get-macro-docstring (macro expander)
"Return a one-line docstring for the given grammar MACRO.
EXPANDER is the name of the function that expands MACRO."
(provide 'semantic/grammar)
+\f
+;; Local variables:
+;; generated-autoload-load-name: "semantic/grammar"
+;; End:
+
;;; semantic/grammar.el ends here