cmCommandArgumentParser.y 5.0 KB

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