Print Page | Close Window

Generator loop misses last line??

Printed From: MetaCase
Category:
Forum Name: MetaEdit+
Forum Description: All topics relating to MetaEdit+ or DSM
URL: https://www.metacase.com/forums/forum_posts.asp?TID=121
Printed Date: 27.Mar.2026 at 00:25
Software Version: Web Wiz Forums 12.05 - http://www.webwizforums.com


Topic: Generator loop misses last line??
Posted By: Angelo
Subject: Generator loop misses last line??
Date 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;




Replies:
Posted By: jpt
Date 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; 
 


Posted By: Angelo
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.05 - http://www.webwizforums.com
Copyright ©2001-2022 Web Wiz Ltd. - https://www.webwiz.net