Skip to content

Commit

Permalink
Merge pull request #404 from ydah/organize-test-for-parameterizingrules
Browse files Browse the repository at this point in the history
Organize Parameterizing rules testing
  • Loading branch information
yui-knk authored Apr 29, 2024
2 parents e2d9fd3 + 64e3462 commit 595472f
Show file tree
Hide file tree
Showing 21 changed files with 1,586 additions and 1,340 deletions.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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

0 comments on commit 595472f

Please sign in to comment.