1 /* This test file tests kates Lex/Flex highlighting */
2 
3 %option c++
4 %option yyclass="KateTester"
5 %option yylineno
6 
7  /* This is a C(++) comment */
8 
9 /* This one is a lex comment ! */
10 
11 %{
12 #include <iostream>
13 #include "realparser.hpp"
14 using namespace std;
15 %}
16 
17 /* Some definitions */
18 DIGIT    [0-9]
19 LETTER   [_a-zA-Z]
20 
21 %%
22 
23  /* Comment *shall be indented here* */
24 [ \t\n\r]+
25 
26  /* Note: there is a bad } just here     vvv */
27 \/\*([^\*]|\*[^/])*\*\/ { foo(a, b, c); } }
28 
29  /* A start condition scope... */
30 <ESC>{
31   "a" {
32 
33   /* C mode ! */
34   return 0;
35 }
36 
37   "b" %{
38 
39   /* C mode, too ! */
40   return 0;
41 %}
42 
43   "c" return 0; // C++ comment
44 }
45 
46  /* Big rule */
47 \"([^"\\]|\\.)*\" {
48 
49    yylval.string_val = new char[strlen(yytext) + 1];
50    int j = 0, i = 1;
51 
52    while (yytext[i] != '"')
53       if (yytext[i] != '\\')
54          yylval.string_val[j++] = yytext[i++];
55       else
56          switch (yytext[i + 1])
57          {
58          case 'n':
59             yylval.string_val[j++] = '\n'; i += 2;
60             break;
61          default:
62             yylval.string_val[j++] << yytext[i + 1], i += 2;
63          }
64 
65     yylval.string_val[j] = 0;
66     return TOK_STRING;
67 
68 }
69 
70  /* Dot (match all) */
71 .             {return yylval.int_val = yytext[0];}
72 
73 %%
74 
75 // Here is pure C(++)
76 #include <iostream>
77 
78 int main(void)
79 {
80   std::cout << "Hello, World\n";
81   return 0;
82 }
83