cpp.re 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. Copyright (c) 2001 Daniel C. Nuffer
  4. Copyright (c) 2001-2013 Hartmut Kaiser.
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. This is a lexer conforming to the Standard with a few exceptions.
  8. So it does allow the '$' to be part of identifiers. If you need strict
  9. Standards conforming behaviour, please include the lexer definition
  10. provided in the file strict_cpp.re.
  11. TODO:
  12. handle errors better.
  13. =============================================================================*/
  14. /*!re2c
  15. re2c:indent:string = " ";
  16. any = [\t\v\f\r\n\040-\377];
  17. anyctrl = [\001-\037];
  18. OctalDigit = [0-7];
  19. Digit = [0-9];
  20. HexDigit = [a-fA-F0-9];
  21. Integer = (("0" [xX] HexDigit+) | ("0" OctalDigit*) | ([1-9] Digit*));
  22. ExponentStart = [Ee] [+-];
  23. ExponentPart = [Ee] [+-]? Digit+;
  24. FractionalConstant = (Digit* "." Digit+) | (Digit+ ".");
  25. FloatingSuffix = [fF] [lL]? | [lL] [fF]?;
  26. IntegerSuffix = [uU] [lL]? | [lL] [uU]?;
  27. LongIntegerSuffix = [uU] ([lL] [lL]) | ([lL] [lL]) [uU]?;
  28. MSLongIntegerSuffix = "u"? "i64";
  29. Backslash = [\\] | "??/";
  30. EscapeSequence = Backslash ([abfnrtv?'"] | Backslash | "x" HexDigit+ | OctalDigit OctalDigit? OctalDigit?);
  31. HexQuad = HexDigit HexDigit HexDigit HexDigit;
  32. UniversalChar = Backslash ("u" HexQuad | "U" HexQuad HexQuad);
  33. Newline = "\r\n" | "\n" | "\r";
  34. PPSpace = ([ \t\f\v]|("/*"(any\[*]|Newline|("*"+(any\[*/]|Newline)))*"*"+"/"))*;
  35. Pound = "#" | "??=" | "%:";
  36. NonDigit = [a-zA-Z_$] | UniversalChar;
  37. */
  38. /*!re2c
  39. "/*" { goto ccomment; }
  40. "//" { goto cppcomment; }
  41. "."? Digit { goto pp_number; }
  42. "alignas" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_ALIGNAS : T_IDENTIFIER); }
  43. "alignof" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_ALIGNOF : T_IDENTIFIER); }
  44. "asm" { BOOST_WAVE_RET(T_ASM); }
  45. "auto" { BOOST_WAVE_RET(T_AUTO); }
  46. "bool" { BOOST_WAVE_RET(T_BOOL); }
  47. "break" { BOOST_WAVE_RET(T_BREAK); }
  48. "case" { BOOST_WAVE_RET(T_CASE); }
  49. "catch" { BOOST_WAVE_RET(T_CATCH); }
  50. "char" { BOOST_WAVE_RET(T_CHAR); }
  51. "char16_t" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_CHAR16_T : T_IDENTIFIER); }
  52. "char32_t" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_CHAR32_T : T_IDENTIFIER); }
  53. "class" { BOOST_WAVE_RET(T_CLASS); }
  54. "const" { BOOST_WAVE_RET(T_CONST); }
  55. "constexpr" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_CONSTEXPR : T_IDENTIFIER); }
  56. "const_cast" { BOOST_WAVE_RET(T_CONSTCAST); }
  57. "continue" { BOOST_WAVE_RET(T_CONTINUE); }
  58. "decltype" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_DECLTYPE : T_IDENTIFIER); }
  59. "default" { BOOST_WAVE_RET(T_DEFAULT); }
  60. "delete" { BOOST_WAVE_RET(T_DELETE); }
  61. "do" { BOOST_WAVE_RET(T_DO); }
  62. "double" { BOOST_WAVE_RET(T_DOUBLE); }
  63. "dynamic_cast" { BOOST_WAVE_RET(T_DYNAMICCAST); }
  64. "else" { BOOST_WAVE_RET(T_ELSE); }
  65. "enum" { BOOST_WAVE_RET(T_ENUM); }
  66. "explicit" { BOOST_WAVE_RET(T_EXPLICIT); }
  67. "export" { BOOST_WAVE_RET(T_EXPORT); }
  68. "extern" { BOOST_WAVE_RET(T_EXTERN); }
  69. "false" { BOOST_WAVE_RET(T_FALSE); }
  70. "float" { BOOST_WAVE_RET(T_FLOAT); }
  71. "for" { BOOST_WAVE_RET(T_FOR); }
  72. "friend" { BOOST_WAVE_RET(T_FRIEND); }
  73. "goto" { BOOST_WAVE_RET(T_GOTO); }
  74. "if" { BOOST_WAVE_RET(T_IF); }
  75. "import" { BOOST_WAVE_RET(s->enable_import_keyword ? T_IMPORT : T_IDENTIFIER); }
  76. "inline" { BOOST_WAVE_RET(T_INLINE); }
  77. "int" { BOOST_WAVE_RET(T_INT); }
  78. "long" { BOOST_WAVE_RET(T_LONG); }
  79. "mutable" { BOOST_WAVE_RET(T_MUTABLE); }
  80. "namespace" { BOOST_WAVE_RET(T_NAMESPACE); }
  81. "new" { BOOST_WAVE_RET(T_NEW); }
  82. "noexcept" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_NOEXCEPT : T_IDENTIFIER); }
  83. "nullptr" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_NULLPTR : T_IDENTIFIER); }
  84. "operator" { BOOST_WAVE_RET(T_OPERATOR); }
  85. "private" { BOOST_WAVE_RET(T_PRIVATE); }
  86. "protected" { BOOST_WAVE_RET(T_PROTECTED); }
  87. "public" { BOOST_WAVE_RET(T_PUBLIC); }
  88. "register" { BOOST_WAVE_RET(T_REGISTER); }
  89. "reinterpret_cast" { BOOST_WAVE_RET(T_REINTERPRETCAST); }
  90. "return" { BOOST_WAVE_RET(T_RETURN); }
  91. "short" { BOOST_WAVE_RET(T_SHORT); }
  92. "signed" { BOOST_WAVE_RET(T_SIGNED); }
  93. "sizeof" { BOOST_WAVE_RET(T_SIZEOF); }
  94. "static" { BOOST_WAVE_RET(T_STATIC); }
  95. "static_cast" { BOOST_WAVE_RET(T_STATICCAST); }
  96. "static_assert" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_STATICASSERT : T_IDENTIFIER); }
  97. "struct" { BOOST_WAVE_RET(T_STRUCT); }
  98. "switch" { BOOST_WAVE_RET(T_SWITCH); }
  99. "template" { BOOST_WAVE_RET(T_TEMPLATE); }
  100. "this" { BOOST_WAVE_RET(T_THIS); }
  101. "thread_local" { BOOST_WAVE_RET(s->act_in_cpp0x_mode ? T_THREADLOCAL : T_IDENTIFIER); }
  102. "throw" { BOOST_WAVE_RET(T_THROW); }
  103. "true" { BOOST_WAVE_RET(T_TRUE); }
  104. "try" { BOOST_WAVE_RET(T_TRY); }
  105. "typedef" { BOOST_WAVE_RET(T_TYPEDEF); }
  106. "typeid" { BOOST_WAVE_RET(T_TYPEID); }
  107. "typename" { BOOST_WAVE_RET(T_TYPENAME); }
  108. "union" { BOOST_WAVE_RET(T_UNION); }
  109. "unsigned" { BOOST_WAVE_RET(T_UNSIGNED); }
  110. "using" { BOOST_WAVE_RET(T_USING); }
  111. "virtual" { BOOST_WAVE_RET(T_VIRTUAL); }
  112. "void" { BOOST_WAVE_RET(T_VOID); }
  113. "volatile" { BOOST_WAVE_RET(T_VOLATILE); }
  114. "wchar_t" { BOOST_WAVE_RET(T_WCHART); }
  115. "while" { BOOST_WAVE_RET(T_WHILE); }
  116. "__int8" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_INT8 : T_IDENTIFIER); }
  117. "__int16" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_INT16 : T_IDENTIFIER); }
  118. "__int32" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_INT32 : T_IDENTIFIER); }
  119. "__int64" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_INT64 : T_IDENTIFIER); }
  120. "_"? "_based" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_BASED : T_IDENTIFIER); }
  121. "_"? "_declspec" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_DECLSPEC : T_IDENTIFIER); }
  122. "_"? "_cdecl" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_CDECL : T_IDENTIFIER); }
  123. "_"? "_fastcall" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_FASTCALL : T_IDENTIFIER); }
  124. "_"? "_stdcall" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_STDCALL : T_IDENTIFIER); }
  125. "__try" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_TRY : T_IDENTIFIER); }
  126. "__except" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_EXCEPT : T_IDENTIFIER); }
  127. "__finally" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_FINALLY : T_IDENTIFIER); }
  128. "__leave" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_LEAVE : T_IDENTIFIER); }
  129. "_"? "_inline" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_INLINE : T_IDENTIFIER); }
  130. "_"? "_asm" { BOOST_WAVE_RET(s->enable_ms_extensions ? T_MSEXT_ASM : T_IDENTIFIER); }
  131. "{" { BOOST_WAVE_RET(T_LEFTBRACE); }
  132. "??<" { BOOST_WAVE_RET(T_LEFTBRACE_TRIGRAPH); }
  133. "<%" { BOOST_WAVE_RET(T_LEFTBRACE_ALT); }
  134. "}" { BOOST_WAVE_RET(T_RIGHTBRACE); }
  135. "??>" { BOOST_WAVE_RET(T_RIGHTBRACE_TRIGRAPH); }
  136. "%>" { BOOST_WAVE_RET(T_RIGHTBRACE_ALT); }
  137. "[" { BOOST_WAVE_RET(T_LEFTBRACKET); }
  138. "??(" { BOOST_WAVE_RET(T_LEFTBRACKET_TRIGRAPH); }
  139. "<:" { BOOST_WAVE_RET(T_LEFTBRACKET_ALT); }
  140. "]" { BOOST_WAVE_RET(T_RIGHTBRACKET); }
  141. "??)" { BOOST_WAVE_RET(T_RIGHTBRACKET_TRIGRAPH); }
  142. ":>" { BOOST_WAVE_RET(T_RIGHTBRACKET_ALT); }
  143. "#" { BOOST_WAVE_RET(T_POUND); }
  144. "%:" { BOOST_WAVE_RET(T_POUND_ALT); }
  145. "??=" { BOOST_WAVE_RET(T_POUND_TRIGRAPH); }
  146. "##" { BOOST_WAVE_RET(T_POUND_POUND); }
  147. "#??=" { BOOST_WAVE_RET(T_POUND_POUND_TRIGRAPH); }
  148. "??=#" { BOOST_WAVE_RET(T_POUND_POUND_TRIGRAPH); }
  149. "??=??=" { BOOST_WAVE_RET(T_POUND_POUND_TRIGRAPH); }
  150. "%:%:" { BOOST_WAVE_RET(T_POUND_POUND_ALT); }
  151. "(" { BOOST_WAVE_RET(T_LEFTPAREN); }
  152. ")" { BOOST_WAVE_RET(T_RIGHTPAREN); }
  153. ";" { BOOST_WAVE_RET(T_SEMICOLON); }
  154. ":" { BOOST_WAVE_RET(T_COLON); }
  155. "..." { BOOST_WAVE_RET(T_ELLIPSIS); }
  156. "?" { BOOST_WAVE_RET(T_QUESTION_MARK); }
  157. "::"
  158. {
  159. if (s->act_in_c99_mode) {
  160. --YYCURSOR;
  161. BOOST_WAVE_RET(T_COLON);
  162. }
  163. else {
  164. BOOST_WAVE_RET(T_COLON_COLON);
  165. }
  166. }
  167. "." { BOOST_WAVE_RET(T_DOT); }
  168. ".*"
  169. {
  170. if (s->act_in_c99_mode) {
  171. --YYCURSOR;
  172. BOOST_WAVE_RET(T_DOT);
  173. }
  174. else {
  175. BOOST_WAVE_RET(T_DOTSTAR);
  176. }
  177. }
  178. "+" { BOOST_WAVE_RET(T_PLUS); }
  179. "-" { BOOST_WAVE_RET(T_MINUS); }
  180. "*" { BOOST_WAVE_RET(T_STAR); }
  181. "/" { BOOST_WAVE_RET(T_DIVIDE); }
  182. "%" { BOOST_WAVE_RET(T_PERCENT); }
  183. "^" { BOOST_WAVE_RET(T_XOR); }
  184. "??'" { BOOST_WAVE_RET(T_XOR_TRIGRAPH); }
  185. "xor" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_XOR_ALT); }
  186. "&" { BOOST_WAVE_RET(T_AND); }
  187. "bitand" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_AND_ALT); }
  188. "|" { BOOST_WAVE_RET(T_OR); }
  189. "bitor" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_OR_ALT); }
  190. "??!" { BOOST_WAVE_RET(T_OR_TRIGRAPH); }
  191. "~" { BOOST_WAVE_RET(T_COMPL); }
  192. "??-" { BOOST_WAVE_RET(T_COMPL_TRIGRAPH); }
  193. "compl" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_COMPL_ALT); }
  194. "!" { BOOST_WAVE_RET(T_NOT); }
  195. "not" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_NOT_ALT); }
  196. "=" { BOOST_WAVE_RET(T_ASSIGN); }
  197. "<" { BOOST_WAVE_RET(T_LESS); }
  198. ">" { BOOST_WAVE_RET(T_GREATER); }
  199. "+=" { BOOST_WAVE_RET(T_PLUSASSIGN); }
  200. "-=" { BOOST_WAVE_RET(T_MINUSASSIGN); }
  201. "*=" { BOOST_WAVE_RET(T_STARASSIGN); }
  202. "/=" { BOOST_WAVE_RET(T_DIVIDEASSIGN); }
  203. "%=" { BOOST_WAVE_RET(T_PERCENTASSIGN); }
  204. "^=" { BOOST_WAVE_RET(T_XORASSIGN); }
  205. "xor_eq" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_XORASSIGN_ALT); }
  206. "??'=" { BOOST_WAVE_RET(T_XORASSIGN_TRIGRAPH); }
  207. "&=" { BOOST_WAVE_RET(T_ANDASSIGN); }
  208. "and_eq" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_ANDASSIGN_ALT); }
  209. "|=" { BOOST_WAVE_RET(T_ORASSIGN); }
  210. "or_eq" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_ORASSIGN_ALT); }
  211. "??!=" { BOOST_WAVE_RET(T_ORASSIGN_TRIGRAPH); }
  212. "<<" { BOOST_WAVE_RET(T_SHIFTLEFT); }
  213. ">>" { BOOST_WAVE_RET(T_SHIFTRIGHT); }
  214. ">>=" { BOOST_WAVE_RET(T_SHIFTRIGHTASSIGN); }
  215. "<<=" { BOOST_WAVE_RET(T_SHIFTLEFTASSIGN); }
  216. "==" { BOOST_WAVE_RET(T_EQUAL); }
  217. "!=" { BOOST_WAVE_RET(T_NOTEQUAL); }
  218. "not_eq" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_NOTEQUAL_ALT); }
  219. "<=" { BOOST_WAVE_RET(T_LESSEQUAL); }
  220. ">=" { BOOST_WAVE_RET(T_GREATEREQUAL); }
  221. "&&" { BOOST_WAVE_RET(T_ANDAND); }
  222. "and" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_ANDAND_ALT); }
  223. "||" { BOOST_WAVE_RET(T_OROR); }
  224. "??!|" { BOOST_WAVE_RET(T_OROR_TRIGRAPH); }
  225. "|??!" { BOOST_WAVE_RET(T_OROR_TRIGRAPH); }
  226. "or" { BOOST_WAVE_RET(s->act_in_c99_mode ? T_IDENTIFIER : T_OROR_ALT); }
  227. "??!??!" { BOOST_WAVE_RET(T_OROR_TRIGRAPH); }
  228. "++" { BOOST_WAVE_RET(T_PLUSPLUS); }
  229. "--" { BOOST_WAVE_RET(T_MINUSMINUS); }
  230. "," { BOOST_WAVE_RET(T_COMMA); }
  231. "->*"
  232. {
  233. if (s->act_in_c99_mode) {
  234. --YYCURSOR;
  235. BOOST_WAVE_RET(T_ARROW);
  236. }
  237. else {
  238. BOOST_WAVE_RET(T_ARROWSTAR);
  239. }
  240. }
  241. "->" { BOOST_WAVE_RET(T_ARROW); }
  242. "??/" { BOOST_WAVE_RET(T_ANY_TRIGRAPH); }
  243. "L"? (['] (EscapeSequence | UniversalChar | any\[\n\r\\'])+ ['])
  244. { BOOST_WAVE_RET(T_CHARLIT); }
  245. "L"? (["] (EscapeSequence | UniversalChar | any\[\n\r\\"])* ["])
  246. { BOOST_WAVE_RET(T_STRINGLIT); }
  247. "L"? "R" ["]
  248. {
  249. if (s->act_in_cpp0x_mode)
  250. {
  251. rawstringdelim = "";
  252. goto extrawstringlit;
  253. }
  254. --YYCURSOR;
  255. BOOST_WAVE_RET(T_IDENTIFIER);
  256. }
  257. [uU] [']
  258. {
  259. if (s->act_in_cpp0x_mode)
  260. goto extcharlit;
  261. --YYCURSOR;
  262. BOOST_WAVE_RET(T_IDENTIFIER);
  263. }
  264. ([uU] | "u8") ["]
  265. {
  266. if (s->act_in_cpp0x_mode)
  267. goto extstringlit;
  268. --YYCURSOR;
  269. BOOST_WAVE_RET(T_IDENTIFIER);
  270. }
  271. ([uU] | "u8") "R" ["]
  272. {
  273. if (s->act_in_cpp0x_mode)
  274. {
  275. rawstringdelim = "";
  276. goto extrawstringlit;
  277. }
  278. --YYCURSOR;
  279. BOOST_WAVE_RET(T_IDENTIFIER);
  280. }
  281. ([a-zA-Z_$] | UniversalChar) ([a-zA-Z_0-9$] | UniversalChar)*
  282. { BOOST_WAVE_RET(T_IDENTIFIER); }
  283. Pound PPSpace ( "include" | "include_next") PPSpace "<" (any\[\n\r>])+ ">"
  284. { BOOST_WAVE_RET(T_PP_HHEADER); }
  285. Pound PPSpace ( "include" | "include_next") PPSpace "\"" (any\[\n\r"])+ "\""
  286. { BOOST_WAVE_RET(T_PP_QHEADER); }
  287. Pound PPSpace ( "include" | "include_next") PPSpace
  288. { BOOST_WAVE_RET(T_PP_INCLUDE); }
  289. Pound PPSpace "if" { BOOST_WAVE_RET(T_PP_IF); }
  290. Pound PPSpace "ifdef" { BOOST_WAVE_RET(T_PP_IFDEF); }
  291. Pound PPSpace "ifndef" { BOOST_WAVE_RET(T_PP_IFNDEF); }
  292. Pound PPSpace "else" { BOOST_WAVE_RET(T_PP_ELSE); }
  293. Pound PPSpace "elif" { BOOST_WAVE_RET(T_PP_ELIF); }
  294. Pound PPSpace "endif" { BOOST_WAVE_RET(T_PP_ENDIF); }
  295. Pound PPSpace "define" { BOOST_WAVE_RET(T_PP_DEFINE); }
  296. Pound PPSpace "undef" { BOOST_WAVE_RET(T_PP_UNDEF); }
  297. Pound PPSpace "line" { BOOST_WAVE_RET(T_PP_LINE); }
  298. Pound PPSpace "error" { BOOST_WAVE_RET(T_PP_ERROR); }
  299. Pound PPSpace "pragma" { BOOST_WAVE_RET(T_PP_PRAGMA); }
  300. Pound PPSpace "warning" { BOOST_WAVE_RET(T_PP_WARNING); }
  301. Pound PPSpace "region" { BOOST_WAVE_RET(T_MSEXT_PP_REGION); }
  302. Pound PPSpace "endregion" { BOOST_WAVE_RET(T_MSEXT_PP_ENDREGION); }
  303. [ \t\v\f]+
  304. { BOOST_WAVE_RET(T_SPACE); }
  305. Newline
  306. {
  307. s->line++;
  308. cursor.column = 1;
  309. BOOST_WAVE_RET(T_NEWLINE);
  310. }
  311. "\000"
  312. {
  313. if (s->eof && cursor != s->eof)
  314. {
  315. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  316. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  317. "invalid character '\\000' in input stream");
  318. }
  319. BOOST_WAVE_RET(T_EOF);
  320. }
  321. any { BOOST_WAVE_RET(TOKEN_FROM_ID(*s->tok, UnknownTokenType)); }
  322. anyctrl
  323. {
  324. // flag the error
  325. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  326. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  327. "invalid character '\\%03o' in input stream", *--YYCURSOR);
  328. }
  329. */
  330. ccomment:
  331. /*!re2c
  332. "*/" { BOOST_WAVE_RET(T_CCOMMENT); }
  333. Newline
  334. {
  335. /*if(cursor == s->eof) BOOST_WAVE_RET(T_EOF);*/
  336. /*s->tok = cursor; */
  337. s->line += count_backslash_newlines(s, cursor) +1;
  338. cursor.column = 1;
  339. goto ccomment;
  340. }
  341. any { goto ccomment; }
  342. "\000"
  343. {
  344. if(cursor == s->eof)
  345. {
  346. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  347. (*s->error_proc)(s, lexing_exception::generic_lexing_warning,
  348. "Unterminated 'C' style comment");
  349. }
  350. else
  351. {
  352. --YYCURSOR; // next call returns T_EOF
  353. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  354. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  355. "invalid character: '\\000' in input stream");
  356. }
  357. }
  358. anyctrl
  359. {
  360. // flag the error
  361. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  362. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  363. "invalid character '\\%03o' in input stream", *--YYCURSOR);
  364. }
  365. */
  366. cppcomment:
  367. /*!re2c
  368. Newline
  369. {
  370. /*if(cursor == s->eof) BOOST_WAVE_RET(T_EOF); */
  371. /*s->tok = cursor; */
  372. s->line++;
  373. cursor.column = 1;
  374. BOOST_WAVE_RET(T_CPPCOMMENT);
  375. }
  376. any { goto cppcomment; }
  377. "\000"
  378. {
  379. if (s->eof && cursor != s->eof)
  380. {
  381. --YYCURSOR; // next call returns T_EOF
  382. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  383. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  384. "invalid character '\\000' in input stream");
  385. }
  386. --YYCURSOR; // next call returns T_EOF
  387. if (!s->single_line_only)
  388. {
  389. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  390. (*s->error_proc)(s, lexing_exception::generic_lexing_warning,
  391. "Unterminated 'C++' style comment");
  392. }
  393. BOOST_WAVE_RET(T_CPPCOMMENT);
  394. }
  395. anyctrl
  396. {
  397. // flag the error
  398. BOOST_WAVE_UPDATE_CURSOR(); // adjust the input cursor
  399. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  400. "invalid character '\\%03o' in input stream", *--YYCURSOR);
  401. }
  402. */
  403. /* this subscanner is called whenever a pp_number has been started */
  404. pp_number:
  405. {
  406. cursor = uchar_wrapper(s->tok = s->cur, s->column = s->curr_column);
  407. marker = uchar_wrapper(s->ptr);
  408. limit = uchar_wrapper(s->lim);
  409. if (s->detect_pp_numbers) {
  410. /*!re2c
  411. "."? Digit (Digit | NonDigit | ExponentStart | ".")*
  412. { BOOST_WAVE_RET(T_PP_NUMBER); }
  413. */
  414. }
  415. else {
  416. /*!re2c
  417. ((FractionalConstant ExponentPart?) | (Digit+ ExponentPart)) FloatingSuffix?
  418. { BOOST_WAVE_RET(T_FLOATLIT); }
  419. Integer { goto integer_suffix; }
  420. */
  421. }
  422. }
  423. /* this subscanner is called, whenever an Integer was recognized */
  424. integer_suffix:
  425. {
  426. if (s->enable_ms_extensions) {
  427. /*!re2c
  428. LongIntegerSuffix | MSLongIntegerSuffix
  429. { BOOST_WAVE_RET(T_LONGINTLIT); }
  430. IntegerSuffix?
  431. { BOOST_WAVE_RET(T_INTLIT); }
  432. */
  433. }
  434. else {
  435. /*!re2c
  436. LongIntegerSuffix
  437. { BOOST_WAVE_RET(T_LONGINTLIT); }
  438. IntegerSuffix?
  439. { BOOST_WAVE_RET(T_INTLIT); }
  440. */
  441. }
  442. }
  443. /* this subscanner is invoked for C++0x extended character literals */
  444. extcharlit:
  445. {
  446. /*!re2c
  447. ((EscapeSequence | UniversalChar | any\[\n\r\\']) ['])
  448. { BOOST_WAVE_RET(T_CHARLIT); }
  449. any
  450. { BOOST_WAVE_RET(TOKEN_FROM_ID(*s->tok, UnknownTokenType)); }
  451. */
  452. }
  453. /* this subscanner is invoked for C++0x extended character string literals */
  454. extstringlit:
  455. {
  456. /*!re2c
  457. ((EscapeSequence | UniversalChar | any\[\n\r\\"])* ["])
  458. { BOOST_WAVE_RET(T_STRINGLIT); }
  459. any
  460. { BOOST_WAVE_RET(TOKEN_FROM_ID(*s->tok, UnknownTokenType)); }
  461. */
  462. }
  463. extrawstringlit:
  464. {
  465. // we have consumed the double quote but not the lparen
  466. // at this point we may see a delimiter
  467. /*!re2c
  468. * {
  469. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  470. "Invalid character in raw string delimiter ('%c')", yych);
  471. }
  472. // delimiters are any character but parentheses, backslash, and whitespace
  473. any\[()\\\t\v\f\r\n]
  474. {
  475. rawstringdelim += yych;
  476. if (rawstringdelim.size() > 16)
  477. {
  478. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  479. "Raw string delimiter of excessive length (\"%s\") in input stream",
  480. rawstringdelim.c_str());
  481. }
  482. goto extrawstringlit;
  483. }
  484. "("
  485. {
  486. rawstringdelim = ")" + rawstringdelim;
  487. goto extrawstringbody;
  488. }
  489. */
  490. }
  491. extrawstringbody:
  492. {
  493. /*!re2c
  494. * {
  495. (*s->error_proc)(s, lexing_exception::generic_lexing_error,
  496. "Invalid character in raw string body ('%c')", yych);
  497. }
  498. Newline
  499. {
  500. s->line += count_backslash_newlines(s, cursor) +1;
  501. cursor.column = 1;
  502. goto extrawstringbody;
  503. }
  504. (EscapeSequence | UniversalChar | any\["])
  505. {
  506. goto extrawstringbody;
  507. }
  508. ["]
  509. {
  510. // check to see if we have completed a delimiter
  511. if (string_type((char *)(YYCURSOR - rawstringdelim.size() - 1),
  512. (char *)(YYCURSOR - 1)) == rawstringdelim)
  513. {
  514. BOOST_WAVE_RET(T_RAWSTRINGLIT);
  515. } else {
  516. goto extrawstringbody;
  517. }
  518. }
  519. */
  520. }