cmCommandArgumentParser.y 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. %{
  2. /*=========================================================================
  3. Program: CMake - Cross-Platform Makefile Generator
  4. Module: $RCSfile$
  5. Language: C++
  6. Date: $Date$
  7. Version: $Revision$
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. /*
  15. This file must be translated to C and modified to build everywhere.
  16. Run bison like this:
  17. bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
  18. Modify cmCommandArgumentParser.cxx:
  19. - remove TABs
  20. */
  21. #include "cmStandardIncludes.h"
  22. /* Configure the parser to use a lexer object. */
  23. #define YYPARSE_PARAM yyscanner
  24. #define YYLEX_PARAM yyscanner
  25. #define YYERROR_VERBOSE 1
  26. #define cmCommandArgument_yyerror(x) \
  27. cmCommandArgumentError(yyscanner, x)
  28. #define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
  29. /* Make sure malloc and free are available on QNX. */
  30. #ifdef __QNX__
  31. # include <malloc.h>
  32. #endif
  33. /* Make sure the parser uses standard memory allocation. The default
  34. generated parser malloc/free declarations do not work on all
  35. platforms. */
  36. #include <stdlib.h>
  37. #define YYMALLOC malloc
  38. #define YYFREE free
  39. /*-------------------------------------------------------------------------*/
  40. #include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
  41. #include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
  42. #include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  43. /* Forward declare the lexer entry point. */
  44. YY_DECL;
  45. /* Internal utility functions. */
  46. static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
  47. #define YYDEBUG 1
  48. //#define YYMAXDEPTH 100000
  49. //#define YYINITDEPTH 10000
  50. /* Disable some warnings in the generated code. */
  51. #ifdef __BORLANDC__
  52. # pragma warn -8004 /* Variable assigned a value that is not used. */
  53. # pragma warn -8008 /* condition always returns true */
  54. # pragma warn -8060 /* possibly incorrect assignment */
  55. # pragma warn -8066 /* unreachable code */
  56. #endif
  57. #ifdef _MSC_VER
  58. # pragma warning (disable: 4102) /* Unused goto label. */
  59. # pragma warning (disable: 4065) /* Switch statement contains default but no
  60. case. */
  61. #endif
  62. %}
  63. /* Generate a reentrant parser object. */
  64. %pure_parser
  65. /*
  66. %union {
  67. char* string;
  68. }
  69. */
  70. /*-------------------------------------------------------------------------*/
  71. /* Tokens */
  72. %token cal_NCURLY
  73. %token cal_DCURLY
  74. %token cal_DOLLAR "$"
  75. %token cal_LCURLY "{"
  76. %token cal_RCURLY "}"
  77. %token cal_NAME
  78. %token cal_BSLASH "\\"
  79. %token cal_SYMBOL
  80. %token cal_AT "@"
  81. %token cal_ERROR
  82. %token cal_ATNAME
  83. /*-------------------------------------------------------------------------*/
  84. /* grammar */
  85. %%
  86. Start:
  87. GoalWithOptionalBackSlash
  88. {
  89. $<str>$ = 0;
  90. yyGetParser->SetResult($<str>1);
  91. }
  92. GoalWithOptionalBackSlash:
  93. Goal
  94. {
  95. $<str>$ = $<str>1;
  96. }
  97. |
  98. Goal cal_BSLASH
  99. {
  100. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  101. }
  102. Goal:
  103. {
  104. $<str>$ = 0;
  105. }
  106. |
  107. String Goal
  108. {
  109. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  110. }
  111. String:
  112. OuterText
  113. {
  114. $<str>$ = $<str>1;
  115. }
  116. |
  117. Variable
  118. {
  119. $<str>$ = $<str>1;
  120. }
  121. OuterText:
  122. cal_NAME
  123. {
  124. $<str>$ = $<str>1;
  125. }
  126. |
  127. cal_AT
  128. {
  129. $<str>$ = $<str>1;
  130. }
  131. |
  132. cal_DOLLAR
  133. {
  134. $<str>$ = $<str>1;
  135. }
  136. |
  137. cal_LCURLY
  138. {
  139. $<str>$ = $<str>1;
  140. }
  141. |
  142. cal_RCURLY
  143. {
  144. $<str>$ = $<str>1;
  145. }
  146. |
  147. cal_SYMBOL
  148. {
  149. $<str>$ = $<str>1;
  150. }
  151. Variable:
  152. cal_NCURLY MultipleIds cal_RCURLY
  153. {
  154. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  155. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  156. }
  157. |
  158. cal_DCURLY MultipleIds cal_RCURLY
  159. {
  160. $<str>$ = yyGetParser->ExpandVariable($<str>2);
  161. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  162. }
  163. |
  164. cal_ATNAME
  165. {
  166. $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
  167. }
  168. MultipleIds:
  169. {
  170. $<str>$ = 0;
  171. }
  172. |
  173. ID MultipleIds
  174. {
  175. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  176. }
  177. ID:
  178. cal_NAME
  179. {
  180. $<str>$ = $<str>1;
  181. }
  182. |
  183. Variable
  184. {
  185. $<str>$ = $<str>1;
  186. }
  187. %%
  188. /* End of grammar */
  189. /*--------------------------------------------------------------------------*/
  190. void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
  191. {
  192. yyGetParser->Error(message);
  193. }