branch: externals/bnf-mode commit a53ade1cc6c9deeaa5a2e7558af75857bff2773f Author: Serghei Iakovlev <serg...@phalconphp.com> Commit: Serghei Iakovlev <serg...@phalconphp.com>
Fixed BNF rule name definition to follow ALGOL 60 report --- CHANGELOG.org | 6 +++++- README.org | 5 +++-- bnf-mode.el | 53 +++++++++++++++++++++++++--------------------- test/bnf-mode-font-test.el | 28 ++++++++++++++++++------ test/test-helper.el | 2 +- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 4704a7a..c2fcffb 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [[http://keepachangelog.com][Keep a Changelog]] and this project adheres to [[http://semver.org][Semantic Versioning]]. -** [[https://github.com/sergeyklay/bnf-mode/compare/0.3.0...HEAD][Unreleased]] +** [[https://github.com/sergeyklay/bnf-mode/compare/0.3.1...HEAD][Unreleased]] +** [[https://github.com/sergeyklay/bnf-mode/compare/0.3.0...0.3.1][0.3.1]] - 2019-03-17 +*** Fixed +- Fixed BNF rule name definition to follow [[https://www.masswerk.at/algol60/report.htm][ALGOL 60 report]] + ** [[https://github.com/sergeyklay/bnf-mode/compare/0.2.0...0.3.0][0.3.0]] - 2019-03-17 *** Changed - LHS nonterminals may be preceded by an unlimited number of spaces diff --git a/README.org b/README.org index 7d74e9e..04d3d0c 100644 --- a/README.org +++ b/README.org @@ -18,8 +18,8 @@ EBNF and ABNF are not supported but in my plans for the near future. When developing this mode, the following RFCs were taken into account: -- [[https://www.ietf.org/rfc/rfc822.txt][RFC822]]: Standard for ARPA Internet Text Messages -- [[https://www.ietf.org/rfc/rfc5234.txt][RFC5234]]: Augmented BNF for Syntax Specifications: ABNF +- [[https://tools.ietf.org/html/rfc822][RFC822]]: Standard for ARPA Internet Text Messages +- [[https://tools.ietf.org/html/rfc5234][RFC5234]]: Augmented BNF for Syntax Specifications: ABNF - [[https://tools.ietf.org/html/rfc7405][RFC7405]]: Case-Sensitive String Support in ABNF ** Features @@ -89,6 +89,7 @@ To see what has changed in recent versions of BNF Mode, see the [[https://github ** External Links +- [[https://www.masswerk.at/algol60/report.htm][Revised Report on the Algorithmic Language Algol 60]] - [[https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form][Wikipedia: Backus–Naur form]] - [[https://en.wikipedia.org/wiki/Extended_Backus%25E2%2580%2593Naur_form][Wikipedia: Extended Backus–Naur form]] - [[https://en.wikipedia.org/wiki/Augmented_Backus%25E2%2580%2593Naur_form][Wikipedia: Augmented Backus–Naur form]] diff --git a/bnf-mode.el b/bnf-mode.el index 2902ada..4f1ba12 100644 --- a/bnf-mode.el +++ b/bnf-mode.el @@ -4,7 +4,7 @@ ;; Author: Serghei Iakovlev (concat "sadhooklay" "@" "gmail" ".com") ;; Maintainer: Serghei Iakovlev -;; Version: 0.4.0 +;; Version: 0.3.1 ;; URL: https://github.com/sergeyklay/bnf-mode ;; Keywords: languages ;; Package-Requires: ((cl-lib "0.5") (pkg-info "0.4") (emacs "24.3")) @@ -39,10 +39,12 @@ ;; - RFC822: Standard for ARPA Internet Text Messages [1] ;; - RFC5234: Augmented BNF for Syntax Specifications: ABNF [2] ;; - FRC7405: Case-Sensitive String Support in ABNF [3] +;; - Revised Report on the Algorithmic Language Algol 60 [4] ;; ;; [1]: https://www.ietf.org/rfc/rfc822.txt ;; [2]: https://www.ietf.org/rfc/rfc5234.txt ;; [3]: https://www.ietf.org/rfc/rfc7405.txt +;; [4]: https://www.masswerk.at/algol60/report.htm ;; ;; Usage: Put this file in your Emacs Lisp path (eg. site-lisp) and add to ;; your .emacs file: @@ -114,11 +116,12 @@ just return nil." (eval-when-compile (defconst bnf-rx-constituents `( - (bnf-rule-name . ,(rx (and - symbol-start - letter - (0+ (or "-" alnum)) - symbol-end))) + (bnf-rule-name . ,(rx + (and + (1+ (or alnum digit)) + (0+ (or alnum digit + (in "!\"\#$%&'()*+,\-./:;=?@\[\\\]^_`{|}~") + (in " \t")))))) "Additional special sexps for `bnf-rx'.")) (defmacro bnf-rx (&rest sexps) @@ -128,11 +131,10 @@ In addition to the standard forms of `rx', the following forms are available: `bnf-rule-name' - Any valid BNF 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 examle see RFC5234#2.1 + Any valid BNF rule name. This rule was obtained by studying + ALGOL 60 report, where the BNF was officially announced. + Please note: This rule is not suitable for ABNF or EBNF + (see URL `https://www.masswerk.at/algol60/report.htm'). See `rx' documentation for more information about REGEXPS param." (let ((rx-constituents (append bnf-rx-constituents rx-constituents))) @@ -207,23 +209,26 @@ See `rx' documentation for more information about REGEXPS param." "A major mode for editing BNF grammars." :syntax-table bnf-mode-syntax-table :group 'bnf-mode - ;; Comment setup (for more see RFC822#2.8) + + ;; Comments setup. (setq-local comment-use-syntax nil) (setq-local comment-start "; ") (setq-local comment-end "") - (setq-local font-lock-keyword-face 'php-keyword) + ;; Font locking - (setq font-lock-defaults '( - ;; Keywords - bnf-font-lock-keywords - ;; keywords-only - nil - ;; Regarding to RFC5234#2.1 rule names are case - ;; insensitive. The names <rulename>, <Rulename>, - ;; <RULENAME>, and <rUlENamE> all refer to the - ;; same rule. - t - ))) + (setq font-lock-defaults + '( + ;; Keywords + bnf-font-lock-keywords + ;; keywords-only + nil + ;; Regarding to RFC5234 rule names are case insensitive. + ;; The names <rulename>, <Rulename>, <RULENAME>, and <rUlENamE> + ;; all refer to the same rule. As far as is known, this doesn't + ;; conflict with original BNF version + ;; (see URL `https://tools.ietf.org/html/rfc5234') + t + ))) ;; Invoke bnf-mode when appropriate diff --git a/test/bnf-mode-font-test.el b/test/bnf-mode-font-test.el index 096bd94..727e147 100644 --- a/test/bnf-mode-font-test.el +++ b/test/bnf-mode-font-test.el @@ -4,7 +4,7 @@ ;; Author: Serghei Iakovlev (concat "sadhooklay" "@" "gmail" ".com") ;; Maintainer: Serghei Iakovlev -;; Version: 0.4.0 +;; Version: 0.3.1 ;; URL: https://github.com/sergeyklay/bnf-mode ;; This file is not part of GNU Emacs. @@ -121,20 +121,36 @@ angle-brackets ::= are-optional" (ert-deftest bnf-mode-syntax-table/fontify-alternatives () :tags '(fontification syntax-table) (bnf-test-with-temp-buffer "<foo> | <bar> | <baz>" - ;; foo + ;; “foo” (should (eq (bnf-test-face-at 2) 'font-lock-builtin-face)) (should (eq (bnf-test-face-at 4) 'font-lock-builtin-face)) - ;; | + ;; “|” (should (eq (bnf-test-face-at 7) 'font-lock-warning-face)) - ;; bar + ;; “bar” (should (eq (bnf-test-face-at 10) 'font-lock-builtin-face)) (should (eq (bnf-test-face-at 12) 'font-lock-builtin-face)) - ;; | + ;; “|” (should (eq (bnf-test-face-at 15) 'font-lock-warning-face)) - ;; baz + ;; “baz” (should (eq (bnf-test-face-at 18) 'font-lock-builtin-face)) (should (eq (bnf-test-face-at 20) 'font-lock-builtin-face)))) +(ert-deftest bnf-mode-syntax-table/fontify-rule-punctuation () + :tags '(fontification syntax-table) + (bnf-test-with-temp-buffer" +<proper string> ::= + <any sequence of symbols not containing ` or ' > + | <empty>" + ;; “proper string” + (should (eq (bnf-test-face-at 3) 'font-lock-function-name-face)) + (should (eq (bnf-test-face-at 15) 'font-lock-function-name-face)) + ;; “any sequence of symbols not containing ` or ' ” + (should (eq (bnf-test-face-at 31) 'font-lock-builtin-face)) + (should (eq (bnf-test-face-at 76) 'font-lock-builtin-face)) + ;; “empty” + (should (eq (bnf-test-face-at 90) 'font-lock-builtin-face)) + (should (eq (bnf-test-face-at 94) 'font-lock-builtin-face)))) + (provide 'bnf-mode-font-test) ;;; bnf-mode-font-test.el ends here diff --git a/test/test-helper.el b/test/test-helper.el index 887675b..6227629 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -4,7 +4,7 @@ ;; Author: Serghei Iakovlev (concat "sadhooklay" "@" "gmail" ".com") ;; Maintainer: Serghei Iakovlev -;; Version: 0.4.0 +;; Version: 0.3.1 ;; URL: https://github.com/sergeyklay/bnf-mode ;; This file is not part of GNU Emacs.