Diff of /syntax/c.jsf.in [000000] .. [409b67] Maximize Restore

  Switch to unified view

a b/syntax/c.jsf.in
1
# JOE syntax highlight file for C and C++
2
3
# A (deterministic) state machine which performs lexical analysis of C.
4
# (This is the "assembly language" of syntax highlighting.  A separate
5
# program could be used to convert a regular expression NFA syntax into this
6
# format).
7
8
# Each state begins with ':<name> <color-name>'
9
# <color-name> is the color used for characters eaten by the state
10
# (really a symbol for a user definable color).
11
12
# The first state defined is the initial state.
13
14
# Within a state, define transitions (jumps) to other states.  Each
15
# jump has the form: <character-list> <target-state> [<option>s]
16
17
# There are three ways to specify <character-list>s, either * for any
18
# character not otherwise specified, & to match the character in the
19
# delimiter match buffer or a literal list of characters within quotes
20
# (ranges and escape sequences allowed).  When the next character matches
21
# any in the list, a jump to the target-state is taken and the character is
22
# eaten (we advance to the next character of the file to be colored).
23
#
24
# The * transition should be the first transition specified in the state.
25
#
26
# There are several options:
27
#   noeat         do not eat the character, instead feed it to the next state
28
#                 (this tends to make the states smaller, but be careful: you
29
#     can make infinite loops).  'noeat' implies 'recolor=-1'.
30
#
31
#   recolor=-N    Recolor the past N characters with the color of the
32
#     target-state.  For example once /* is recognized as the
33
#     start of C comment, you want to color the /* with the C
34
#     comment color with recolor=-2.
35
#
36
#   mark  Mark beginning of a region with current position.
37
#
38
#   markend   Mark end of region.
39
#
40
#   recolormark Recolor all of the characters in the marked region with
41
#               the color of the target-state.  If markend is not given,
42
#     all of the characters up to the current position are recolored.
43
#     Note that the marked region can not cross line boundaries and
44
#               must be on the same line as recolormark.
45
#
46
#   buffer        start copying characters to a string buffer, beginning with this
47
#     one (it's ok to not terminate buffering with a matching
48
#     'strings' option- the buffer is limited to leading 23
49
#     characters).
50
#
51
#   save_c      Save character in delimiter match buffer.
52
#
53
#   save_s      Copy string buffer to delimiter match buffer.
54
#
55
#   strings   A list of strings follows.  If the buffer matches any of the
56
#     given strings, a jump to the target-state in the string list
57
#     is taken instead of the normal jump.
58
#
59
#   istrings  Same as strings, but case is ignored.
60
#
61
#               Note: strings and istrings should be the last option on the
62
#     line.  They cause any options which follow them to be ignored.
63
#
64
#   hold        Stop buffering string- a future 'strings' or 'istrings' will
65
#               look at contents of buffer at this point.  Useful for distinguishing
66
#               commands and function calls in some languages 'write 7' is a command
67
#               'write (' is a function call- hold lets us stop at the space and delay
68
#               the string lookup until the ( or 7.
69
#
70
#   The format of the string list is:
71
#
72
#      "string"   <target-state> [<options>s]
73
#      "string"   <target-state> [<options>s]
74
#      "&"        <target-state> [<options>s]   # matches contents of delimiter match buffer
75
#      done
76
#
77
#   (all of the options above are allowed except "strings", "istrings" and "noeat".  noeat is
78
#    always implied after a matched string).
79
#
80
# Weirdness: only states have colors, not transitions.  This means that you
81
# sometimes have to make dummy states with '* next-state noeat' just to get
82
# a color specification.
83
#
84
# Delimiter match buffer is for perl and shell: a regex in perl can be s<..>(...)
85
# and in shell you can say: <<EOS ....... EOS
86
87
# New feature: subroutines
88
89
# Highlighter state machines can now make subroutine calls.  This works by
90
# template instantiation: the called state machine is included in your
91
# current state machine, but is modified so that the return address points
92
# to the called.  There is still no run-time stack (the state is represented
93
# as a single integer plus the saved delimiter string).
94
95
# Recursion is allowed, but is self limited to 5 levels.
96
97
# To call a subroutine, use the 'call' option:
98
#
99
# "\""    fred    call=string(dquote)
100
#
101
# The subroutine called 'string' is called and the jump to 'fred' is
102
# ignored.  The 'dquote' option is passed to the subroutine.
103
#
104
# The subroutine itself returns to the caller like this:
105
#       "\""  whatever  return
106
#
107
# If we're in a subroutine, the return is made.  Otherwise the jump
108
# to 'whatever' is made.
109
#
110
# There are several ways of delimiting subroutines which show up in how it
111
# is called.  Here are the options:
112
#
113
# call=string()         A file called string.jsf is the subroutine.
114
#                         The entire file is the subroutine.  The starting
115
#                         point is the first state in the file.
116
#
117
# call=library.string()     A file called library.jsf has the subroutine.
118
#                         The subroutine within the file is called string.
119
#
120
# call=.string()          There is a subroutine called string in the current file.
121
#
122
# When a subroutine is within a file, but is not the whole file, it is delimited
123
# as follows:
124
#
125
#  .subr string
126
#
127
#  . . . states for string subroutine . . .
128
#
129
#  .end
130
#
131
# Option flags can be passed to subroutines which control preprocessor-like
132
# directives.  For example:
133
#
134
# .ifdef dquote
135
#    "\"" idle    return
136
# .endif
137
# .ifdef squote
138
#    "'"  idle    return
139
# .endif
140
#
141
# .else if also available.  .ifdefs can be nested.
142
143
144
# Obsolete feature: the sync lines specification no longer matter.  We now always parse
145
# from the beginning of the file.  Here is the old description:
146
#
147
# Define no. sync lines
148
# You can say:
149
# -200     means 200 lines
150
# -        means always start parsing from beginning of file when we lose sync
151
#          if nothing is specified, the default is -50
152
-
153
154
# Define colors and attributes.  Give a list of attributes, one
155
# background color and one foreground color (default is used if
156
# color is left out).
157
#
158
# Attributes:
159
#   bold inverse blink dim underline
160
#
161
# Standard colors:
162
#
163
# Foreground:
164
#   white cyan magenta blue yellow green red black
165
#
166
# Background:
167
#   bg_white bg_cyan bg_magenta bg_blue bg_yellow bg_green bg_red bg_black
168
#
169
# For 16 color and 256 color xterms: "export TERM=xterm-16color", these
170
# brighter than normal colors are available:
171
#
172
# Note that you need an xterm which was compiled to support 16 or 256 colors
173
# and a matching termcap/terminfo entry for it.
174
#
175
# Foreground:
176
#   WHITE CYAN MAGENTA BLUE YELLOW GREEN RED BLACK
177
#
178
# Background:
179
#   bg_WHITE bg_CYAN bg_MAGENTA bg_BLUE bg_YELLOW bg_GREEN bg_RED bg_BLACK
180
#
181
# For 256 color xterm: "export TERM=xterm-256color", these become available:
182
#
183
# Note that you need an xterm which was compiled to support 256 colors and a
184
# matching termcap/terminfo entry for it.
185
#
186
# fg_RGB and bg_RGB, where R, G, and B range from 0 - 5.  So: fg_500 is bright red.
187
#
188
# fg_NN and bg_NN give shades of grey, where the intensity, NN, ranges from 0 - 23.
189
190
=Idle
191
=Bad      bold red
192
=Preproc  blue
193
=Define       bold blue
194
=Comment  green
195
=IncLocal cyan
196
=IncSystem    bold cyan
197
=Constant     cyan
198
=Escape   bold cyan
199
=Type         bold
200
=Keyword  bold
201
=CppKeyword   bold
202
=Brace        magenta
203
=Control
204
205
:reset Idle
206
  *       first       noeat
207
  " \t"       reset
208
209
:first Idle
210
  *       idle        noeat
211
  "#"     pre     recolor=-1
212
213
:pre Preproc
214
  *       preproc     noeat
215
  " \t"       pre
216
  "a-z"       preident    recolor=-1 buffer
217
218
:preident Preproc
219
  *       preproc     noeat strings
220
  "define"    predef
221
  "include"   preinc
222
done
223
  "a-z"       preident
224
225
:preinc Preproc
226
  *       preinc
227
  " \t"       preinc_ws
228
  "\n"        reset
229
  
230
:preinc_ws Preproc
231
  *       prebad      recolor=-1
232
  " \t"       preinc_ws
233
  "\""        preinc_local    recolor=-1
234
  "<"     preinc_system   recolor=-1
235
236
:preinc_local IncLocal
237
  *       preinc_local
238
  "\"\n"      reset
239
  
240
:preinc_system IncSystem
241
  *       preinc_system
242
  ">\n"       reset
243
244
:prebad   Bad 
245
  *       prebad
246
  "\n"        reset
247
248
249
:predef Preproc
250
  *       predef
251
  " \t"       predef_ws
252
  "\n"        reset
253
  
254
:predef_ws Preproc
255
  *       prebad      recolor=-1
256
  " \t"       predef_ws
257
  "a-zA-Z0-9_"    predef_ident    recolor=-1
258
259
:predef_ident Define
260
  *       idle        noeat
261
  "a-zA-Z0-9_"    predef_ident
262
263
264
:preproc Preproc
265
  *       preproc
266
  "\n"        reset
267
  "\\"        preproc_cont
268
  "/"     preproc_slash
269
  
270
:preproc_slash Preproc
271
  *       preproc     noeat
272
  "*"     comment     recolor=-2
273
  "/"     line_comment    recolor=-2
274
  
275
:preproc_cont Preproc
276
  *       preproc_cont
277
  "\n"        preproc
278
279
# All following states are for when we're not in a preprocessor line
280
281
:idle Idle
282
  *       idle
283
  "\n"        reset
284
  "/"     slash
285
  "0"     first_digit recolor=-1
286
  "1-9"       decimal recolor=-1
287
  "."     maybe_float
288
  "\""        string      recolor=-1
289
  "'"     char        recolor=-1
290
  "a-zA-Z_"   ident       buffer
291
  "\\"        outside_escape  recolor=-1
292
  "{}"        brace       recolor=-1
293
  ",:;=()><[]*&|!~+\-%^"  control     recolor=-1
294
295
:outside_escape   Escape
296
  *   idle
297
298
:brace Brace
299
  *   idle    noeat
300
301
:control Control
302
  *   idle    noeat
303
304
:slash Idle
305
  *       idle        noeat recolor=-2    # Not sure about this
306
  "*"     comment     recolor=-2
307
  "/"     line_comment    recolor=-2
308
309
:comment Comment
310
  *       comment
311
  "*"     maybe_end_comment
312
313
:maybe_end_comment Comment
314
  *       comment
315
  "/"     idle
316
  "*"     maybe_end_comment
317
318
:line_comment Comment
319
  *       line_comment
320
  "\n"        reset
321
322
:first_digit Constant
323
  *       idle    noeat
324
  "xX"        hex
325
  "."     float
326
  "eE"        epart
327
  "0-7"       octal
328
  "89"        bad_number  recolor=-1
329
330
:bad_number Bad
331
  *       idle    noeat
332
  "0-9"       bad_number
333
334
:octal Constant
335
  *       idle    noeat
336
  "0-7"       octal
337
  "89"        bad_number  recolor=-1
338
339
:hex Constant
340
  *       idle    noeat
341
  "0-9A-Fa-f" hex
342
343
:decimal Constant
344
  *       idle    noeat
345
  "0-9"       decimal
346
  "eE"        epart
347
  "."     float
348
349
:maybe_float Constant
350
  *       idle    recolor=-2  noeat
351
  "0-9"       float       recolor=-2
352
353
:float Constant
354
  *       idle    noeat
355
  "eE"        epart
356
  "0-9"       float
357
358
:epart Constant
359
  *       idle    noeat
360
  "0-9+\-"    enum
361
362
:enum Constant
363
  *       idle    noeat
364
  "0-9"       enum
365
366
:string   Constant
367
  *       string
368
  "\""        idle
369
  "\\"        string_escape   recolor=-1
370
  "%"     string_control  recolor=-1
371
372
:string_escape Escape
373
  *       string
374
  "x"     string_hex1
375
  "0-7"       string_octal2
376
  "\n"        string      recolor=-2
377
378
:string_hex1 Escape
379
  *       string      noeat
380
  "0-9a-fA-F" string_hex2
381
382
:string_hex2 Escape
383
  *       string      noeat
384
  "0-9a-fA-F" string
385
386
:string_octal2 Escape
387
  *       string      noeat
388
  "0-7"       string_octal3
389
390
:string_octal3 Escape
391
  *       string      noeat
392
  "0-7"       string
393
394
:string_control Escape
395
  *       string
396
  "\""        string noeat
397
  "\n"        reset
398
  "0-9.\-+ #hjILtz$"  string_control
399
400
:char Constant
401
  *       char
402
  "\n"        reset
403
  "'"     idle
404
  "\\"        char_escape recolor=-1
405
406
:char_escape  Escape
407
  *       char
408
  "x"     char_hex1
409
  "0-7"       char_octal2
410
  "\n"        char        recolor=-2
411
412
:char_hex1 Escape
413
  *       char        noeat
414
  "0-9a-fA-F" char_hex2
415
416
:char_hex2 Escape
417
  *       char        noeat
418
  "0-9a-fA-F" char
419
420
:char_octal2 Escape
421
  *       char        noeat
422
  "0-7"       char_octal3
423
424
:char_octal3 Escape
425
  *       char        noeat
426
  "0-7"       char
427
428
:ident Idle
429
  *       idle        noeat strings
430
  "int"       type
431
  "float"     type
432
  "long"      type
433
  "short"     type
434
  "char"      type
435
  "double"    type
436
  "signed"    type
437
  "unsigned"  type
438
  "void"      type
439
  "static"    type
440
  "register"  type
441
  "extern"    type
442
  "inline"    type
443
  "auto"      type
444
  "const"     type
445
  "volatile"  type
446
  "if"        kw
447
  "else"      kw
448
  "while"     kw
449
  "for"       kw
450
  "break"     kw
451
  "continue"  kw
452
  "do"        kw
453
  "case"      kw
454
  "default"   kw
455
  "switch"    kw
456
  "goto"      kw
457
  "struct"    kw
458
  "enum"      kw
459
  "return"    kw
460
  "sizeof"    kw
461
  "typedef"   kw
462
  "union"     kw
463
  "asm"       kw
464
# C++ keywords
465
  #"asm"          cppkw (listed above as a C keyword)
466
  "bool"          cppkw
467
  "catch"         cppkw
468
  "class"         cppkw
469
  "const_cast"        cppkw
470
  "delete"        cppkw
471
  "dynamic_cast"      cppkw
472
  "explicit"      cppkw
473
  "false"         cppkw
474
  "friend"        cppkw
475
  #"inline"       cppkw (listed above as a C keyword)
476
  "mutable"       cppkw
477
  "namespace"     cppkw
478
  "new"           cppkw
479
  "operator"      cppkw
480
  "private"       cppkw
481
  "protected"     cppkw
482
  "public"        cppkw
483
  "reinterpret_cast"  cppkw
484
  "static_cast"       cppkw
485
  "template"      cppkw
486
  "this"          cppkw
487
  "throw"         cppkw
488
  "true"          cppkw
489
  "try"           cppkw
490
  "typeid"        cppkw
491
  "typename"      cppkw
492
  "using"         cppkw
493
  "virtual"       cppkw
494
  "wchar_t"       type
495
# Non-Standard
496
  "typeof"        cppkw
497
done
498
  "a-zA-Z0-9_"    ident
499
500
:type Type
501
  *   idle    noeat
502
503
:kw Keyword
504
  *   idle    noeat
505
506
:cppkw CppKeyword
507
  *   idle    noeat