cmCommandArgumentParser.y 4.1 KB

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