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_0

I have change the sequence of generate-entity and generate-dao,always the first rule was excuted while the second was not;
Why?

Asked by ZJG on 19 March 2013 at 07:44

The reason is, that the first strategy changes the current term. In your example, generate-dao would be applied to the result of generate-entity which is probably not intended. You can see this in the debug message after s1, the current term is None, which is not handled by your generate-dao rules. You can avoid this, by embedding the call in a where (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 where clause should never fail, you can use a with clause instead.

Answered by Guido Wachsmuth on 19 March 2013 at 08:17