cmCommandArgumentLexer.in.l 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /*
  5. This file must be translated to C and modified to build everywhere.
  6. Run flex like this:
  7. flex --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
  8. Modify cmCommandArgumentLexer.cxx:
  9. - add #include "cmStandardIncludes.h" to top of file
  10. - put header block at top of file
  11. - remove TABs
  12. - remove use of the 'register' storage class specifier
  13. - remove "yyscanner" argument from these methods:
  14. yy_fatal_error, cmCommandArgument_yyalloc, cmCommandArgument_yyrealloc, cmCommandArgument_yyfree
  15. - remove all YY_BREAK lines occurring right after return statements
  16. - change while ( 1 ) to for(;;)
  17. - add "return 0;" to end of cmCommandArgument_yylex
  18. Modify cmCommandArgumentLexer.h:
  19. - remove TABs
  20. - remove the yy_init_globals function
  21. - remove the block that includes unistd.h
  22. - remove #line directives (avoids bogus warning on old Sun)
  23. */
  24. #include "cmStandardLexer.h"
  25. #include "cmCommandArgumentParserHelper.h"
  26. /* Replace the lexer input function. */
  27. #undef YY_INPUT
  28. #define YY_INPUT(buf, result, max_size) \
  29. { result = yyextra->LexInput(buf, max_size); }
  30. /* Include the set of tokens from the parser. */
  31. #include "cmCommandArgumentParserTokens.h"
  32. /*--------------------------------------------------------------------------*/
  33. %}
  34. %option reentrant
  35. %option noyywrap
  36. %option nounput
  37. %pointer
  38. %s ESCAPES
  39. %s NOESCAPES
  40. %%
  41. \$ENV\{ {
  42. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  43. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  44. return cal_ENVCURLY;
  45. }
  46. \$[A-Za-z0-9/_.+-]+\{ {
  47. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  48. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  49. return cal_NCURLY;
  50. }
  51. @[A-Za-z0-9/_.+-]+@ {
  52. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  53. yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
  54. return cal_ATNAME;
  55. }
  56. "${" {
  57. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  58. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  59. yylvalp->str = yyextra->DCURLYVariable;
  60. return cal_DCURLY;
  61. }
  62. "}" {
  63. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  64. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  65. yylvalp->str = yyextra->RCURLYVariable;
  66. return cal_RCURLY;
  67. }
  68. "@" {
  69. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  70. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  71. yylvalp->str = yyextra->ATVariable;
  72. return cal_AT;
  73. }
  74. [A-Za-z0-9/_.+-]+ {
  75. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  76. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  77. return cal_NAME;
  78. }
  79. <ESCAPES>\\. {
  80. if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
  81. {
  82. return cal_ERROR;
  83. }
  84. return cal_SYMBOL;
  85. }
  86. [^\${}\\@]+ {
  87. //std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
  88. yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  89. return cal_SYMBOL;
  90. }
  91. "$" {
  92. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  93. yylvalp->str = yyextra->DOLLARVariable;
  94. return cal_DOLLAR;
  95. }
  96. "{" {
  97. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  98. yylvalp->str = yyextra->LCURLYVariable;
  99. return cal_LCURLY;
  100. }
  101. <ESCAPES>"\\" {
  102. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  103. yylvalp->str = yyextra->BSLASHVariable;
  104. return cal_BSLASH;
  105. }
  106. <NOESCAPES>"\\" {
  107. //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
  108. yylvalp->str = yyextra->BSLASHVariable;
  109. return cal_SYMBOL;
  110. }
  111. %%
  112. /*--------------------------------------------------------------------------*/
  113. void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
  114. {
  115. /* Hack into the internal flex-generated scanner to set the state. */
  116. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  117. if(noEscapes)
  118. {
  119. BEGIN(NOESCAPES);
  120. }
  121. else
  122. {
  123. BEGIN(ESCAPES);
  124. }
  125. }