1 %option prefix="comment_lexer"
2 
3 %{
4     #include "Assignment.h"
5     #include "expression.h"
6     #include "value.h"
7     #include "comment_parser.hxx"
8     #include <boost/lexical_cast.hpp>
9     YY_BUFFER_STATE yy_scan_string ( const char *str ) ;
10     std::string stringcon;
11 
12     //isatty for visual c++ and mingw-cross-env
13     #if defined __WIN32__ && ! defined _MSC_VER
14     #include "unistd.h"
15     #endif
16     #if defined __WIN32__ || defined _MSC_VER
17     extern "C" int __cdecl _isatty(int _FileHandle);
18     #define isatty _isatty
19     #define strdup _strdup
20     #define fileno _fileno
21     #endif
22 
23 %}
24 
25 
26 %x cond_string
27 D [0-9]
28 E [Ee][-+]?{D}+
29 H [0-9a-fA-F]
30 U       [\x80-\xbf]
31 U2      [\xc2-\xdf]
32 U3      [\xe0-\xef]
33 U4      [\xf0-\xf4]
34 UNICODE {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
35 
36 %%
37 
38 
39 [+-]?{D}+{E}? |
40 [+-]?{D}*\.{D}+{E}? |
41 [+-]?{D}+\.{D}*{E}? {
42                     try {
43                         comment_parserlval.num = boost::lexical_cast<double>(yytext);
44                         return NUM;
catch(boost::bad_lexical_cast &)45                     } catch (boost::bad_lexical_cast&) {}
46                 }
47 
48 "[" { return yytext[0];}
49 "]" { return yytext[0];}
50 "," { return yytext[0];}
51 ":" { return yytext[0];}
52 
53 [ \t]
54 
55 \"			{ BEGIN(cond_string); stringcon.clear(); }
56 <cond_string>{
57 \\n			{ stringcon += '\n'; }
58 \\t			{ stringcon += '\t'; }
59 \\r			{ stringcon += '\r'; }
60 \\\\			{ stringcon += '\\'; }
61 \\\"			{ stringcon += '"'; }
62 {UNICODE}               { stringcon += yytext; }
63 [^\\\n\"]		{ stringcon += yytext; }
64 \" 			{ BEGIN(INITIAL);
65 			comment_parserlval.text = strdup(stringcon.c_str());
66 			return WORD; }
67 <<EOF>> {   BEGIN(INITIAL);
68 			comment_parserlval.text = strdup(stringcon.c_str());
69 			return WORD; }
70 }
71 
72 
73 [^(\[ \] \, \" \:)]* { comment_parserlval.text=strdup(yytext); return WORD;}
74 
75 . { }
76 
77 %%
78 
79 int yywrap(void) {
80 return 1;
81 }
82 
83 void comment_scan_string(const char* str)
84 {
85     yy_switch_to_buffer(yy_scan_string(str));
86 }
87