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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/bnf-mode 687ee9e 16/74: Angle brackets to use for nonte


From: Stefan Monnier
Subject: [elpa] externals/bnf-mode 687ee9e 16/74: Angle brackets to use for nonterminals are optional. Changed
Date: Thu, 9 May 2019 08:27:45 -0400 (EDT)

branch: externals/bnf-mode
commit 687ee9e0c10f18c711888af96573bf7b97aff4da
Author: Serghei Iakovlev <address@hidden>
Commit: Serghei Iakovlev <address@hidden>

    Angle brackets to use for nonterminals are optional. Changed
    
    In addition:
    
    - LHS nonterminals may be preceded by an unlimited number of spaces
---
 CHANGELOG.org              |  8 ++++++--
 bnf-mode.el                | 36 +++++++++++++++++++++++++++---------
 test/bnf-mode-font-test.el | 37 ++++++++++++++++++++++++++++---------
 3 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index f8157a7..eb76ed8 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -7,12 +7,16 @@ The format is based on [[http://keepachangelog.com][Keep a 
Changelog]] and this
 
 ** [[https://github.com/sergeyklay/bnf-mode/compare/0.1.0...HEAD][Unreleased]]
 
+*** Changed
+- LHS nonterminals may be preceded by an unlimited number of spaces
+- Regarding to 
[[https://tools.ietf.org/html/rfc5234#section-2.1][RFC5234#2.1]] angle brackets 
to use for nonterminals are optional
+
 ** 0.2.0 - 2019-03-16
 *** Changed
-- Comments are no longer use syntax table.  For more see `comment-use-syntax'.
+- Comments are no longer use syntax table.  For more see `comment-use-syntax'
 
 *** Fixed
-- Changed comment syntax from ~#~ to ~;~ to follow 
[[https://tools.ietf.org/html/rfc822#section-2.8][RFC822#2.8]] .
+- Changed comment syntax from ~#~ to ~;~ to follow 
[[https://tools.ietf.org/html/rfc822#section-2.8][RFC822#2.8]]
 
 ** 0.1.0 - 2019-03-16
 *** Added
diff --git a/bnf-mode.el b/bnf-mode.el
index dd685ef..32e74ec 100644
--- a/bnf-mode.el
+++ b/bnf-mode.el
@@ -146,23 +146,41 @@ See `rx' documentation for more information about REGEXPS 
param."
 
 (defvar bnf-font-lock-keywords
   `(
-    ;; LHS nonterminals
+    ;; LHS nonterminals may be preceded
+    ;; by an unlimited number of spaces
     (,(bnf-rx (and line-start
+                   (0+ space)
                    "<"
                    (group rulename)
-                   ">"))
+                   ">"
+                   (1+ space)
+                   "::="))
      1 font-lock-function-name-face)
-    ;; other nonterminals
-    (,(bnf-rx (and "<"
+    ;; Regarding to RFC5234#2.1 angle brackets
+    ;; (“<”, “>”) for LHS nonterminals are optional.
+    (,(bnf-rx (and line-start
+                   (0+ space)
+                   (group rulename)
+                   (1+ space)
+                   "::="))
+     1 font-lock-function-name-face)
+    ;; RHS nonterminals
+    (,(bnf-rx (and "::="
+                   (1+ space)
+                   "<"
                    (group rulename)
                    ">"))
      1 font-lock-builtin-face)
-    ;; "may expand into" symbol
-    (,(bnf-rx (and (0+ space)
-                   symbol-start
+     ;; Regarding to RFC5234#2.1 angle brackets
+     ;; (“<”, “>”) for RHS nonterminals are optional.
+     (,(bnf-rx (and "::="
+                   (1+ space)
+                   (group rulename)))
+     1 font-lock-builtin-face)
+    ;; “may expand into” symbol
+    (,(bnf-rx (and symbol-start
                    (group "::=")
-                   symbol-end
-                   (0+ space)))
+                   symbol-end))
      1 font-lock-constant-face)
     ;; Alternatives
     (,(bnf-rx (and (0+ space)
diff --git a/test/bnf-mode-font-test.el b/test/bnf-mode-font-test.el
index 2300695..23c5bd9 100644
--- a/test/bnf-mode-font-test.el
+++ b/test/bnf-mode-font-test.el
@@ -61,27 +61,35 @@ buffer."
                              (should (eq (bnf-test-face-at 1) 
'font-lock-comment-face))
                              (should (eq (bnf-test-face-at 3) 
'font-lock-comment-face))
                              (should-not (bnf-test-face-at 5))
-                             (should (eq (bnf-test-face-at 24) '
-                                         font-lock-comment-face))))
+                             (should (eq (bnf-test-face-at 24) 
'font-lock-comment-face))))
 
 (ert-deftest bnf-mode-syntax-table/fontify-nonterminals ()
   :tags '(fontification syntax-table)
-  (bnf-test-with-temp-buffer "<stm> ::= <decl>"
+  (bnf-test-with-temp-buffer "<stm> ::= <decl>
+angle-brackets ::= are-optional"
                              ;; angle bracket
                              (should-not (bnf-test-face-at 1))
-                             ;; "stm"
+                             ;; “stm”
                              (should (eq (bnf-test-face-at 2) 
'font-lock-function-name-face))
                              (should (eq (bnf-test-face-at 4) 
'font-lock-function-name-face))
                              ;; angle bracket
                              (should-not (bnf-test-face-at 5))
-                             ;; "may expand into" symbol
-                             (should-not (eq (bnf-test-face-at 7) 
'font-lock-function-name-face))
-                             (should-not (eq (bnf-test-face-at 9) 
'font-lock-function-name-face))
+                             ;; “::=” symbol
+                             (should (eq (bnf-test-face-at 7) 
'font-lock-constant-face))
+                             (should (eq (bnf-test-face-at 9) 
'font-lock-constant-face))
                              ;; angle bracket
                              (should-not (bnf-test-face-at 11))
-                             ;; "dec" symbol
+                             ;; “dec” symbol
                              (should (eq (bnf-test-face-at 12) 
'font-lock-builtin-face))
-                             (should (eq (bnf-test-face-at 15) 
'font-lock-builtin-face))))
+                             (should (eq (bnf-test-face-at 15) 
'font-lock-builtin-face))
+                             ;; “angle-brackets”
+                             (should (eq (bnf-test-face-at 18) 
'font-lock-function-name-face))
+                             (should (eq (bnf-test-face-at 31) 
'font-lock-function-name-face))
+                             ;; space
+                             (should-not (bnf-test-face-at 32))
+                             ;; “are-optional” symbol
+                             (should (eq (bnf-test-face-at 37) 
'font-lock-builtin-face))
+                             (should (eq (bnf-test-face-at 48) 
'font-lock-builtin-face))))
 
 (ert-deftest bnf-mode-syntax-table/fontify-nonterminals-case ()
   :tags '(fontification syntax-table)
@@ -96,6 +104,17 @@ buffer."
                              (should (eq (bnf-test-face-at 30) 
'font-lock-builtin-face))
                              (should-not (bnf-test-face-at 31))))
 
+(ert-deftest bnf-mode-syntax-table/fontify-nonterminals-start-pos ()
+  :tags '(fontification syntax-table)
+  (bnf-test-with-temp-buffer "   <rule> ::= doo"
+                             (should-not (bnf-test-face-at 4))
+                             (should (eq (bnf-test-face-at 5) 
'font-lock-function-name-face))
+                             (should (eq (bnf-test-face-at 6) 
'font-lock-function-name-face))
+                             (should (eq (bnf-test-face-at 7) 
'font-lock-function-name-face))
+                             (should (eq (bnf-test-face-at 8) 
'font-lock-function-name-face))
+                             (should-not (bnf-test-face-at 9))))
+
+
 (provide 'bnf-mode-font-test)
 
 ;;; bnf-mode-font-test.el ends here



reply via email to

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