c903a282d1c3d86885c0f4187339d1196c561e19
[alioth/jupp.git] / syntax / c.jsf.in
1 # $MirOS: contrib/code/jupp/syntax/c.jsf.in,v 1.7 2016/10/07 19:43:56 tg Exp $
2 #-
3 # JOE syntax highlight file for C and C++
4
5 # A (deterministic) state machine which performs lexical analysis of C.
6 # (This is the "assembly language" of syntax highlighting.  A separate
7 # program could be used to convert a regular expression NFA syntax into this
8 # format).
9
10 # Each state begins with ':<name> <color-name>'
11 # <color-name> is the color used for characters eaten by the state
12 # (really a symbol for a user definable color).
13
14 # The first state defined is the initial state.
15
16 # Within a state, define transitions (jumps) to other states.  Each
17 # jump has the form: <character-list> <target-state> [<option>s]
18
19 # There are two ways to specify <character-list>s, either * for any
20 # character not otherwise specified, or a literal list of characters within
21 # quotes (ranges and escape sequences allows).  When the next character
22 # matches any in the list, a jump to the target-state is taken and the
23 # character is eaten (we advance to the next character of the file to be
24 # colored).
25 #
26 # The * transition should be the first transition specified in the state.
27 #
28 # There are several options:
29 #   noeat       do not eat the character, instead feed it to the next state
30 #               (this tends to make the states smaller, but be careful: you
31 #               can make infinite loops).  'noeat' implies 'recolor=-1'.
32 #
33 #   recolor=-N  Recolor the past N characters with the color of the
34 #               target-state.  For example once /* is recognized as the
35 #               start of C comment, you want to color the /* with the C
36 #               comment color.
37 #
38 #   buffer      start copying characters to a buffer, beginning with this
39 #               one (it's ok to not terminate buffering with a matching
40 #               'strings' option- the buffer is limited to leading 19
41 #               characters).
42 #
43 #   strings     A list of strings follows.  If the buffer matches any of the
44 #               given strings, a jump to the target-state in the string list
45 #               is taken instead of the normal jump.
46 #
47 #   istrings    Same as strings, but case is ignored.
48 #
49 #   hold        Stop buffering string- a future 'strings' or 'istrings' will
50 #               look at contents of buffer at this point.  Useful for distinguishing
51 #               commands and function calls in some languages 'write 7' is a command
52 #               'write (' is a function call- hold lets us stop at the space and delay
53 #               the string lookup until the ( or 7.
54 #
55 #   The format of the string list is:
56 #
57 #      "string"   <target-state> [<options>s]
58 #      "string"   <target-state> [<options>s]
59 #      done
60 #
61 #   (all of the options above are allowed except "strings", "istrings" and "noeat".  noeat is
62 #    always implied after a matched string).
63 #
64 # Weirdness: only states have colors, not transitions.  This means that you
65 # sometimes have to make dummy states with '* next-state noeat' just to get
66 # a color specification.
67 #
68 # Encoding: everything is handled as UTF-8 by octets, that is, you can have
69 # individual octets change states (the colour of the last octet applies).
70 # The JSF files themselves must accordingly be encoded in UTF-8. When a raw
71 # octet or an invalid UTF-8 sequence is read, a number of \xFF octets are
72 # matched on.
73
74
75 # Define no. sync lines
76 # You can say:
77 # -200     means 200 lines
78 # -        means always start parsing from beginning of file when we lose sync
79 #          if nothing is specified, the default is -120
80
81 # Always reparse from beginning
82 -
83
84
85 # Define colors
86 #
87 # bold inverse blink dim underline
88 # white cyan magenta blue yellow green red black
89 # bg_white bg_cyan bg_magenta bg_blue bg_yellow bg_green bg_red bg_black
90
91 =Idle
92 =Bad            bold red
93 =Preproc        blue
94 =Define         bold blue
95 =Comment        green
96 =IncLocal       cyan
97 =IncSystem      bold cyan
98 =Constant       cyan
99 =Escape         bold cyan
100 =Type           bold
101 =Keyword        bold
102 =CppKeyword     bold
103 =Brace          magenta
104 =Control
105
106 :reset Idle
107         *               first           noeat
108         " \t"           reset
109
110 :first Idle
111         *               idle            noeat
112         "#"             pre             recolor=-1
113
114 :pre Preproc
115         *               preproc         noeat
116         " \t"           pre
117         "a-z"           preident        recolor=-1 buffer
118
119 :preident Preproc
120         *               preproc         noeat strings
121         "define"        predef
122         "include"       preinc
123 done
124         "a-z"           preident
125
126 :preinc Preproc
127         *               preinc
128         " \t"           preinc_ws
129         "\n"            reset
130
131 :preinc_ws Preproc
132         *               prebad          recolor=-1
133         " \t"           preinc_ws
134         "\""            preinc_local    recolor=-1
135         "<"             preinc_system   recolor=-1
136
137 :preinc_local IncLocal
138         *               preinc_local
139         "\"\n"          reset
140
141 :preinc_system IncSystem
142         *               preinc_system
143         ">\n"           reset
144
145 :prebad Bad
146         *               prebad
147         "\n"            reset
148
149
150 :predef Preproc
151         *               predef
152         " \t"           predef_ws
153         "\n"            reset
154
155 :predef_ws Preproc
156         *               prebad          recolor=-1
157         " \t"           predef_ws
158         "a-zA-Z0-9_"    predef_ident    recolor=-1
159
160 :predef_ident Define
161         *               idle            noeat
162         "a-zA-Z0-9_"    predef_ident
163
164
165 :preproc Preproc
166         *               preproc
167         "\n"            reset
168         "\\"            preproc_cont
169         "/"             preproc_slash
170
171 :preproc_slash Preproc
172         *               preproc         noeat
173         "*"             comment         recolor=-2
174         "/"             line_comment    recolor=-2
175
176 :preproc_cont Preproc
177         *               preproc_cont
178         "\n"            preproc
179
180 # All following states are for when we're not in a preprocessor line
181
182 :idle Idle
183         *               idle
184         "\n"            reset
185         "/"             slash
186         "0"             first_digit     recolor=-1
187         "1-9"           decimal recolor=-1
188         "."             maybe_float
189         "\""            string          recolor=-1
190         "'"             char            recolor=-1
191         "a-zA-Z_"       ident           buffer
192         "{}"            brace           recolor=-1
193         ",:;=()><[]*&|!~+\-%^"  control         recolor=-1
194
195 :brace Brace
196         *       idle    noeat
197
198 :control Control
199         *       idle    noeat
200
201 :slash Idle
202         *               idle            noeat recolor=-2        # Not sure about this
203         "*"             comment         recolor=-2
204         "/"             line_comment    recolor=-2
205
206 :comment Comment
207         *               comment
208         "*"             maybe_end_comment
209
210 :maybe_end_comment Comment
211         *               comment
212         "/"             idle
213         "*"             maybe_end_comment
214
215 :line_comment Comment
216         *               line_comment
217         "\n"            reset
218
219 :first_digit Constant
220         *               idle    noeat
221         "xX"            hex
222         "."             float
223         "eE"            epart
224         "0-7"           octal
225         "89"            bad_number      recolor=-1
226
227 :bad_number Bad
228         *               idle    noeat
229         "0-9"           bad_number
230
231 :octal Constant
232         *               idle    noeat
233         "0-7"           octal
234         "89"            bad_number      recolor=-1
235
236 :hex Constant
237         *               idle    noeat
238         "0-9A-Fa-f"     hex
239
240 :decimal Constant
241         *               idle    noeat
242         "0-9"           decimal
243         "eE"            epart
244         "."             float
245
246 :maybe_float Constant
247         *               idle    recolor=-2      noeat
248         "0-9"           float           recolor=-2
249
250 :float Constant
251         *               idle    noeat
252         "eE"            epart
253         "0-9"           float
254
255 :epart Constant
256         *               idle    noeat
257         "0-9+\-"        enum
258
259 :enum Constant
260         *               idle    noeat
261         "0-9"           enum
262
263 :string Constant
264         *               string
265         "\""            idle
266         "\\"            string_escape   recolor=-1
267         "%"             string_control  recolor=-1
268
269 :string_escape Escape
270         *               string
271         "x"             string_hex1
272         "0-7"           string_octal2
273         "\n"            string          recolor=-2
274
275 :string_hex1 Escape
276         *               string          noeat
277         "0-9a-fA-F"     string_hex2
278
279 :string_hex2 Escape
280         *               string          noeat
281         "0-9a-fA-F"     string
282
283 :string_octal2 Escape
284         *               string          noeat
285         "0-7"           string_octal3
286
287 :string_octal3 Escape
288         *               string          noeat
289         "0-7"           string
290
291 :string_control Escape
292         *               string_control
293         "\""            reset
294         "diouxXeEfFgGaAcspn%SC\n"       string
295         "\\"            string_escape   recolor=-1
296
297 :char Constant
298         *               char
299         "\n"            reset
300         "'"             idle
301         "\\"            char_escape     recolor=-1
302
303 :char_escape    Escape
304         *               char
305         "x"             char_hex1
306         "0-7"           char_octal2
307         "\n"            char            recolor=-2
308
309 :char_hex1 Escape
310         *               char            noeat
311         "0-9a-fA-F"     char_hex2
312
313 :char_hex2 Escape
314         *               char            noeat
315         "0-9a-fA-F"     char
316
317 :char_octal2 Escape
318         *               char            noeat
319         "0-7"           char_octal3
320
321 :char_octal3 Escape
322         *               char            noeat
323         "0-7"           char
324
325 :ident Idle
326         *               idle            noeat strings
327         "int"           type
328         "float"         type
329         "long"          type
330         "short"         type
331         "char"          type
332         "double"        type
333         "signed"        type
334         "unsigned"      type
335         "void"          type
336         "static"        type
337         "register"      type
338         "extern"        type
339         "inline"        type
340         "auto"          type
341         "const"         type
342         "volatile"      type
343         "if"            kw
344         "else"          kw
345         "while"         kw
346         "for"           kw
347         "break"         kw
348         "continue"      kw
349         "do"            kw
350         "case"          kw
351         "default"       kw
352         "switch"        kw
353         "goto"          kw
354         "struct"        kw
355         "enum"          kw
356         "return"        kw
357         "sizeof"        kw
358         "typedef"       kw
359         "union"         kw
360         "asm"           kw
361 # C++ keywords
362         "class"         cppkw
363         "public"        cppkw
364         "private"       cppkw
365         "protected"     cppkw
366         "friend"        cppkw
367         "new"           cppkw
368         "delete"        cppkw
369         "bool"          cppkw
370         "namespace"     cppkw
371         "operator"      cppkw
372         "template"      cppkw
373         "catch"         cppkw
374         "throw"         cppkw
375         "try"           cppkw
376         "typeof"        cppkw
377 done
378         "a-zA-Z0-9_"    ident
379
380 :type Type
381         *       idle    noeat
382
383 :kw Keyword
384         *       idle    noeat
385
386 :cppkw CppKeyword
387         *       idle    noeat