cmGccDepfileLexer.in.l 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. :{WSPACE}+ {
  46. // A colon followed by space ends the rules and starts a new dependency.
  47. yyextra->newDependency();
  48. }
  49. {WSPACE}+ {
  50. // Rules and dependencies are separated by blocks of whitespace.
  51. yyextra->newRuleOrDependency();
  52. }
  53. [a-zA-Z0-9+,/_.~()}{%=@\x5B\x5D!\x80-\xFF-]+ {
  54. // Got a span of plain text.
  55. yyextra->addToCurrentPath(yytext);
  56. }
  57. . {
  58. // Got an otherwise unmatched character.
  59. yyextra->addToCurrentPath(yytext);
  60. }
  61. %%
  62. /*--------------------------------------------------------------------------*/
  63. #endif /* __clang_analyzer__ */