parsing again

Saaa empty at needmail.com
Wed Jul 1 16:58:52 PDT 2009


My mixin try (doesn't compile though :)
<3 at downs

string ctToString(int i)
{
  if (!i) return "0";
  string res;
  while (i) {
    res = "0123456789"[i%10] ~ res;
    i /= 10;
  }
  return res;
}

string index(int len)
{
  string res;
  for (int i = 0; i < len; ++i)
    res ~= "[indices["~ctToString(i)~"]] ";
  return res;
}

string casesString(T)(T array)
{
  string res;
  for (int i = 0; i < Depth!(T); ++i)
  {
    res ~= `case `~ctToString(i)~`:`~
    ` if( temp`~ index(i) ~`.length < index[`~ctToString(i)~`] ) temp`~ 
index(i) ~`.length = temp`~ index(i) ~`.length * 2 ;`
    ~`break;`;
  }
  return res;
}


pragma(msg, casesString!(T)(parsed));

ddata\ddata.d(330): Error: variable parsed is used before initialization
ddata\ddata.d(330): Error: cannot evaluate casesString(parsed) at compile 
time
ddata\ddata.d(330): Error: string expected for message, not 
'casesString(parsed)'



> --
> switch( depth )
> {
>  case 0:
>    if( temp.length < index[depth] ) temp.length = temp.length * 2;
>  break;
>  static if( is(T A:A[][]))
>  {
>    case 1:
>      if( temp[ index[0] ].length < index[depth] ) temp[index[0]].length = 
> temp[index[0]].length * 2;
>    break;
>  }
>  static if( is(T A:A[][][]))
>  {
>    case 2:
>      if( temp[ index[0] ][ index[1] ].length < index[depth] ) temp[ 
> index[0] ][ index[1] ].length = temp[ index[0] ][ index[1] ].length * 2;
>    break;
>  }
> default:
> assert(false);
> break;
> }
> -- 




More information about the Digitalmars-d-learn mailing list