You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
4.1 KiB
192 lines
4.1 KiB
16 years ago
|
%{
|
||
8 years ago
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||
16 years ago
|
/*
|
||
|
|
||
|
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:
|
||
8 years ago
|
- "#if 0" out yyerrorlab block in range ["goto yyerrlab1", "yyerrlab1:"]
|
||
16 years ago
|
|
||
|
*/
|
||
|
|
||
8 years ago
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||
|
|
||
|
#include <string.h>
|
||
16 years ago
|
|
||
|
#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;
|
||
|
|
||
8 years ago
|
/* Helper function to forward error callback from parser. */
|
||
|
static void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message);
|
||
16 years ago
|
|
||
16 years ago
|
/* Configure the parser to support large input. */
|
||
|
#define YYMAXDEPTH 100000
|
||
|
#define YYINITDEPTH 10000
|
||
16 years ago
|
|
||
|
/* 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. */
|
||
16 years ago
|
# pragma warning (disable: 4244) /* loss of precision */
|
||
|
# pragma warning (disable: 4702) /* unreachable code */
|
||
16 years ago
|
#endif
|
||
|
%}
|
||
|
|
||
|
/* Generate a reentrant parser object. */
|
||
8 years ago
|
%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
|
||
16 years ago
|
|
||
|
/*
|
||
|
%union {
|
||
|
char* string;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
/*-------------------------------------------------------------------------*/
|
||
|
/* Tokens */
|
||
16 years ago
|
%token cal_ENVCURLY
|
||
16 years ago
|
%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:
|
||
8 years ago
|
GoalWithOptionalBackSlash {
|
||
|
$<str>$ = 0;
|
||
|
yyGetParser->SetResult($<str>1);
|
||
|
}
|
||
16 years ago
|
|
||
|
GoalWithOptionalBackSlash:
|
||
8 years ago
|
Goal {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
|
| Goal cal_BSLASH {
|
||
|
$<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
|
||
|
}
|
||
16 years ago
|
|
||
|
Goal:
|
||
8 years ago
|
{
|
||
|
$<str>$ = 0;
|
||
|
}
|
||
|
| String Goal {
|
||
|
$<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
|
||
|
}
|
||
16 years ago
|
|
||
|
String:
|
||
8 years ago
|
OuterText {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
|
| Variable {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
16 years ago
|
|
||
|
OuterText:
|
||
8 years ago
|
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;
|
||
|
}
|
||
16 years ago
|
|
||
|
Variable:
|
||
8 years ago
|
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);
|
||
|
}
|
||
16 years ago
|
|
||
16 years ago
|
EnvVarName:
|
||
8 years ago
|
MultipleIds {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
|
| cal_SYMBOL EnvVarName {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
16 years ago
|
|
||
16 years ago
|
MultipleIds:
|
||
8 years ago
|
{
|
||
|
$<str>$ = 0;
|
||
|
}
|
||
|
| ID MultipleIds {
|
||
|
$<str>$ = yyGetParser->CombineUnions($<str>1, $<str>2);
|
||
|
}
|
||
16 years ago
|
|
||
|
ID:
|
||
8 years ago
|
cal_NAME {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
|
| Variable {
|
||
|
$<str>$ = $<str>1;
|
||
|
}
|
||
|
;
|
||
16 years ago
|
|
||
|
%%
|
||
|
/* End of grammar */
|
||
|
|
||
|
/*--------------------------------------------------------------------------*/
|
||
8 years ago
|
void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message)
|
||
16 years ago
|
{
|
||
|
yyGetParser->Error(message);
|
||
|
}
|