Why are only parts of my strategies executed?
I have asked the question in question 12;
and I have added debug messages to the code;
The strategy is:generate-all= debug(!"before s1 "); generate-entity; debug(!"after s1 "); generate-dao; debug(!"after s2 ")and the debug info is:
before s1 (Module("entity"{[Module,"entity"]},[Entity("User"{[Entity,"User","entity"]},[Property("Username"{[Property,"Username","User","entity"]},Type("String"{[Entity,"String"]})),Property("Password"{[Property,"Password","User","entity"]},Type("String"{[Entity,"String"]}))])]),[],Module("entity"{[Module,"entity"]},[Entity("User"{[Entity,"User","entity"]},[Property("Username"{[Property,"Username","User","entity"]},Type("String"{[Entity,"String"]})),Property("Password"{[Property,"Password","User","entity"]},Type("String"{[Entity,"String"]}))])]),"login/User.ent","F:/Work Station/Other/sjtu.se.dsl") after s1 None rewriting failed, trace: generate_all_0_0 generate_dao_0_0I have change the sequence of
Asked by ZJG on 19 March 2013 at 07:44generate-entityandgenerate-dao,always the first rule was excuted while the second was not;
Why?
1 Answer
The reason is, that the first strategy changes the current term. In your example,
generate-daowould be applied to the result ofgenerate-entitywhich is probably not intended. You can see this in the debug messageafter s1, the current term isNone, which is not handled by yourgenerate-daorules. You can avoid this, by embedding the call in awhere(this restores the current term):generate-all= debug(!"before s1 "); where(generate-entity); debug(!"after s1 "); generate-dao; debug(!"after s2 ")The more canonical solution looks like this:
editor-generate (selected, ...) -> None() where content1 := <generate-1> selected; handle1 := <fopen> ("somefilename.ext", "w"); <fputs> (content1, handle1); fclose; content2 := <generate-2> selected; handle2 := <fopen> ("someotherfilename.ext", "w"); <fputs> (content2, handle2); fclose; ...or even like this:
editor-generate (selected, ...) -> None() where content1 := <generate-1> selected; handle1 := <fopen> ("somefilename.ext", "w"); <fputs> (content1, handle1); fclose where content2 := <generate-2> selected; handle2 := <fopen> ("someotherfilename.ext", "w"); <fputs> (content2, handle2); fclose; ...If you are sure a
Answered by Guido Wachsmuth on 19 March 2013 at 08:17whereclause should never fail, you can use awithclause instead.