www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics




D - Tokenized compile time initialization

↑ ↓ ← Fernando Tolentino <josefernandotolentino gmail.com> writes:
Hi, I wonder if D support in future (maybe in 2.0 :) ) this feature. I imagine
like some it.

  char[] mary="Mary Simpson";
  Query q = {select * from person where name = {mary} order by birth};

But the compiler will do

  char[] mary="Mary Simpson";
  Query q = new Query();
  with(q) {
    q.addfield("*");
    q.addfrom("person");
    q.where.eq("name",mary);
  }

This will work if the programmer creates Query class in that way:

module query;

class Query
{
    this() // normal initializer
    {   ...
    }
    tokenized this(token[] tokens) // here is the magic, compiler will execute
this script (interpret or use dynamic library(plugin for compiler))
      init(){
        whitespaces=[" ","\t","\r","\n"]; // must support multiline in tokens
and D style comments
        clauses=["select","from","as","where","order by"]; // must replace any
whitespace for space(ascii 32)
        operators=["=","<>","like","(", ")"]; // i think everythink must be
casesensitive
      }
      main(){
        parseSelect(false);
      }
      parseSelect(bool isSubSelect)
      {
        token.checkClause("select"); // if not is compiling fails
        token.next(); // autoskip whitespaces
        parseField();
        while (!(token.eof() || token.isClause("from"))
        {
          if (token.isOperator(")") {
            if (isSubSelect)
            {
              token.next();
              return;
            }
          }
          checkOperator(',');
          token.next();
          parseField();
        }
        parseField(){
          if (token.isOperator("(") {
            token.next();
            mixin("Query subselect = new Query()");
            mixin("with(subselect){");
            parseSelect(true);
            mixin("}");
            mixin("addfield("""+field+""","""+token.str+""")");
          }
          else {
            auto field=token.text;
            token.next();
            if (token.isClause('as')){
              token.next();
              mixin("addfield("""+field+""","""+token.str+""")");
              token.next();
            }
            else mixin("addfield("""+field+""")");
          }
        }
        parseFrom()
....
     }
    }
}


well, is like some this.

thanks for attention.
Apr 12 2008
↑ ↓ Benjamin Shropshire <ao pathlink.com> writes:
this newsgroup is depricated, use the digitalmars.d group
Apr 12 2008
↑ ↓ → Ary Borenszweig <ary esperanto.org.ar> writes:
Benjamin Shropshire escribió:
 this newsgroup is depricated, use the digitalmars.d group

Why is one allowed to write to this newsgroup if it is deprecated?
Apr 12 2008