summaryrefslogtreecommitdiffstats
path: root/Source/LexerParser/cmCommandArgumentParser.y
blob: 0c6aad547ae991300853e4a8268e53a59eb414a8 (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
%{
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
/*

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:
  - "#if 0" out yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]

*/

#include "cmConfigure.h" // IWYU pragma: keep

#include <string.h>

#define yyGetParser (cmCommandArgument_yyget_extra(yyscanner))

/* Make sure malloc and free are available on QNX.  */
#ifdef __QNX__
# include <malloc.h>
#endif

/* Make sure the parser uses standard memory allocation.  The default
   generated parser malloc/free declarations do not work on all
   platforms.  */
#include <stdlib.h>
#define YYMALLOC malloc
#define YYFREE free

/*-------------------------------------------------------------------------*/
#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;

/* Helper function to forward error callback from parser.  */
static void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message);

/* Configure the parser to support large input.  */
#define YYMAXDEPTH 100000
#define YYINITDEPTH 10000

/* Disable some warnings in the generated code.  */
#ifdef _MSC_VER
# pragma warning (disable: 4102) /* Unused goto label.  */
# pragma warning (disable: 4065) /* Switch statement contains default but no
                                    case. */
# pragma warning (disable: 4244) /* loss of precision */
# pragma warning (disable: 4702) /* unreachable code */
#endif
#if defined(__GNUC__) && __GNUC__ >= 8
# pragma GCC diagnostic ignored "-Wconversion"
#endif
%}

/* Generate a reentrant parser object.  */
%define api.pure

/* Configure the parser to use a lexer object.  */
%lex-param   {yyscan_t yyscanner}
%parse-param {yyscan_t yyscanner}

%define parse.error verbose

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

/*-------------------------------------------------------------------------*/
/* Tokens */
%token cal_ENVCURLY
%token cal_NCURLY
%token cal_DCURLY
%token cal_DOLLAR "$"
%token cal_LCURLY "{"
%token cal_RCURLY "}"
%token cal_NAME
%token cal_BSLASH "\\"
%token cal_SYMBOL
%token cal_AT     "@"
%token cal_ERROR
%token cal_ATNAME

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


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

GoalWithOptionalBackSlash:
  Goal {
    $<str>$ = $<str>1;
  }
| Goal cal_BSLASH {
    $<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
  }

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

String:
  OuterText {
    $<str>$ = $<str>1;
  }
| Variable {
    $<str>$ = $<str>1;
  }

OuterText:
  cal_NAME {
    $<str>$ = $<str>1;
  }
| cal_AT {
    $<str>$ = $<str>1;
  }
| cal_DOLLAR {
    $<str>$ = $<str>1;
  }
| cal_LCURLY {
    $<str>$ = $<str>1;
  }
| cal_RCURLY {
    $<str>$ = $<str>1;
  }
| cal_SYMBOL {
    $<str>$ = $<str>1;
  }

Variable:
  cal_ENVCURLY EnvVarName cal_RCURLY {
    $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1, $<str>2);
  }
| cal_NCURLY MultipleIds cal_RCURLY {
    $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1, $<str>2);
  }
| cal_DCURLY MultipleIds cal_RCURLY {
    $<str>$ = yyGetParser->ExpandVariable($<str>2);
  }
| cal_ATNAME {
    $<str>$ = yyGetParser->ExpandVariableForAt($<str>1);
  }

EnvVarName:
  MultipleIds {
    $<str>$ = $<str>1;
  }
| cal_SYMBOL EnvVarName {
    $<str>$ = $<str>1;
  }

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

ID:
  cal_NAME {
    $<str>$ = $<str>1;
  }
| Variable {
    $<str>$ = $<str>1;
  }
;

%%
/* End of grammar */

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