1/*============================================================================= 2 Boost.Wave: A Standard compliant C++ preprocessor library 3 4 Sample: IDL lexer 5 6 http://www.boost.org/ 7 8 Copyright (c) 2001-2010 Hartmut Kaiser. Distributed under the Boost 9 Software License, Version 1.0. (See accompanying file 10 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 11=============================================================================*/ 12 13// to build idl.inc from this file: 14// re2c -b -o idl.inc idl.re 15 16/*!re2c 17re2c:indent:string = " "; 18any = [\t\v\f\r\n\040-\377]; 19anyctrl = [\000-\377]; 20OctalDigit = [0-7]; 21Digit = [0-9]; 22HexDigit = [a-fA-F0-9]; 23ExponentPart = [Ee] [+-]? Digit+; 24FractionalConstant = (Digit* "." Digit+) | (Digit+ "."); 25FloatingSuffix = [fF][lL]?|[lL][fF]?; 26IntegerSuffix = [uU][lL]?|[lL][uU]?; 27FixedPointSuffix = [dD]; 28Backslash = [\\]|"??/"; 29EscapeSequence = Backslash ([abfnrtv?'"] | Backslash | "x" HexDigit+ | OctalDigit OctalDigit? OctalDigit?); 30HexQuad = HexDigit HexDigit HexDigit HexDigit; 31UniversalChar = Backslash ("u" HexQuad | "U" HexQuad HexQuad); 32Newline = "\r\n" | "\n" | "\r"; 33PPSpace = ([ \t]|("/*"(any\[*]|Newline|("*"+(any\[*/]|Newline)))*"*"+"/"))*; 34Pound = "#" | "??=" | "%:"; 35*/ 36 37/*!re2c 38 "/*" { goto ccomment; } 39 "//" { goto cppcomment; } 40 41 "TRUE" { BOOST_WAVE_RET(T_TRUE); } 42 "FALSE" { BOOST_WAVE_RET(T_FALSE); } 43 44 "{" { BOOST_WAVE_RET(T_LEFTBRACE); } 45 "}" { BOOST_WAVE_RET(T_RIGHTBRACE); } 46 "[" { BOOST_WAVE_RET(T_LEFTBRACKET); } 47 "]" { BOOST_WAVE_RET(T_RIGHTBRACKET); } 48 "#" { BOOST_WAVE_RET(T_POUND); } 49 "##" { BOOST_WAVE_RET(T_POUND_POUND); } 50 "(" { BOOST_WAVE_RET(T_LEFTPAREN); } 51 ")" { BOOST_WAVE_RET(T_RIGHTPAREN); } 52 ";" { BOOST_WAVE_RET(T_SEMICOLON); } 53 ":" { BOOST_WAVE_RET(T_COLON); } 54 "?" { BOOST_WAVE_RET(T_QUESTION_MARK); } 55 "." { BOOST_WAVE_RET(T_DOT); } 56 "+" { BOOST_WAVE_RET(T_PLUS); } 57 "-" { BOOST_WAVE_RET(T_MINUS); } 58 "*" { BOOST_WAVE_RET(T_STAR); } 59 "/" { BOOST_WAVE_RET(T_DIVIDE); } 60 "%" { BOOST_WAVE_RET(T_PERCENT); } 61 "^" { BOOST_WAVE_RET(T_XOR); } 62 "&" { BOOST_WAVE_RET(T_AND); } 63 "|" { BOOST_WAVE_RET(T_OR); } 64 "~" { BOOST_WAVE_RET(T_COMPL); } 65 "!" { BOOST_WAVE_RET(T_NOT); } 66 "=" { BOOST_WAVE_RET(T_ASSIGN); } 67 "<" { BOOST_WAVE_RET(T_LESS); } 68 ">" { BOOST_WAVE_RET(T_GREATER); } 69 "<<" { BOOST_WAVE_RET(T_SHIFTLEFT); } 70 ">>" { BOOST_WAVE_RET(T_SHIFTRIGHT); } 71 "==" { BOOST_WAVE_RET(T_EQUAL); } 72 "!=" { BOOST_WAVE_RET(T_NOTEQUAL); } 73 "<=" { BOOST_WAVE_RET(T_LESSEQUAL); } 74 ">=" { BOOST_WAVE_RET(T_GREATEREQUAL); } 75 "&&" { BOOST_WAVE_RET(T_ANDAND); } 76 "||" { BOOST_WAVE_RET(T_OROR); } 77 "++" { BOOST_WAVE_RET(T_PLUSPLUS); } 78 "--" { BOOST_WAVE_RET(T_MINUSMINUS); } 79 "," { BOOST_WAVE_RET(T_COMMA); } 80 81 ([a-zA-Z_] | UniversalChar) ([a-zA-Z_0-9] | UniversalChar)* 82 { BOOST_WAVE_RET(T_IDENTIFIER); } 83 84 (("0" [xX] HexDigit+) | ("0" OctalDigit*) | ([1-9] Digit*)) IntegerSuffix? 85 { BOOST_WAVE_RET(T_INTLIT); } 86 87 ((FractionalConstant ExponentPart?) | (Digit+ ExponentPart)) FloatingSuffix? 88 { BOOST_WAVE_RET(T_FLOATLIT); } 89 90 (FractionalConstant | Digit+) FixedPointSuffix 91 { BOOST_WAVE_RET(T_FIXEDPOINTLIT); } 92 93 "L"? (['] (EscapeSequence|any\[\n\r\\']|UniversalChar)+ [']) 94 { BOOST_WAVE_RET(T_CHARLIT); } 95 96 "L"? (["] (EscapeSequence|any\[\n\r\\"]|UniversalChar)* ["]) 97 { BOOST_WAVE_RET(T_STRINGLIT); } 98 99 100 Pound PPSpace "include" PPSpace "<" (any\[\n\r>])+ ">" 101 { BOOST_WAVE_RET(T_PP_HHEADER); } 102 103 Pound PPSpace "include" PPSpace "\"" (any\[\n\r"])+ "\"" 104 { BOOST_WAVE_RET(T_PP_QHEADER); } 105 106 Pound PPSpace "include" PPSpace 107 { BOOST_WAVE_RET(T_PP_INCLUDE); } 108 109 Pound PPSpace "if" { BOOST_WAVE_RET(T_PP_IF); } 110 Pound PPSpace "ifdef" { BOOST_WAVE_RET(T_PP_IFDEF); } 111 Pound PPSpace "ifndef" { BOOST_WAVE_RET(T_PP_IFNDEF); } 112 Pound PPSpace "else" { BOOST_WAVE_RET(T_PP_ELSE); } 113 Pound PPSpace "elif" { BOOST_WAVE_RET(T_PP_ELIF); } 114 Pound PPSpace "endif" { BOOST_WAVE_RET(T_PP_ENDIF); } 115 Pound PPSpace "define" { BOOST_WAVE_RET(T_PP_DEFINE); } 116 Pound PPSpace "undef" { BOOST_WAVE_RET(T_PP_UNDEF); } 117 Pound PPSpace "line" { BOOST_WAVE_RET(T_PP_LINE); } 118 Pound PPSpace "error" { BOOST_WAVE_RET(T_PP_ERROR); } 119 Pound PPSpace "pragma" { BOOST_WAVE_RET(T_PP_PRAGMA); } 120 121 Pound PPSpace "warning" { BOOST_WAVE_RET(T_PP_WARNING); } 122 123 [ \t\v\f]+ 124 { BOOST_WAVE_RET(T_SPACE); } 125 126 Newline 127 { 128 s->line++; 129 BOOST_WAVE_RET(T_NEWLINE); 130 } 131 132 "\000" 133 { 134 if(cursor != s->eof) 135 { 136 using namespace std; // some systems have printf in std 137 if (0 != s->error_proc) { 138 (*s->error_proc)(s, 139 cpplexer::lexing_exception::generic_lexing_error, 140 "'\\000' in input stream"); 141 } 142 else 143 printf("Error: 0 in file\n"); 144 } 145 BOOST_WAVE_RET(T_EOF); 146 } 147 148 anyctrl 149 { 150 BOOST_WAVE_RET(TOKEN_FROM_ID(*s->tok, UnknownTokenType)); 151 } 152*/ 153 154ccomment: 155/*!re2c 156 "*/" { BOOST_WAVE_RET(T_CCOMMENT); } 157 Newline 158 { 159 /*if(cursor == s->eof) BOOST_WAVE_RET(T_EOF);*/ 160 /*s->tok = cursor; */ 161 s->line += count_backslash_newlines(s, cursor) +1; 162 goto ccomment; 163 } 164 165 any { goto ccomment; } 166 167 "\000" 168 { 169 using namespace std; // some systems have printf in std 170 if(cursor == s->eof) 171 { 172 if (s->error_proc) 173 (*s->error_proc)(s, 174 cpplexer::lexing_exception::generic_lexing_warning, 175 "Unterminated comment"); 176 else 177 printf("Error: Unterminated comment\n"); 178 } 179 else 180 { 181 if (s->error_proc) 182 (*s->error_proc)(s, 183 cpplexer::lexing_exception::generic_lexing_error, 184 "'\\000' in input stream"); 185 else 186 printf("Error: 0 in file"); 187 } 188 /* adjust cursor such next call returns T_EOF */ 189 --YYCURSOR; 190 /* the comment is unterminated, but nevertheless its a comment */ 191 BOOST_WAVE_RET(T_CCOMMENT); 192 } 193 194 anyctrl 195 { 196 if (s->error_proc) 197 (*s->error_proc)(s, 198 cpplexer::lexing_exception::generic_lexing_error, 199 "invalid character in input stream"); 200 else 201 printf("Error: 0 in file"); 202 } 203 204*/ 205 206cppcomment: 207/*!re2c 208 Newline 209 { 210 /*if(cursor == s->eof) BOOST_WAVE_RET(T_EOF); */ 211 /*s->tok = cursor; */ 212 s->line++; 213 BOOST_WAVE_RET(T_CPPCOMMENT); 214 } 215 216 any { goto cppcomment; } 217 218 "\000" 219 { 220 using namespace std; // some systems have printf in std 221 if(cursor != s->eof) 222 { 223 if (s->error_proc) 224 (*s->error_proc)(s, 225 cpplexer::lexing_exception::generic_lexing_error, 226 "'\\000' in input stream"); 227 else 228 printf("Error: 0 in file"); 229 } 230 /* adjust cursor such next call returns T_EOF */ 231 --YYCURSOR; 232 /* the comment is unterminated, but nevertheless its a comment */ 233 BOOST_WAVE_RET(T_CPPCOMMENT); 234 } 235*/ 236