MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Generator loop misses last line??
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Generator loop misses last line??

 Post Reply Post Reply
Author
Message
Angelo View Drop Down
Member
Member
Avatar

Joined: 03.Oct.2008
Location: The Netherlands
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Angelo Quote  Post ReplyReply Direct Link To This Post Topic: Generator loop misses last line??
    Posted: 12.Oct.2009 at 18:07
Just ran into something I've never seen before, so it's likely my mistake, but somehow I don't see what's wrong here.

I am creating a simple E-R like DSL for a tutorial, a generator to generate SQL code from it.
The language contains Entities, and each entity has Attributes, which I travers in the following loop in the code generator.


dowhile :Attributes
{
  '  `'; :Name '` ';

  if type = 'Text' then
    if :Size; < '256' num then
      ' varchar';
      if :Size; > '0' num then
          '('; :Size; ')';
      endif
    else
      'text';
    endif
  endif

  if type = 'Enum' then
     ' enum(';
     dowhile :Values;
     {
       id; ', ';
     }
     ')';
  endif

  if type = 'Integer' then
    ' int(11)';
  endif

  if type = 'float' then
     ' float';
  endif

  if :NullAllowed; = 'F' then
    ' NOT NULL';
  endif

  if :Default; <> '' then
    ' default `'; :Default; '` ';
  endif

  ','; newline;
}



What I don't get is why the last line in this loop is skipped for the last Attribute in the list.


  ','; newline;


It's not a conditional, and I can't spot a typ-o...

Who has seen this before, or sees my error?

The resulting code for one example entity is like this (there should be a comma and an newline between NOT NULL and PRIMARY KEY at the bottom, in the spot indicated by the bold blue X:


CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL auto_increment,
  `naam`  varchar(64) NOT NULL,
  `loginnaam`  varchar(255) NOT NULL,
  `wachtwoord`  varchar(32) NOT NULL,
  `accounttype`  enum(consultant, company, admin) NOT NULL default `consultant` ,
  `email`  varchar(128) NOT NULL X PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;



Edited by Angelo - 12.Oct.2009 at 18:13
Back to Top
jpt View Drop Down
MetaCase
MetaCase
Avatar

Joined: 25.Mar.2008
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpt Quote  Post ReplyReply Direct Link To This Post Posted: 12.Oct.2009 at 20:28
Replace dowhile with do and then it should work.
 
In MERL, dowhile clause is a variant of do that skips the generation process once the last item is handled, in your case ','; newline; 
 
Back to Top
Angelo View Drop Down
Member
Member
Avatar

Joined: 03.Oct.2008
Location: The Netherlands
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Angelo Quote  Post ReplyReply Direct Link To This Post Posted: 12.Oct.2009 at 23:49
Now how could I miss that, after so long....

Thanks Juha Pekka, guess I was looking in at the bottom of the statement for too long to see the problem at the top.

Edited by Angelo - 12.Oct.2009 at 23:50
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.023 seconds.