1;;
2;; Copyright (c) 2003 by The XFree86 Project, Inc.
3;;
4;; Permission is hereby granted, free of charge, to any person obtaining a
5;; copy of this software and associated documentation files (the "Software"),
6;; to deal in the Software without restriction, including without limitation
7;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
8;; and/or sell copies of the Software, and to permit persons to whom the
9;; Software is furnished to do so, subject to the following conditions:
10;;
11;; The above copyright notice and this permission notice shall be included in
12;; all copies or substantial portions of the Software.
13;;
14;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17;; THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19;; OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20;; SOFTWARE.
21;;
22;; Except as contained in this notice, the name of the XFree86 Project shall
23;; not be used in advertising or otherwise to promote the sale, use or other
24;; dealings in this Software without prior written authorization from the
25;; XFree86 Project.
26;;
27;; Author: Paulo César Pereira de Andrade
28;;
29;;
30;; $XFree86: xc/programs/xedit/lisp/modules/progmodes/rpm.lsp,v 1.1 2003/01/16 03:50:46 paulo Exp $
31;;
32
33(require "syntax")
34(in-package "XEDIT")
35
36;; Only for testing, unifinished, good for viewing but too slow for real use...
37#|
38(defsynprop *prop-rpm-special*
39    "rpm-special"
40    :font	"*courier-bold-r*-12-*"
41    :foreground	"NavyBlue"
42)
43
44(defsynprop *prop-rpm-escape*
45    "rpm-escape"
46    :font	"*lucidatypewriter-medium-r*-12-*"
47    :foreground	"Red3")
48
49;; main package is implicit
50(defsyntax *rpm-mode* :package nil nil nil
51    (syntable :sections nil nil
52	(syntoken "^%package"
53	    :icase t
54	    :switch :package
55	    ;; XXX :begin :package was added just to test finishing and
56	    ;; starting a new syntax-table, unfortunately if using it
57	    ;; this way, frequently the entire file will be reparsed
58	    ;; at every character typed.
59	    ;; TODO study these cases and implement code to avoid it,
60	    ;; the easiest way is limiting the number of backtracked lines,
61	    ;; the screen contents sometimes could not correctly reflect
62	    ;; file contents in this case...
63	    :begin :package
64	    :property *prop-rpm-special*)
65	(syntoken "^%(build|setup|install|pre|preun|post|postun)\\>"
66	    :icase t
67	    :property *prop-rpm-special*
68	    :switch :package
69	    :begin :shell)
70	;; %changelog, XXX no rules to return to the toplevel
71	(syntoken "^%changelog\\>"
72	    :icase t
73	    :switch :package
74	    :begin :changelog
75	    :property *prop-rpm-special*)
76	(syntable :changelog nil nil
77	    ;; ignore if escaped
78	    (syntoken "%%")
79	    ;; "warn" if not escaped
80	    (syntoken "%" :property *prop-control*)
81	    ;; emails
82	    (syntoken "<[a-z0-9_-]+@[a-z0-9_-]+\\.\\w+(\\.\\w+)?>"
83		:icase t
84		:property *prop-string*)
85	)
86	;; comments
87	(syntoken "#" :contained t :nospec t :begin :comment)
88	(syntable :comment *prop-comment* nil
89	    ;; some macros are expanded even when inside comments, and may
90	    ;; cause surprises, "warn" about it
91	    (syntoken "%\\{?\\w+\\}?" :property *prop-rpm-special*)
92	    (syntoken "$" :switch -1)
93	)
94	(synaugment :global)
95    )
96
97    ;; may appear anywhere
98    (syntable :global nil nil
99	;; preprocessor like commands
100	(syntoken "^%(define|if|ifarch|else|endif)\\>"
101	    :icase t
102	    :property *prop-preprocessor*)
103	;; variables
104	(syntoken "%\\{.*\\}" :property *prop-constant*)
105    )
106
107    ;; example: "Group: ..." or "Group(pt_BR): ..."
108    (syntoken "^\\w+(\\(\\w+\\))?:" :property *prop-keyword*)
109
110    ;; for sections with shell commands
111    (syntable :shell nil nil
112	(syntoken "\\<(if|then|elif|else|fi|for|do|done|case|esac|while|until)\\>"
113	    :property *prop-keyword*)
114	(syntable :strings nil nil
115	    (syntoken "\"" :nospec t :begin :string :contained t)
116	    (syntable :string *prop-string* nil
117		(syntoken "\\$\\(?\\w+\\)?" :property *prop-constant*)
118		(syntoken "\\\\.")
119		(syntoken "\"" :nospec t :switch -1)
120	    )
121	    (syntoken "\'" :nospec t :begin :constant :contained t)
122	    (syntable :constant *prop-constant* nil
123		(syntoken "\\\\.")
124		(syntoken "\'" :nospec t :switch -1)
125	    )
126	    (syntoken "\`" :nospec t :begin :escape :contained t)
127	    (syntable :escape *prop-rpm-escape* nil
128		(syntoken "\\$\\(?\\w+\\)?" :property *prop-constant*)
129		(syntoken "\\\\.")
130		(syntoken "\`" :nospec t :switch -1)
131	    )
132	)
133	(synaugment :strings :sections)
134    )
135    (synaugment :sections)
136)
137|#
138
139
140(defsyntax *rpm-mode* :package nil nil nil
141    ;; commands, macro definitions, etc
142    (syntoken "^\\s*%\\s*\\w+" :property *prop-keyword*)
143
144    ;; rpm "variables"
145    (syntoken "%\\{.*\\}" :property *prop-constant*)
146
147    ;; package info, example: "Group: ...", "Group(pt_BR): ...", etc.
148    (syntoken "^\\w+(\\(\\w+\\))?:" :property *prop-preprocessor*)
149
150    ;; comments
151    (syntoken "#" :contained t :nospec t :begin :comment)
152    (syntable :comment *prop-comment* nil
153	;; some macros are expanded even when inside comments, and may
154	;; cause surprises, "warn" about it
155	(syntoken "%define\\>" :property *prop-control*)
156	(syntoken "%\\{?\\w+\\}?" :property *prop-string*)
157	(syntoken "$" :switch -1)
158    )
159
160    ;; emails
161    (syntoken "<?[a-z0-9_-]+@[a-z0-9_-]+\\.\\w+(\\.\\w+)*>?"
162	:icase t
163	:property *prop-string*)
164    ;; links
165    (syntoken "\\<(http|ftp)://\\S+" :property *prop-string*)
166)
167