[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bnf-mode f100f00 04/74: Initial font locking
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bnf-mode f100f00 04/74: Initial font locking |
Date: |
Thu, 9 May 2019 08:27:42 -0400 (EDT) |
branch: externals/bnf-mode
commit f100f00d5282db5186d2457ee272664f7c3855d2
Author: Serghei Iakovlev <address@hidden>
Commit: Serghei Iakovlev <address@hidden>
Initial font locking
---
bnf-mode.el | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 64 insertions(+), 10 deletions(-)
diff --git a/bnf-mode.el b/bnf-mode.el
index 8dde75f..f6cae2b 100644
--- a/bnf-mode.el
+++ b/bnf-mode.el
@@ -50,7 +50,7 @@
;;; Compatibility
;; Work around emacs bug#18845, cc-mode expects cl to be loaded
-;; while zephir-mode only uses cl-lib (without compatibility aliases)
+;; while bnf-mode only uses cl-lib (without compatibility aliases)
(eval-and-compile
(if (and (= emacs-major-version 24) (>= emacs-minor-version 4))
(require 'cl)))
@@ -61,6 +61,9 @@
;; Tell the byte compiler about autoloaded functions from packages
(declare-function pkg-info-version-info "pkg-info" (package))
+(eval-when-compile
+ (require 'rx))
+
(require 'cl-lib)
(require 'pkg-info)
@@ -68,7 +71,7 @@
;;; Customization
;;;###autoload
-(defgroup zephir nil
+(defgroup bnf nil
"Major mode for editing BNF grammars."
:tag "BNF"
:prefix "bnf-"
@@ -85,7 +88,7 @@
;;; Version information
-(defun zephir-mode-version (&optional show-version)
+(defun bnf-mode-version (&optional show-version)
"Display string describing the version of BNF Mode.
If called interactively or if SHOW-VERSION is non-nil, show the
@@ -98,21 +101,70 @@ If the version number could not be determined, signal an
error,
if called interactively, or if SHOW-VERSION is non-nil, otherwise
just return nil."
(interactive (list t))
- (let ((version (pkg-info-version-info 'zephir-mode)))
+ (let ((version (pkg-info-version-info 'bnf-mode)))
(when show-version
(message "BNF Mode version: %s" version))
version))
+
+;;; Specialized rx
+
+(eval-when-compile
+ (defconst bnf-rx-constituents
+ `(
+ ;; non-terminal
+ (non-terminal . ,(rx (and
+ "<"
+ symbol-start
+ (1+ (not blank))
+ symbol-end
+ ">")))
+ "Additional special sexps for `bnf-rx'."))
+
+ (defmacro bnf-rx (&rest sexps)
+ "BNF-specific replacement for `rx'.
+
+In addition to the standard forms of `rx', the following forms
+are available:
+
+`non-terminal'
+ Any valid non-terminal.
+
+See `rx' documentation for more information about REGEXPS param."
+ (let ((rx-constituents (append bnf-rx-constituents rx-constituents)))
+ (cond ((null sexps)
+ (error "No regexp"))
+ ((cdr sexps)
+ (rx-to-string `(and ,@sexps) t))
+ (t
+ (rx-to-string (car sexps) t))))))
+
+
+;;; Font Locking
+(defvar bnf-font-lock-keywords
+ `(
+ ;; Non-terminals
+ (,(bnf-rx (and line-start
+ (group non-terminal)))
+ 1 font-lock-function-name-face))
+ "Font lock keywords for BNF Mode.")
+
+
+;;; Initialization
+
(defvar bnf-mode-syntax-table
(let ((table (make-syntax-table)))
- (modify-syntax-entry ?# "<" table)
- (modify-syntax-entry ?\n ">" table)
+ ;; Give CR the same syntax as newline
+ (modify-syntax-entry ?\^m "> b" table)
+ ;; Characters used to delimit string constants
+ (modify-syntax-entry ?\" "\"" table)
+ ;; Comments setup
+ (modify-syntax-entry ?# "<" table)
+ (modify-syntax-entry ?\n ">" table)
table)
"Syntax table in use in `bnf-mode' buffers.")
-
-;;; Initialization
-
+;;;###autoload
(define-derived-mode bnf-mode prog-mode "BNF"
"A major mode for editing BNF grammars."
:group 'bnf-mode
@@ -120,7 +172,9 @@ just return nil."
(setq-local comment-use-syntax t)
(setq-local comment-auto-fill-only-comments t)
(setq-local comment-start "# ")
- (setq-local comment-end ""))
+ (setq-local comment-end "")
+ ;; Font locking
+ (setq font-lock-defaults '((bnf-font-lock-keywords) nil nil)))
;; Invoke bnf-mode when appropriate
- [elpa] branch externals/bnf-mode created (now a4ca649), Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode cecdb79 01/74: Initial commit, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode f100f00 04/74: Initial font locking,
Stefan Monnier <=
- [elpa] externals/bnf-mode f0a3cd7 03/74: Add CHANGELOG file, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode d3a7059 08/74: Added change log, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode aa8e9af 12/74: Initial test case, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode d50ded2 13/74: Amended tests, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 1d8c1e7 14/74: Update change log [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 7e37702 25/74: Correct BNF description [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode f6fd97b 07/74: Setup Travis CI builds, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 246a24f 22/74: Bump version, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 3e48f65 27/74: BNF has no strings. Treat ' and " as a symbols, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode a7ea867 32/74: Correct documentation, Stefan Monnier, 2019/05/09