[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bnf-mode e2f8bfa 53/74: Added support of ; character to
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bnf-mode e2f8bfa 53/74: Added support of ; character to use in terminals |
Date: |
Thu, 9 May 2019 08:27:52 -0400 (EDT) |
branch: externals/bnf-mode
commit e2f8bfa26047469b32d5b1540bc4eb052c8215af
Author: Serghei Iakovlev <address@hidden>
Commit: Serghei Iakovlev <address@hidden>
Added support of ; character to use in terminals
---
CHANGELOG.org | 4 ++--
bnf-mode.el | 23 ++++++++++++++++++++++-
test/bnf-mode-font-test.el | 18 ++++++++++++++++++
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 07c06f0..5d0b6a7 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -8,9 +8,9 @@ The format is based on [[http://keepachangelog.com][Keep a
Changelog]] and this
** [[https://github.com/sergeyklay/bnf-mode/compare/0.3.2...HEAD][Unreleased]]
*** Added
- Added =comment-start-skip= to help comment commands recognize comments
-
-*** Changed
- Return back =comment-start= and =comment-end= removed in
[[https://github.com/sergeyklay/bnf-mode/commit/83f0e0fc144e453bcce459d2d655a7b48e77953e][83f0e0f]]
+- More intelligent terminal syntax recognition.
+ Added support of "=;=" character as an extra character used in terminals.
** [[https://github.com/sergeyklay/bnf-mode/compare/0.3.1...0.3.2][0.3.2]] -
2019-03-24
*** Changed
diff --git a/bnf-mode.el b/bnf-mode.el
index 232b6c4..387dc51 100644
--- a/bnf-mode.el
+++ b/bnf-mode.el
@@ -154,7 +154,7 @@ See `rx' documentation for more information about REGEXPS
param."
"Font lock BNF keywords for BNF Mode.")
-;;; Initialization
+;;; Syntax
(defvar bnf-mode-syntax-table
(let ((table (make-syntax-table)))
@@ -186,6 +186,25 @@ See `rx' documentation for more information about REGEXPS
param."
table)
"Syntax table in use in `bnf-mode' buffers.")
+(defun bnf--syntax-propertize (start end)
+ "Apply syntax table properties to special constructs in region START to END.
+Currently handled:
+
+ - Fontify terminals with ';' character correctly"
+ (save-excursion
+ (goto-char start)
+ ;; Search for terminals like "<abc;>" or "<a;bc>".
+ ;; Does not work for terminals like "<a;bc;>".
+ (while (re-search-forward "\\(?:<[^>]*\\);" end t)
+ (when (looking-at "\\(?:[^>]\\)*>")
+ ;; Mark the ";" character as an extra character used in terminals
+ ;; along with word constituents.
+ (put-text-property (1- (point)) (point)
+ 'syntax-table (string-to-syntax "_"))))))
+
+
+;;; Initialization
+
;;;###autoload
(define-derived-mode bnf-mode prog-mode "BNF"
"A major mode for editing BNF grammars."
@@ -196,6 +215,8 @@ See `rx' documentation for more information about REGEXPS
param."
(setq-local comment-start "; ")
(setq-local comment-end "")
(setq-local comment-start-skip "\\(?:\\(\\W\\|^\\);+\\)\\s-*")
+ ;; Tune up syntax `syntax-table'
+ (setq-local syntax-propertize-function #'bnf--syntax-propertize)
;; Font locking
(setq font-lock-defaults
'(
diff --git a/test/bnf-mode-font-test.el b/test/bnf-mode-font-test.el
index 6f9b1b7..d25f54b 100644
--- a/test/bnf-mode-font-test.el
+++ b/test/bnf-mode-font-test.el
@@ -163,5 +163,23 @@ angle-brackets ::= are-optional"
(should (eq (bnf-test-face-at 90) 'font-lock-builtin-face))
(should (eq (bnf-test-face-at 94) 'font-lock-builtin-face))))
+(ert-deftest bnf-mode-syntax-table/fontify-dotcomma-inside-rule ()
+ :tags '(fontification syntax-table)
+ (bnf-test-with-temp-buffer
+ "<a rule> ::= <abc;>
+; <foo> ::= <bar>
+<a> ::= <ab;c>"
+ ;; "abc;"
+ (should (eq (bnf-test-face-at 16) 'font-lock-builtin-face))
+ (should (eq (bnf-test-face-at 18) 'font-lock-builtin-face))
+ ;; "; <foo> ::= <bar>"
+ (should (eq (bnf-test-face-at 22) 'font-lock-comment-delimiter-face))
+ (should (eq (bnf-test-face-at 22) 'font-lock-comment-delimiter-face))
+ (should (eq (bnf-test-face-at 23) 'font-lock-comment-face))
+ (should (eq (bnf-test-face-at 37) 'font-lock-comment-face))
+ ;; "ab;c"
+ (should (eq (bnf-test-face-at 48) 'font-lock-builtin-face))
+ (should (eq (bnf-test-face-at 51) 'font-lock-builtin-face))))
+
(provide 'bnf-mode-font-test)
;;; bnf-mode-font-test.el ends here
- [elpa] externals/bnf-mode ed24bee 21/74: Bumb version, (continued)
- [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
- [elpa] externals/bnf-mode a3a77e3 29/74: In the BNF there are no grouping brackets except angle ones. Fixed, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 1698dc8 39/74: Improved documentation, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 64a32ba 42/74: Cleaned up Makefile, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode a53ade1 24/74: Fixed BNF rule name definition to follow ALGOL 60 report, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 65bfadc 65/74: Fixed orthodox comments regexp, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode e2f8bfa 53/74: Added support of ; character to use in terminals,
Stefan Monnier <=
- [elpa] externals/bnf-mode 3a46f17 36/74: Correct documentation, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode f99de60 47/74: Cleaned up Makefile, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 7bbf329 49/74: Added comment-start-skip to help comment commands recognize comments, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 00a0543 50/74: Removed not used tests macro, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 6eb06a8 52/74: Make tests easier to read, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 273eabd 31/74: Correct change log formatting (II) [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 687ee9e 16/74: Angle brackets to use for nonterminals are optional. Changed, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 83f0e0f 28/74: Code cleanup, Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 96c6e76 61/74: Changed CI deploy token [ci skip], Stefan Monnier, 2019/05/09
- [elpa] externals/bnf-mode 8dabc6c 63/74: Minor correction to the change log format, Stefan Monnier, 2019/05/09