Advertisement
Guest User

Untitled

a guest
Jan 4th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.70 KB | None | 0 0
  1.  
  2. Thing parse(string* text) {
  3.   if (text.accept "(") {
  4.     Thing[] things;
  5.     while (!text.accept ")")
  6.       things ~= parse text;
  7.     return new List things;
  8.   }
  9.   if (gotNum(text, &float f)) {
  10.     return new Number f;
  11.   }
  12.   if (text.accept("\"")) {
  13.     auto str = slice(text, "\"");
  14.     return new String str;
  15.   }
  16.   if (text.accept("'")) {
  17.     return new Escape (parse text);
  18.   }
  19.   auto t2 = *text #.strip();
  20.   char[auto~] token;
  21.   while (t2.length && t2[0] != " " && t2[0] != ")" && t2[0] != "(" && t2[0] != "\r" && t2[0] != "\n") {
  22.     token ~= t2[0];
  23.     t2 = t2[1..$];
  24.   }
  25.   if (!token.length)
  26.     error "Don't know what to do at $t2";
  27.   *text = t2;
  28.   return new Token token[];
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement