| 1 |
/** |
| 2 |
* the "incl" state is used for picking up the name |
| 3 |
* of an include file |
| 4 |
*/ |
| 5 |
%x incl |
| 6 |
%x c_comment |
| 7 |
%x cpp_comment |
| 8 |
%x using_namespace |
| 9 |
|
| 10 |
simple_escape [abfnrtv'"?\\] |
| 11 |
octal_escape [0-7]{1,3} |
| 12 |
hex_escape "x"[0-9a-fA-F]+ |
| 13 |
|
| 14 |
escape_sequence [\\]({simple_escape}|{octal_escape}|{hex_escape}) |
| 15 |
c_char [^'\\\n]|{escape_sequence} |
| 16 |
s_char [^"\\\n]|{escape_sequence} |
| 17 |
|
| 18 |
ns_name [a-zA-Z][a-zA-Z:_]* |
| 19 |
using_ns "using "[ ]*"namespace" |
| 20 |
ns_alias "namespace "{ns_name}[ ]*"="[ ]*{ns_name}[ ]*";" |
| 21 |
|
| 22 |
%{ |
| 23 |
// Avoid spam output |
| 24 |
#ifdef ECHO |
| 25 |
#undef ECHO |
| 26 |
#endif |
| 27 |
#define ECHO |
| 28 |
|
| 29 |
// Never exit |
| 30 |
#ifdef YY_FATAL_ERROR |
| 31 |
#undef YY_FATAL_ERROR |
| 32 |
#endif |
| 33 |
#define YY_FATAL_ERROR(msg) |
| 34 |
|
| 35 |
#include <list> |
| 36 |
#include <wx/filename.h> |
| 37 |
#include "crawler_include.h" |
| 38 |
|
| 39 |
%} |
| 40 |
|
| 41 |
%option yylineno |
| 42 |
|
| 43 |
%% |
| 44 |
|
| 45 |
"//" { |
| 46 |
BEGIN(cpp_comment); |
| 47 |
} |
| 48 |
|
| 49 |
"/*" { |
| 50 |
BEGIN(c_comment); |
| 51 |
} |
| 52 |
|
| 53 |
"L"?[']{c_char}+['] {/* eat a string */} |
| 54 |
"L"?["]{s_char}*["] {/* eat a string */} |
| 55 |
{using_ns} {BEGIN(using_namespace);} |
| 56 |
<using_namespace>[a-zA-Z][a-zA-Z:_]* { /* got the namespace */ |
| 57 |
fcFileOpener::Get()->AddNamespace(yytext); |
| 58 |
BEGIN(INITIAL); |
| 59 |
} |
| 60 |
<using_namespace>; {BEGIN(INITIAL);} |
| 61 |
<using_namespace>. {} |
| 62 |
{ns_alias} {fcFileOpener::Get()->AddNamespaceAlias(yytext);} |
| 63 |
include {BEGIN(incl);} |
| 64 |
. {} |
| 65 |
<incl>\n {BEGIN(INITIAL);} |
| 66 |
<incl>[ \t]* {} /* eat the whitespace */ |
| 67 |
<incl>["<][^ \t\n]+[">] { /* got the include file name */ |
| 68 |
// Open the new file |
| 69 |
FILE * new_file(NULL); |
| 70 |
|
| 71 |
// keep the include statement |
| 72 |
fcFileOpener::Get()->AddIncludeStatement( yytext ); |
| 73 |
wxString filepath; |
| 74 |
if ( fcFileOpener::Get()->getDepth() < fcFileOpener::Get()->getMaxDepth() ) { |
| 75 |
new_file = fcFileOpener::Get()->OpenFile( yytext, filepath ); |
| 76 |
} |
| 77 |
|
| 78 |
if ( ! new_file ) { |
| 79 |
// We got some error |
| 80 |
BEGIN(INITIAL); |
| 81 |
|
| 82 |
} else { |
| 83 |
// keep the current buffer |
| 84 |
fc_in = new_file; |
| 85 |
fcFileOpener::Get()->PushBufferState( YY_CURRENT_BUFFER, filepath ); |
| 86 |
|
| 87 |
yy_switch_to_buffer( yy_create_buffer( new_file, YY_BUF_SIZE ) ); |
| 88 |
BEGIN(INITIAL); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
<cpp_comment>\n { |
| 93 |
BEGIN(INITIAL); |
| 94 |
} |
| 95 |
<cpp_comment>. {} /* do nothing */ |
| 96 |
|
| 97 |
<c_comment>"*/" { |
| 98 |
BEGIN(INITIAL); |
| 99 |
} |
| 100 |
|
| 101 |
<c_comment>. {} |
| 102 |
|
| 103 |
<<EOF>> { |
| 104 |
if ( !fcFileOpener::Get()->IsStateStackEmpty() ) { |
| 105 |
|
| 106 |
if ( YY_CURRENT_BUFFER->yy_input_file ) { |
| 107 |
fclose( YY_CURRENT_BUFFER->yy_input_file ); |
| 108 |
YY_CURRENT_BUFFER->yy_input_file = NULL; |
| 109 |
} |
| 110 |
|
| 111 |
yy_delete_buffer ( YY_CURRENT_BUFFER ); |
| 112 |
yy_switch_to_buffer ( fcFileOpener::Get()->PopBufferState() ); |
| 113 |
|
| 114 |
} else { |
| 115 |
|
| 116 |
if ( YY_CURRENT_BUFFER->yy_input_file ) { |
| 117 |
fclose( YY_CURRENT_BUFFER->yy_input_file ); |
| 118 |
YY_CURRENT_BUFFER->yy_input_file = NULL; |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
yy_delete_buffer ( YY_CURRENT_BUFFER ); |
| 123 |
yyterminate(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
%% |
| 128 |
|
| 129 |
int yywrap() { |
| 130 |
return 1; |
| 131 |
} |
| 132 |
|
| 133 |
int crawlerScan( const char* filePath ) |
| 134 |
{ |
| 135 |
BEGIN INITIAL; |
| 136 |
fc_lineno = 1; |
| 137 |
|
| 138 |
wxFileName fn(filePath); |
| 139 |
if ( fn.IsRelative() ) { |
| 140 |
fn.MakeAbsolute(); |
| 141 |
} |
| 142 |
|
| 143 |
FILE* fp = fopen(fn.GetFullPath().mb_str(wxConvUTF8).data(), "r"); |
| 144 |
if ( fp == NULL ) { |
| 145 |
//printf("%s\n", strerror(errno)); |
| 146 |
// failed to open input file... |
| 147 |
return -1; |
| 148 |
} |
| 149 |
|
| 150 |
// set the initial search directory |
| 151 |
fcFileOpener::Get()->SetCwd( fn.GetPath() ); |
| 152 |
|
| 153 |
yy_switch_to_buffer( yy_create_buffer(fp, YY_BUF_SIZE) ); |
| 154 |
fc_in = fp; |
| 155 |
int rc = fc_lex(); |
| 156 |
yy_delete_buffer( YY_CURRENT_BUFFER ); |
| 157 |
|
| 158 |
return rc; |
| 159 |
} |
| 160 |
|