cmCommandArgumentParser.y 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. %{
  2. /*============================================================================
  3. CMake - Cross Platform Makefile Generator
  4. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. /*
  12. This file must be translated to C and modified to build everywhere.
  13. Run bison like this:
  14. bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y
  15. Modify cmCommandArgumentParser.cxx:
  16. - remove TABs
  17. - remove use of the 'register' storage class specifier
  18. - put header block at top of file
  19. */
  20. #include "cmStandardIncludes.h"
  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 malloc and free are available on QNX. */
  29. #ifdef __QNX__
  30. # include <malloc.h>
  31. #endif
  32. /* Make sure the parser uses standard memory allocation. The default
  33. generated parser malloc/free declarations do not work on all
  34. platforms. */
  35. #include <stdlib.h>
  36. #define YYMALLOC malloc
  37. #define YYFREE free
  38. /*-------------------------------------------------------------------------*/
  39. #include "cmCommandArgumentParserHelper.h" /* Interface to parser object. */
  40. #include "cmCommandArgumentLexer.h" /* Interface to lexer object. */
  41. #include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  42. /* Forward declare the lexer entry point. */
  43. YY_DECL;
  44. /* Internal utility functions. */
  45. static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
  46. #define YYDEBUG 1
  47. /* Configure the parser to support large input. */
  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. # pragma warning (disable: 4244) /* loss of precision */
  62. # pragma warning (disable: 4702) /* unreachable code */
  63. #endif
  64. %}
  65. /* Generate a reentrant parser object. */
  66. %pure_parser
  67. /*
  68. %union {
  69. char* string;
  70. }
  71. */
  72. /*-------------------------------------------------------------------------*/
  73. /* Tokens */
  74. %token cal_ENVCURLY
  75. %token cal_NCURLY
  76. %token cal_DCURLY
  77. %token cal_DOLLAR "$"
  78. %token cal_LCURLY "{"
  79. %token cal_RCURLY "}"
  80. %token cal_NAME
  81. %token cal_BSLASH "\\"
  82. %token cal_SYMBOL
  83. %token cal_AT "@"
  84. %token cal_ERROR
  85. %token cal_ATNAME
  86. /*-------------------------------------------------------------------------*/
  87. /* grammar */
  88. %%
  89. Start:
  90. GoalWithOptionalBackSlash
  91. {
  92. $<str>$ = 0;
  93. yyGetParser->SetResult($<str>1);
  94. }
  95. GoalWithOptionalBackSlash:
  96. Goal
  97. {
  98. $<str>$ = $<str>1;
  99. }
  100. |
  101. Goal cal_BSLASH
  102. {
  103. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  104. }
  105. Goal:
  106. {
  107. $<str>$ = 0;
  108. }
  109. |
  110. String Goal
  111. {
  112. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  113. }
  114. String:
  115. OuterText
  116. {
  117. $<str>$ = $<str>1;
  118. }
  119. |
  120. Variable
  121. {
  122. $<str>$ = $<str>1;
  123. }
  124. OuterText:
  125. cal_NAME
  126. {
  127. $<str>$ = $<str>1;
  128. }
  129. |
  130. cal_AT
  131. {
  132. $<str>$ = $<str>1;
  133. }
  134. |
  135. cal_DOLLAR
  136. {
  137. $<str>$ = $<str>1;
  138. }
  139. |
  140. cal_LCURLY
  141. {
  142. $<str>$ = $<str>1;
  143. }
  144. |
  145. cal_RCURLY
  146. {
  147. $<str>$ = $<str>1;
  148. }
  149. |
  150. cal_SYMBOL
  151. {
  152. $<str>$ = $<str>1;
  153. }
  154. Variable:
  155. cal_ENVCURLY EnvVarName cal_RCURLY
  156. {
  157. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  158. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  159. }
  160. |
  161. cal_NCURLY MultipleIds cal_RCURLY
  162. {
  163. $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  164. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  165. }
  166. |
  167. cal_DCURLY MultipleIds cal_RCURLY
  168. {
  169. $<str>$ = yyGetParser->ExpandVariable($<str>2);
  170. //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
  171. }
  172. |
  173. cal_ATNAME
  174. {
  175. $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
  176. }
  177. EnvVarName:
  178. MultipleIds
  179. {
  180. $<str>$ = $<str>1;
  181. }
  182. |
  183. cal_SYMBOL EnvVarName
  184. {
  185. $<str>$ = $<str>1;
  186. }
  187. MultipleIds:
  188. {
  189. $<str>$ = 0;
  190. }
  191. |
  192. ID MultipleIds
  193. {
  194. $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  195. }
  196. ID:
  197. cal_NAME
  198. {
  199. $<str>$ = $<str>1;
  200. }
  201. |
  202. Variable
  203. {
  204. $<str>$ = $<str>1;
  205. }
  206. %%
  207. /* End of grammar */
  208. /*--------------------------------------------------------------------------*/
  209. void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
  210. {
  211. yyGetParser->Error(message);
  212. }