strict_cpp.re 23 KB

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