[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bnf-mode b18b10c 05/74: Implemented font locking
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bnf-mode b18b10c 05/74: Implemented font locking |
Date: |
Thu, 9 May 2019 08:27:42 -0400 (EDT) |
branch: externals/bnf-mode
commit b18b10cdd6ab043136a0ce0ad3dbf981a9dcbae5
Author: Serghei Iakovlev <address@hidden>
Commit: Serghei Iakovlev <address@hidden>
Implemented font locking
---
bnf-mode.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/bnf-mode.el b/bnf-mode.el
index f6cae2b..24d6e8a 100644
--- a/bnf-mode.el
+++ b/bnf-mode.el
@@ -112,13 +112,12 @@ just return nil."
(eval-when-compile
(defconst bnf-rx-constituents
`(
- ;; non-terminal
- (non-terminal . ,(rx (and
- "<"
- symbol-start
- (1+ (not blank))
- symbol-end
- ">")))
+ ;; rulename
+ (rulename . ,(rx (and
+ symbol-start
+ letter
+ (0+ (or "-" alnum))
+ symbol-end)))
"Additional special sexps for `bnf-rx'."))
(defmacro bnf-rx (&rest sexps)
@@ -127,8 +126,13 @@ just return nil."
In addition to the standard forms of `rx', the following forms
are available:
-`non-terminal'
- Any valid non-terminal.
+`rulename'
+ Any valid rule name. The name of a rule is simply the
+ name itself, that is, a sequence of characters, beginning
+ with an alphabetic character, and followed by a combination
+ of alphabetics, digits, and hyphens (dashes).
+
+ For more see: https://tools.ietf.org/html/rfc5234#section-2.1
See `rx' documentation for more information about REGEXPS param."
(let ((rx-constituents (append bnf-rx-constituents rx-constituents)))
@@ -141,12 +145,34 @@ See `rx' documentation for more information about REGEXPS
param."
;;; Font Locking
+
(defvar bnf-font-lock-keywords
`(
- ;; Non-terminals
+ ;; LHS nonterminals
(,(bnf-rx (and line-start
- (group non-terminal)))
- 1 font-lock-function-name-face))
+ "<"
+ (group rulename)
+ ">"))
+ 1 font-lock-function-name-face)
+ ;; other nonterminals
+ (,(bnf-rx (and "<"
+ (group rulename)
+ ">"))
+ 1 font-lock-builtin-face)
+ ;; "may expand into" symbol
+ (,(bnf-rx (and (0+ space)
+ symbol-start
+ (group "::=")
+ symbol-end
+ (0+ space)))
+ 1 font-lock-constant-face)
+ ;; Alternatives
+ (,(bnf-rx (and (0+ space)
+ symbol-start
+ (group "|")
+ symbol-end
+ (0+ space)))
+ 1 font-lock-warning-face))
"Font lock keywords for BNF Mode.")
@@ -161,20 +187,39 @@ See `rx' documentation for more information about REGEXPS
param."
;; Comments setup
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
+ ;; Treat ::= as sequence of symbols
+ (modify-syntax-entry ?\: "_" table)
+ (modify-syntax-entry ?\= "_" table)
+ ;; Treat | as a symbol
+ (modify-syntax-entry ?\| "_" table)
+ ;; Group angle brackets
+ (modify-syntax-entry ?\< "(>" table)
+ (modify-syntax-entry ?\> ")<" table)
table)
"Syntax table in use in `bnf-mode' buffers.")
;;;###autoload
(define-derived-mode bnf-mode prog-mode "BNF"
"A major mode for editing BNF grammars."
+ :syntax-table bnf-mode-syntax-table
:group 'bnf-mode
;; Comment setup
(setq-local comment-use-syntax t)
(setq-local comment-auto-fill-only-comments t)
(setq-local comment-start "# ")
(setq-local comment-end "")
+ (setq-local font-lock-keyword-face 'php-keyword)
;; Font locking
- (setq font-lock-defaults '((bnf-font-lock-keywords) nil nil)))
+ (setq font-lock-defaults '(
+ ;; Keywords
+ bnf-font-lock-keywords
+ ;; keywords-only
+ nil
+ ;; Regarding RFC-5234
+ ;; The names <rulename>, <Rulename>, <RULENAME>,
+ ;; and <rUlENamE> all refer to the same rule.
+ t
+ )))
;; Invoke bnf-mode when appropriate
- [elpa] externals/bnf-mode d3a7059 08/74: Added change log, (continued)
- [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
- [elpa] externals/bnf-mode 1ad5de5 37/74: Amended installation methods, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode b18b10c 05/74: Implemented font locking,
Stefan Monnier <=
- [elpa] externals/bnf-mode 388206f 09/74: Correct copyright date, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 3beded6 15/74: Rule names are case insensitive. Added test., Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode af8cf6d 18/74: Correct change log [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode fd83621 20/74: Bump version, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode f917836 23/74: Change default goal for make, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode ed24bee 21/74: Bumb version, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode a7df2dd 17/74: Fontify sequences, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode defc412 11/74: Amended description and docs, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode aa2c7a2 30/74: Correct change log formatting [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode c90b14d 26/74: Correct documentation to follow code style guide., Stefan Monnier, 2019/05/09