joy-mode.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ;;; joy-mode.el --- major mode for editing Joy source.
  2. ;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
  3. ;;;
  4. ;;; Joy is free software; you can redistribute it and/or modify it under
  5. ;;; the terms of the GNU General Public License as published by the Free
  6. ;;; Software Foundation; either version 3 of the License, or (at your
  7. ;;; option) any later version.
  8. ;;;
  9. ;;; Joy is distributed in the hope that it will be useful, but WITHOUT
  10. ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. ;;; License for more details.
  13. ;;;
  14. ;;; You should have received a copy of the GNU General Public License
  15. ;;; along with Joy. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
  17. ;;; Commentary:
  18. ;; Provides syntax highlighting for the small number of primitive
  19. ;; operators in Joy, as well as for the fundamental datatypes
  20. ;;; Code:
  21. (setq joy-keywords '("DEFINE" "PUBLIC" "PRIVATE" "LIBRA" "HIDE" "END" "IN"))
  22. (setq joy-primitives '("unstack" "display" "include" "logical" "integer"
  23. "string" "choice" "uncons" "infra" "stack" "putch"
  24. "swap" "cons" "char" "list" "dup" "pop"))
  25. (setq joy-keywords-regexp (regexp-opt joy-keywords 'words))
  26. (setq joy-primitives-regexp (regexp-opt joy-primitives 'words))
  27. (setq joy-font-lock-keywords
  28. `("==" ";"
  29. ("\\(\\.\\)[^[:digit:]]" 1)
  30. ("\\([[:graph:]]+\\)[[:blank:]]*==" 1 font-lock-function-name-face)
  31. ("'\\\\?[[:alnum:]]\\([[:digit:]][[:digit:]]\\)?" . font-lock-type-face)
  32. (,joy-keywords-regexp . font-lock-keyword-face)
  33. (,joy-primitives-regexp . font-lock-builtin-face)))
  34. (defvar joy-syntax-table nil "Syntax table for `joy-mode'.")
  35. (setq joy-syntax-table
  36. (let ((synTable (make-syntax-table)))
  37. ;; bash style comment: "# ..."
  38. (modify-syntax-entry ?# "< b" synTable)
  39. (modify-syntax-entry ?\n "> b" synTable)
  40. ;; Mathematic style comment: "(* ... *)"
  41. (modify-syntax-entry ?\( ". 1" synTable)
  42. (modify-syntax-entry ?\) ". 4" synTable)
  43. (modify-syntax-entry ?* ". 23" synTable)
  44. synTable))
  45. ;;;###autoload
  46. (define-derived-mode joy-mode fundamental-mode
  47. "Joy mode"
  48. "Major mode for editing the purely functional,
  49. concatenative programming language Joy."
  50. :syntax-table joy-syntax-table
  51. (setq font-lock-defaults '(joy-font-lock-keywords))
  52. (setq mode-name "joy"))
  53. ;; clear memory. no longer needed
  54. (setq joy-keywords nil)
  55. (setq joy-primitives nil)
  56. (setq joy-keywords-regexp nil)
  57. (setq joy-primitives-regexp nil)
  58. ;; add the mode to the `features' list
  59. (provide 'joy-mode)
  60. ;; Local Variables:
  61. ;; coding: utf-8
  62. ;; End:
  63. ;;; joy-mode.el ends here