cmCommandArgumentParser.y 4.3 KB

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