Add a patch from Josh Zenker to fix perl highlight
[enscript.git] / states / hl / cpp.st
1 /**
2  * Name: cpp
3  * Description: C++ programming language.
4  * Author: Markku Rossi <mtr@iki.fi>
5  */
6
7 cpp_type_re =
8 /* Types.
9    (build-re '(alignas alignof and and_eq asm auto bitand bitor bool
10    break case catch char char16_t char32_t class compl const constexpr
11    const_cast continue decltype default delete do double dynamic_cast
12    else enum explicit export extern false float for friend goto if
13    inline int long mutable namespace new noexcept not not_eq nullptr
14    operator or or_eq private protected public register
15    reinterpret_cast return short signed sizeof static static_assert
16    static_cast struct switch template this thread_local throw true try
17    typedef typeid typename union unsigned using virtual void volatile
18    wchar_t while xor xor_eq))
19   */
20   /\\b(a(lign(as|of)|nd(|_eq)|sm|uto)|b(it(and|or)|ool|reak)\\
21 |c(a(se|tch)|har(|16_t|32_t)|lass|o(mpl|n(st(|_cast|expr)|tinue)))\\
22 |d(e(cltype|fault|lete)|o(|uble)|ynamic_cast)\\
23 |e(lse|num|x(p(licit|ort)|tern))|f(alse|loat|or|riend)|goto\\
24 |i(f|n(line|t))|long|mutable|n(amespace|ew|o(except|t(|_eq))|ullptr)\\
25 |o(perator|r(|_eq))|p(r(ivate|otected)|ublic)\\
26 |re(gister|interpret_cast|turn)\\
27 |s(hort|i(gned|zeof)|t(atic(|_(assert|cast))|ruct)|witch)\\
28 |t(emplate|h(is|r(ead_local|ow))|r(ue|y)|ype(def|id|name))\\
29 |u(n(ion|signed)|sing)|v(irtual|o(id|latile))|w(char_t|hile)|xor(|_eq))\b/;
30
31 /*
32  * We inherit the C++ state from the C state.  This gives us all the
33  * defaults, etc.  All we have to do here is to overwrite things that
34  * are not implemented, or are broken.
35  */
36 state cpp extends c
37 {
38   BEGIN {
39     /* See `c.st' for the comments on this one. */
40     type_re = cpp_type_re;
41   }
42
43   /* One line comments. */
44   /\/\// {
45     comment_face (true);
46     language_print ($0);
47     call (eat_one_line);
48     comment_face (false);
49   }
50
51   /* Keywords; those missing from C, but not types, goto, or case
52      (build-re '(asm catch delete new operator overload this throw try))
53   */
54   /\b(asm|catch|delete|new|o(perator|verload)|t(h(is|row)|ry))\b/ {
55     keyword_face (true);
56     language_print ($0);
57     keyword_face (false);
58   }
59
60   /* Types. */
61   cpp_type_re {
62     type_face (true);
63     language_print ($0);
64     type_face (false);
65   }
66
67   /* Remove false labels. */
68   /[a-zA-Z0-9_]+::/ {
69     language_print ($0);
70   }
71
72   /* Labels.  Emacs accepts also bare numbers. */
73   /^([ \t]*)([a-zA-Z0-9_]+)(:)/ {
74     language_print ($1);
75
76     if (strcmp ($2, "public") == 0
77         || strcmp ($2, "private") == 0
78         || strcmp ($2, "protected") == 0)
79       {
80         /* These use the `type' face. */
81         type_face (true);
82         language_print ($2);
83         type_face (false);
84       }
85     else
86       {
87         reference_face (true);
88         language_print ($2);
89         reference_face (false);
90       }
91
92     language_print ($3);
93   }
94
95   /*
96    * Function definitions, but only if you code with the one and only
97    * usable indentation style (GNU).
98    */
99   /^([a-zA-Z_][a-zA-Z_0-9:~]*)([ \t]*\()/ {
100     function_name_face (true);
101     language_print ($1);
102     function_name_face (false);
103
104     language_print ($2);
105   }
106
107   /* Function definitions and prototypes for other (loser) coding styles. */
108   /^([A-Za-z][a-zA-Z0-9_\&\* ]+)([ \*])([a-zA-Z_][a-zA-Z_0-9:~]*)([ \t]*\()/ {
109     garbage = $1;
110     middle_garbage = $2;
111     function_name = $3;
112     tail_garbage = $4;
113
114     highlight_types (garbage, cpp_type_re);
115
116     language_print (middle_garbage);
117
118     function_name_face (true);
119     language_print (function_name);
120     function_name_face (false);
121
122     language_print (tail_garbage);
123   }
124 }
125
126 \f
127 /*
128 Local variables:
129 mode: c
130 End:
131 */