Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: D  |  size: 0.70 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data