Simple patch to allow fragments to include other fragments:

%fragment("Hello","header") "..."

%fragment("Hi","header",fragment="Hello") "..."

the latter fragment will include the first one if is invoked.

more than one fragment can be included at the time, just
keep adding fragment="f1",fragment="f2", etc.

this is used to emulate typemaps reuse, where all the
reusable typemap code is put in a fragment static method,
and then it can be included from another fragment typemap
as needed.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5690 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-27 23:39:35 +00:00
commit 6dceec6fdb
5 changed files with 64 additions and 16 deletions

View file

@ -1266,17 +1266,21 @@ except_directive : EXCEPT LPAREN ID RPAREN LBRACE {
%fragment(name,location) { ... }
------------------------------------------------------------ */
fragment_directive: FRAGMENT LPAREN idstring COMMA idstring RPAREN HBLOCK {
fragment_directive: FRAGMENT LPAREN kwargs RPAREN HBLOCK {
Hash *p = nextSibling($3);
$$ = new_node("fragment");
Setattr($$,"section", $5);
Setattr($$,"name",$3);
Setattr($$,"code",$7);
Setattr($$,"section", Getattr(p,"name"));
Setattr($$,"name",Getattr($3,"name"));
Setattr($$,"kwargs",nextSibling(p));
Setattr($$,"code",$5);
}
| FRAGMENT LPAREN idstring COMMA idstring RPAREN LBRACE {
| FRAGMENT LPAREN kwargs RPAREN LBRACE {
Hash *p = nextSibling($3);
skip_balanced('{','}');
$$ = new_node("fragment");
Setattr($$,"section",$5);
Setattr($$,"name",$3);
Setattr($$,"section", Getattr(p,"name"));
Setattr($$,"name",Getattr($3,"name"));
Setattr($$,"kwargs",nextSibling(p));
Delitem(scanner_ccode,0);
Delitem(scanner_ccode,DOH_END);
Setattr($$,"code",Copy(scanner_ccode));