cmGccDepfileLexer.in.l 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. %{
  2. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  3. file Copyright.txt or https://cmake.org/licensing for details. */
  4. /* IWYU pragma: no_forward_declare yyguts_t */
  5. #ifndef __clang_analyzer__ /* Suppress clang-analyzer warnings */
  6. #include <cmGccDepfileLexerHelper.h>
  7. #include <string>
  8. %}
  9. %option prefix="cmGccDepfile_yy"
  10. %option noyywrap
  11. %option reentrant
  12. %pointer
  13. WSPACE [ \t]
  14. NEWLINE \r?\n
  15. %%
  16. \${2} {
  17. // Unescape the dollar sign.
  18. yyextra->addToCurrentPath("$");
  19. }
  20. \\# {
  21. // Unescape the hash.
  22. yyextra->addToCurrentPath("#");
  23. }
  24. (\\\\)*\\[ ] {
  25. // 2N+1 backslashes plus space -> N backslashes plus space.
  26. size_t c = (strlen(yytext) - 1) / 2;
  27. std::string s(c, '\\');
  28. s.push_back(' ');
  29. yyextra->addToCurrentPath(s.c_str());
  30. }
  31. (\\\\)+[ ] {
  32. // 2N backslashes plus space -> 2N backslashes, end of filename.
  33. yytext[strlen(yytext) - 1] = 0;
  34. yyextra->addToCurrentPath(yytext);
  35. yyextra->newDependency();
  36. }
  37. {WSPACE}*\\{NEWLINE} {
  38. // A line continuation ends the current file name.
  39. yyextra->newRuleOrDependency();
  40. }
  41. {NEWLINE} {
  42. // A newline ends the current file name and the current rule.
  43. yyextra->newEntry();
  44. }
  45. :{NEWLINE} {
  46. // A colon ends the rules
  47. yyextra->newDependency();
  48. // A newline after colon terminates current rule.
  49. yyextra->newEntry();
  50. }
  51. :({WSPACE}+|\\{NEWLINE}) {
  52. // A colon followed by space or line continuation ends the rules
  53. // and starts a new dependency.
  54. yyextra->newDependency();
  55. }
  56. {WSPACE}+ {
  57. // Rules and dependencies are separated by blocks of whitespace.
  58. yyextra->newRuleOrDependency();
  59. }
  60. [a-zA-Z0-9+,/_.~()}{%=@\x5B\x5D!\x80-\xFF-]+ {
  61. // Got a span of plain text.
  62. yyextra->addToCurrentPath(yytext);
  63. }
  64. . {
  65. // Got an otherwise unmatched character.
  66. yyextra->addToCurrentPath(yytext);
  67. }
  68. %%
  69. /*--------------------------------------------------------------------------*/
  70. #endif /* __clang_analyzer__ */