Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize Parameterizing rules testing #404

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,21 @@
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);

%}

%union {
int i;
char *s;
}

%token <i> number
%token <s> string

%rule defined_option(X): /* empty */
| X
;

%rule multi_args(X, Y): X
| Y
;

%rule unused_define(X): /* empty */
| X
;

%rule pair(X, Y): X ',' Y { printf("(%d, %d)\n", $1, $2); }
;

%%

program : defined_option(number) <i>
| multi_args(number, string)
| multi_args(number, number)
| pair(number, string) { printf("pair odd even\n"); }
;

%%
Expand Down
43 changes: 43 additions & 0 deletions spec/fixtures/parameterizing_rules/user_defined/multi_arguments.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This is comment for this file.
*/

%{
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}

%union {
int i;
char *s;
}

%token <i> number
%token <s> string

%rule pair(X, Y): X
| Y
;

%%

program : pair(number, string)
| pair(number, number)
;

%%

static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
{
return 0;
}

static int yyerror(YYLTYPE *loc, const char *str)
{
return 0;
}

int main(int argc, char *argv[])
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ static int yyerror(YYLTYPE *loc, const char *str);

%union {
int i;
char* s;
}

%token <i> number
%token <s> string

%rule nested_nested_option(X): /* empty */
| X
Expand All @@ -28,24 +26,9 @@ static int yyerror(YYLTYPE *loc, const char *str);
| nested_option(Y)
;

%rule nested_multi_option(X): /* empty */
| X
;

%rule multi_option(X, Y): /* empty */
| nested_multi_option(X)
| nested_multi_option(Y) X
;

%rule with_word_seps(X): /* empty */
| X ' '+
;

%%

program : option(number)
| multi_option(number, string)
| with_word_seps(string)
;

%%
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This is comment for this file.
*/

%{
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}

%union {
int i;
char* s;
}

%token <i> number
%token <s> string

%rule nested_multi_option(X): /* empty */
| X
;

%rule multi_option(X, Y): /* empty */
| nested_multi_option(X)
| nested_multi_option(Y) X
;

%%

program : multi_option(number, string)
;

%%

static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
{
return 0;
}

static int yyerror(YYLTYPE *loc, const char *str)
{
return 0;
}

int main(int argc, char *argv[])
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This is comment for this file.
*/

%{
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}

%union {
char* s;
}

%token <s> string

%rule with_word_seps(X): /* empty */
| X ' '+
;

%%

program : with_word_seps(string)
;

%%

static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
{
return 0;
}

static int yyerror(YYLTYPE *loc, const char *str)
{
return 0;
}

int main(int argc, char *argv[])
{
}
41 changes: 41 additions & 0 deletions spec/fixtures/parameterizing_rules/user_defined/with_action.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This is comment for this file.
*/

%{
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}

%union {
int i;
char *s;
}

%token <i> number
%token <s> string

%rule pair(X, Y): X ',' Y { printf("(%d, %d)\n", $1, $2); }
;

%%

program : pair(number, string) { printf("pair odd even\n"); }
;

%%

static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
{
return 0;
}

static int yyerror(YYLTYPE *loc, const char *str)
{
return 0;
}

int main(int argc, char *argv[])
{
}
Loading