summaryrefslogtreecommitdiffstats
path: root/Source/cmCommandArgumentParser.y
blob: 05a06744689a86573722945db03dd506ccd11ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
%{
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
/*

This file must be translated to C and modified to build everywhere.

Run bison like this:

  bison --yacc --name-prefix=cmCommandArgument_yy --defines=cmCommandArgumentParserTokens.h -ocmCommandArgumentParser.cxx cmCommandArgumentParser.y

Modify cmCommandArgumentParser.cxx:
  - remove TABs
  - add __HP_aCC to the #if test for yyerrorlab warning suppression

*/

/* Configure the parser to use a lexer object.  */
#define YYPARSE_PARAM yyscanner
#define YYLEX_PARAM yyscanner
#define YYERROR_VERBOSE 1
#define cmCommandArgument_yyerror(x) \
        cmCommandArgumentError(yyscanner, x)
#define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))

/*-------------------------------------------------------------------------*/
#include "cmCommandArgumentParserHelper.h" /* Interface to parser object.  */
#include "cmCommandArgumentLexer.h"  /* Interface to lexer object.  */
#include "cmCommandArgumentParserTokens.h" /* Need YYSTYPE for YY_DECL.  */

/* Forward declare the lexer entry point.  */
YY_DECL;

/* Internal utility functions.  */
static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);

#define YYDEBUG 1
#define YYMAXDEPTH 1000000


#define calCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
#define calElementStart(cnt) yyGetParser->PrepareElement(&yyval)
/* Disable some warnings in the generated code.  */
#ifdef __BORLANDC__
# pragma warn -8004 /* Variable assigned a value that is not used.  */
#endif
#ifdef _MSC_VER
# pragma warning (disable: 4102) /* Unused goto label.  */
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
#endif
%}

/* Generate a reentrant parser object.  */
%pure_parser

/*
%union {
  char* string;
}
*/

/*-------------------------------------------------------------------------*/
/* Tokens */
%token cal_NCURLY
%token cal_DCURLY
%token cal_RCURLY
%token cal_NAME
%token cal_SYMBOL
%token cal_AT
%token cal_ERROR

/*-------------------------------------------------------------------------*/
/* grammar */
%%


Start:
Goal
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = 0;
  yyGetParser->SetResult($<str>1);
}

Goal:
String
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}
|
String Goal
{
  calElementStart(2);
  calCheckEmpty(2);
  $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
}

String:
TextWithRCurly
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}
|
Variable
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}

MultipleIds:
{
  calElementStart(0);
  calCheckEmpty(0);
}
|
ID MultipleIds
{
  calElementStart(2);
  calCheckEmpty(2);
  $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
}

ID:
Text
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}
|
Variable
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}

Text:
cal_NAME
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}
|
cal_SYMBOL
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}

TextWithRCurly:
Text
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}
|
cal_RCURLY
{
  calElementStart(1);
  calCheckEmpty(1);
  $<str>$ = $<str>1;
}

Variable:
cal_NCURLY MultipleIds cal_RCURLY
{
  calElementStart(3);
  calCheckEmpty(3);
  $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
  std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
}
|
cal_DCURLY MultipleIds cal_RCURLY
{
  calElementStart(3);
  calCheckEmpty(3);
  $<str>$ = yyGetParser->ExpandVariable($<str>2);
  std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
}
|
cal_AT cal_NAME cal_AT
{
  calElementStart(3);
  calCheckEmpty(3);
  $<str>$ = yyGetParser->ExpandVariable($<str>2);
}

%%
/* End of grammar */

/*--------------------------------------------------------------------------*/
void cmCommandArgumentError(yyscan_t yyscanner, const char* message)
{
  yyGetParser->Error(message);
}