cpp.re 23 KB

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