cmCommandArgumentParser.y 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. /* Configure the parser to use a lexer object. */
  22. #define YYPARSE_PARAM yyscanner
  23. #define YYLEX_PARAM yyscanner
  24. #define YYERROR_VERBOSE 1
  25. #define cmCommandArgument_yyerror(x) \
  26. cmCommandArgumentError(yyscanner, x)
  27. #define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))
  28. /* Make sure the parser uses standard memory allocation. The default
  29. generated parser malloc/free declarations do not work on all
  30. platforms. */
  31. #include <stdlib.h>
  32. #define YYMALLOC malloc
  33. #define YYFREE free
  34. /*-------------------------------------------------------------------------*/
  35. #include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
  36. #include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
  37. #include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  38. /* Forward declare the lexer entry point. */
  39. YY_DECL;
  40. /* Internal utility functions. */
  41. static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
  42. #define YYDEBUG 1
  43. //#define YYMAXDEPTH 100000
  44. //#define YYINITDEPTH 10000
  45. /* Disable some warnings in the generated code. */
  46. #ifdef __BORLANDC__
  47. # pragma warn -8004 /* Variable assigned a value that is not used. */
  48. #endif
  49. #ifdef _MSC_VER
  50. # pragma warning (disable: 4102) /* Unused goto label. */
  51. # pragma warning (disable: 4065) /* Switch statement contains default but no case. */
  52. #endif
  53. %}
  54. /* Generate a reentrant parser object. */
  55. %pure_parser
  56. /*
  57. %union {
  58. char* string;
  59. }
  60. */
  61. /*-------------------------------------------------------------------------*/
  62. /* Tokens */
  63. %token cal_NCURLY
  64. %token cal_DCURLY
  65. %token cal_DOLLAR "$"
  66. %token cal_LCURLY "{"
  67. %token cal_RCURLY "}"
  68. %token cal_NAME
  69. %token cal_BSLASH "\\"
  70. %token cal_SYMBOL
  71. %token cal_AT "@"
  72. %token cal_ERROR
  73. %token cal_ATNAME
  74. /*-------------------------------------------------------------------------*/
  75. /* grammar */
  76. %%
  77. Start:
  78. GoalWithOptionalBackSlash
  79. {
  80. $<str>$ = 0;
  81. yyGetParser->SetResult($<str>1);
  82. }
  83. GoalWithOptionalBackSlash:
  84. Goal
  85. {
  86. $<str>$ = $<str>1;
  87. }
  88. |
  89. Goal cal_BSLASH
  90. {
  91. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  92. }
  93. Goal:
  94. {
  95. $<str>$ = 0;
  96. }
  97. |
  98. String Goal
  99. {
  100. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  101. }
  102. String:
  103. OuterText
  104. {
  105. $<str>$ = $<str>1;
  106. }
  107. |
  108. Variable
  109. {
  110. $<str>$ = $<str>1;
  111. }
  112. OuterText:
  113. cal_NAME
  114. {
  115. $<str>$ = $<str>1;
  116. }
  117. |
  118. cal_AT
  119. {
  120. $<str>$ = $<str>1;
  121. }
  122. |
  123. cal_DOLLAR
  124. {
  125. $<str>$ = $<str>1;
  126. }
  127. |
  128. cal_LCURLY
  129. {
  130. $<str>$ = $<str>1;
  131. }
  132. |
  133. cal_RCURLY
  134. {
  135. $<str>$ = $<str>1;
  136. }
  137. |
  138. cal_SYMBOL
  139. {
  140. $<str>$ = $<str>1;
  141. }
  142. Variable:
  143. cal_NCURLY MultipleIds cal_RCURLY
  144. {
  145. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  146. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  147. }
  148. |
  149. cal_DCURLY MultipleIds cal_RCURLY
  150. {
  151. $<str>$ = yyGetParser->ExpandVariable($<str>2);
  152. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  153. }
  154. |
  155. cal_ATNAME
  156. {
  157. $<str>$ = yyGetParser->ExpandVariable($<str>1);
  158. }
  159. MultipleIds:
  160. {
  161. $<str>$ = 0;
  162. }
  163. |
  164. ID MultipleIds
  165. {
  166. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  167. }
  168. ID:
  169. cal_NAME
  170. {
  171. $<str>$ = $<str>1;
  172. }
  173. |
  174. Variable
  175. {
  176. $<str>$ = $<str>1;
  177. }
  178. %%
  179. /* End of grammar */
  180. /*--------------------------------------------------------------------------*/
  181. void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
  182. {
  183. yyGetParser->Error(message);
  184. }