Skip to content

Commit ef3632b

Browse files
author
Sebastiano Merlino
committed
Added rules to handle INCLUDES
1 parent e6207aa commit ef3632b

File tree

1 file changed

+107
-11
lines changed

1 file changed

+107
-11
lines changed

ael.y

Lines changed: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,20 @@ char* grow_string(char* head, char* tail)
140140
return s;
141141
}
142142

143+
char* handleIncludedName(char* name)
144+
{
145+
stringstream ss;
146+
ss << "\"" << name << "\"";
147+
return alloc_string((char*)ss.str().data());
148+
}
149+
143150
char* handleMacroDef(char* name,char* arglist, char* stats)
144151
{
145152
stringstream ss;
146153
ss<<"function "<<name<<"("<<arglist<<")"<<endl;
147154
ss<<stats;
148155
ss<<"end"<<endl<<endl;
149-
return (char*)ss.str().data();
156+
return alloc_string((char*)ss.str().data());
150157
}
151158

152159
char* handleContext(char* name,char* content)
@@ -387,7 +394,14 @@ element: extension
387394
| SEMICOLON { $$ = alloc_string((char*)";"); }
388395
;
389396

390-
ignorepat: IGNOREPAT ARROW word SEMICOLON;
397+
ignorepat: IGNOREPAT ARROW word SEMICOLON
398+
{
399+
stringstream ss;
400+
ss << "[\"ignorepat\"] = " << $3;
401+
$$ = alloc_string((char*)ss.str().data());
402+
destroy_string($3);
403+
}
404+
;
391405

392406

393407
extension: word ARROW statement
@@ -457,16 +471,20 @@ ifTime_head: IFTIME LPAREN word3_list COLON word3_list COLON word3_list PIPE
457471
| IFTIME LPAREN word PIPE word3_list PIPE word3_list PIPE word3_list RPAREN
458472
;
459473

460-
word3_list: word { $$ = $1; }
461-
| word word
474+
word3_list:
475+
word
476+
{
477+
$$ = $1;
478+
}
479+
| word word
462480
{
463481
stringstream ss;
464482
ss << $1 << " " << $2;
465483
$$ = alloc_string((char*)ss.str().c_str());
466484
destroy_string($1);
467485
destroy_string($2);
468486
}
469-
| word word word
487+
| word word word
470488
{
471489
stringstream ss;
472490
ss << $1 << " " << $2 << " " << $3;
@@ -721,22 +739,100 @@ switchlist: word SEMICOLON
721739
| switchlist word SEMICOLON
722740
;
723741

724-
includeslist: includedname SEMICOLON
742+
includeslist:
743+
includedname SEMICOLON
744+
{
745+
stringstream ss;
746+
ss << handleIncludedName($1);
747+
$$ = alloc_string((char*)ss.str().data());
748+
destroy_string($1);
749+
}
725750
| includedname PIPE word3_list COLON word3_list COLON word3_list PIPE word3_list PIPE word3_list PIPE word3_list SEMICOLON
751+
{
752+
stringstream ss;
753+
ss << $1 << "|" << $3 << ":" << $5 << ":" << $7 << "|" << $9 << "|" << $11 << "|" << $13;
754+
$$ = alloc_string(handleIncludedName((char*)ss.str().data()));
755+
destroy_string($1);
756+
destroy_string($3);
757+
destroy_string($5);
758+
destroy_string($7);
759+
destroy_string($9);
760+
destroy_string($11);
761+
destroy_string($13);
762+
}
726763
| includedname PIPE word PIPE word3_list PIPE word3_list PIPE word3_list SEMICOLON
764+
{
765+
stringstream ss;
766+
ss << $1 << "|" << $3 << "|" << $5 << "|" << $7 << "|" << $9;
767+
$$ = alloc_string(handleIncludedName((char*)ss.str().data()));
768+
destroy_string($1);
769+
destroy_string($3);
770+
destroy_string($5);
771+
destroy_string($7);
772+
destroy_string($9);
773+
}
727774
| includeslist includedname SEMICOLON
775+
{
776+
stringstream ss;
777+
ss << "," << handleIncludedName($2);
778+
$$ = grow_string($1, (char*) ss.str().data());
779+
destroy_string($1);
780+
destroy_string($2);
781+
}
728782
| includeslist includedname PIPE word3_list COLON word3_list COLON word3_list PIPE word3_list PIPE word3_list PIPE word3_list SEMICOLON
783+
{
784+
stringstream ss;
785+
stringstream iss;
786+
iss << $2 << "|" << $4 << ":" << $6 << ":" << $8 << "|" << $10 << "|" << $12 << "|" << $13;
787+
char* name = handleIncludedName((char*) iss.str().data());
788+
ss << "," << name;
789+
$$ = grow_string($1, (char*) ss.str().data());
790+
destroy_string($2);
791+
destroy_string($4);
792+
destroy_string($6);
793+
destroy_string($8);
794+
destroy_string($10);
795+
destroy_string($12);
796+
destroy_string($13);
797+
}
729798
| includeslist includedname PIPE word PIPE word3_list PIPE word3_list PIPE word3_list SEMICOLON
799+
{
800+
stringstream ss;
801+
stringstream iss;
802+
iss << $2 << "|" << $4 << "|" << $6 << "|" << $8 << "|" << $10;
803+
char* name = handleIncludedName((char*) iss.str().data());
804+
ss << "," << name;
805+
$$ = grow_string($1, (char*) ss.str().data());
806+
destroy_string($2);
807+
destroy_string($4);
808+
destroy_string($6);
809+
destroy_string($8);
810+
destroy_string($10);
811+
}
730812
;
731813

732-
includedname: word
733-
| DEFAULT
734-
;
814+
includedname:
815+
word
816+
{
817+
$$ = $1;
818+
}
819+
| DEFAULT
820+
{
821+
$$ = alloc_string((char*) "default");
822+
}
823+
;
735824

736-
includes: INCLUDES BRA includeslist KET
825+
includes:
826+
INCLUDES BRA includeslist KET
827+
{
828+
stringstream ss;
829+
ss << "include = { " << $3 << " }";
830+
$$ = alloc_string((char*)ss.str().data());
831+
destroy_string($3);
832+
}
737833
| INCLUDES BRA KET
738834
{
739-
printf("\t includes block!\n");
835+
$$ = alloc_string((char*) "include = {}");
740836
}
741837
;
742838

0 commit comments

Comments
 (0)