Initial layout of opossum package.
[cl-opossum.git] / peg-mode.el
blob84305ebb6793062eb0a1d8fe6807e44186a3afa3
1 ;;; peg-mode.el --- emacs mode for editing PEG grammar files
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
5 ;; Author: Utz-Uwe Haus <haus@juist.math.uni-magdeburg.de>
6 ;; Keywords: data
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;;; Commentary:
24 ;; This file provides a major mode for editing PEG grammar files.
25 ;; It includes font-lock definitions and commands for
26 ;; controlling indentation, re-indenting by subdivisions.
28 ;; To use, put the following in your .emacs:
30 ;; (autoload 'peg-mode "peg-mode" "Mode for editing PEG grammar files" t)
32 ;; You may also want something like:
34 ;; (setq auto-mode-alist
35 ;; (append '(("\\.peg$" . peg-mode))
36 ;; auto-mode-alist))
38 ;;
40 ;;; Code:
41 (defconst peg-version "0"
42 "`peg-mode' version number.")
44 (require 'custom)
46 (defgroup peg nil
47 "Support for editing PEG grammar files."
48 :group 'languages)
50 (defcustom peg-mode-hook nil
51 "*Hook to be run when `peg-mode' is entered."
52 :type 'hook
53 :group 'peg)
56 ;; Non-customizable
57 (defconst peg-comment-re "#"
58 "Regexp that starts a comment line.")
61 ;; Utils
64 ;; code
67 ;; major-mode stuff
68 (defvar peg-mode-abbrev-table nil
69 "Abbreviation table used in `peg-mode' buffers.")
70 (define-abbrev-table 'peg-mode-abbrev-table ())
72 (defvar peg-mode-syntax-table nil
73 "Syntax table used in `peg-mode' buffers.")
74 (if peg-mode-syntax-table
75 nil
76 (setq peg-mode-syntax-table (make-syntax-table)))
77 (modify-syntax-entry ?# "<" peg-mode-syntax-table)
78 (modify-syntax-entry ?\n ">" peg-mode-syntax-table)
79 (modify-syntax-entry ?( "()" peg-mode-syntax-table)
80 (modify-syntax-entry ?[ "|" peg-mode-syntax-table)
81 (modify-syntax-entry ?] "|" peg-mode-syntax-table)
82 (modify-syntax-entry ?\" "\"" peg-mode-syntax-table)
83 (modify-syntax-entry ?' "|" peg-mode-syntax-table)
87 ;;;###autoload
88 (defun peg-mode ()
89 "Major mode for editing xrdb config files"
90 (interactive)
91 (kill-all-local-variables)
92 (set-syntax-table peg-mode-syntax-table)
93 (setq major-mode 'peg-mode
94 mode-name "peg"
95 local-abbrev-table peg-mode-abbrev-table)
96 ;(use-local-map peg-mode-map)
97 (setq font-lock-defaults '(peg-font-lock-keywords))
98 ;; local variables
99 (make-local-variable 'parse-sexp-ignore-comments)
100 (make-local-variable 'comment-start-skip)
101 (make-local-variable 'comment-start)
102 (make-local-variable 'comment-end)
103 (make-local-variable 'paragraph-start)
104 (make-local-variable 'paragraph-separate)
105 (make-local-variable 'paragraph-ignore-fill-prefix)
106 (make-local-variable 'indent-region-function)
107 ;; now set their values
108 (setq parse-sexp-ignore-comments t
109 comment-start-skip "![ \t]*"
110 comment-start "! "
111 comment-end "")
112 (setq indent-region-function 'peg-indent-region
113 paragraph-ignore-fill-prefix t
114 paragraph-start (concat "^[ \t]*$\\|^[ \t]*[!]\\|" page-delimiter)
115 paragraph-separate paragraph-start)
116 (run-hooks 'peg-mode-hook))
118 ;; faces and font-locking
119 (defvar peg-rule-name-face 'peg-rule-name-face
120 "Face for a production of a PEG rule's production in a peg grammar file.")
123 (make-face 'peg-rule-name-face)
124 ;(make-face 'xrdb-option-value-face)
126 (defun peg-font-lock-mode-hook ()
127 (or (face-differs-from-default-p 'peg-rule-name-face)
128 (copy-face 'font-lock-keyword-face 'peg-rule-name-face))
129 (remove-hook 'font-lock-mode-hook 'peg-font-lock-mode-hook))
130 (add-hook 'font-lock-mode-hook 'peg-font-lock-mode-hook)
132 (defvar peg-font-lock-keywords
133 (list '("\\([^ \t\n]+\\)[ \t]*<-"
134 (1 peg-rule-name-face))
136 "Additional expressions to highlight in peg grammar file mode.")
137 (put 'peg-mode 'font-lock-defaults '(peg-font-lock-keywords))
140 (provide 'peg-mode)
141 ;;; peg-mode.el ends here