cmCommandArgumentParser.y 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 bison like this:
  7. bison --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
  8. */
  9. #include "cmConfigure.h" // IWYU pragma: keep
  10. #include <string.h>
  11. #define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
  12. /* Make sure malloc and free are available on QNX. */
  13. #ifdef __QNX__
  14. # include <malloc.h>
  15. #endif
  16. #include <stdint.h>
  17. /* Make sure the parser uses standard memory allocation. The default
  18. generated parser malloc/free declarations do not work on all
  19. platforms. */
  20. #include <stdlib.h>
  21. #define YYMALLOC malloc
  22. #define YYFREE free
  23. /*-------------------------------------------------------------------------*/
  24. #include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
  25. #include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
  26. /* Forward declare the lexer entry point. */
  27. YY_DECL;
  28. /* Helper function to forward error callback from parser. */
  29. static void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message);
  30. /* Configure the parser to support large input. */
  31. #define YYMAXDEPTH 100000
  32. #define YYINITDEPTH 10000
  33. /* Disable some warnings in the generated code. */
  34. #ifdef _MSC_VER
  35. # pragma warning (disable: 4102) /* Unused goto label. */
  36. # pragma warning (disable: 4065) /* Switch statement contains default but no
  37. case. */
  38. # pragma warning (disable: 4244) /* loss of precision */
  39. # pragma warning (disable: 4702) /* unreachable code */
  40. #endif
  41. #if defined(__GNUC__) && __GNUC__ >= 8
  42. # pragma GCC diagnostic ignored "-Wconversion"
  43. # pragma GCC diagnostic ignored "-Wfree-nonheap-object"
  44. #endif
  45. #if defined(__clang__) && defined(__has_warning)
  46. # if __has_warning("-Wunused-but-set-variable")
  47. # pragma clang diagnostic ignored "-Wunused-but-set-variable"
  48. # endif
  49. #endif
  50. %}
  51. /* Generate a reentrant parser object. */
  52. %define api.pure
  53. /* Configure the parser to use a lexer object. */
  54. %lex-param {yyscan_t yyscanner}
  55. %parse-param {yyscan_t yyscanner}
  56. %define parse.error verbose
  57. /*
  58. %union {
  59. char* string;
  60. }
  61. */
  62. /*-------------------------------------------------------------------------*/
  63. /* Tokens */
  64. %token cal_ENVCURLY
  65. %token cal_NCURLY
  66. %token cal_DCURLY
  67. %token cal_DOLLAR "$"
  68. %token cal_LCURLY "{"
  69. %token cal_RCURLY "}"
  70. %token cal_NAME
  71. %token cal_BSLASH "\\"
  72. %token cal_SYMBOL
  73. %token cal_AT "@"
  74. %token cal_ERROR
  75. %token cal_ATNAME
  76. /*-------------------------------------------------------------------------*/
  77. /* grammar */
  78. %%
  79. Start:
  80. GoalWithOptionalBackSlash {
  81. $<str>$ = 0;
  82. yyGetParser->SetResult($<str>1);
  83. }
  84. GoalWithOptionalBackSlash:
  85. Goal {
  86. $<str>$ = $<str>1;
  87. }
  88. | Goal cal_BSLASH {
  89. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  90. }
  91. Goal:
  92. {
  93. $<str>$ = 0;
  94. }
  95. | String Goal {
  96. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  97. }
  98. String:
  99. OuterText {
  100. $<str>$ = $<str>1;
  101. }
  102. | Variable {
  103. $<str>$ = $<str>1;
  104. }
  105. OuterText:
  106. cal_NAME {
  107. $<str>$ = $<str>1;
  108. }
  109. | cal_AT {
  110. $<str>$ = $<str>1;
  111. }
  112. | cal_DOLLAR {
  113. $<str>$ = $<str>1;
  114. }
  115. | cal_LCURLY {
  116. $<str>$ = $<str>1;
  117. }
  118. | cal_RCURLY {
  119. $<str>$ = $<str>1;
  120. }
  121. | cal_SYMBOL {
  122. $<str>$ = $<str>1;
  123. }
  124. Variable:
  125. cal_ENVCURLY EnvVarName cal_RCURLY {
  126. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1, $<str>2);
  127. }
  128. | cal_NCURLY MultipleIds cal_RCURLY {
  129. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1, $<str>2);
  130. }
  131. | cal_DCURLY MultipleIds cal_RCURLY {
  132. $<str>$ = yyGetParser->ExpandVariable($<str>2);
  133. }
  134. | cal_ATNAME {
  135. $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
  136. }
  137. EnvVarName:
  138. MultipleIds {
  139. $<str>$ = $<str>1;
  140. }
  141. | cal_SYMBOL EnvVarName {
  142. $<str>$ = $<str>1;
  143. }
  144. MultipleIds:
  145. {
  146. $<str>$ = 0;
  147. }
  148. | ID MultipleIds {
  149. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  150. }
  151. ID:
  152. cal_NAME {
  153. $<str>$ = $<str>1;
  154. }
  155. | Variable {
  156. $<str>$ = $<str>1;
  157. }
  158. ;
  159. %%
  160. /* End of grammar */
  161. /*--------------------------------------------------------------------------*/
  162. void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message)
  163. {
  164. yyGetParser->Error(message);
  165. }