emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]