S-expressions: Difference between revisions

Better D entry
(Updated D entry)
(Better D entry)
Line 850:
 
=={{header|D}}==
<lang d>import std.stdio, std.conv, std.algorithm, std.variant, std.uni;,
std.functional;
 
alias Sexp = Variant;
Line 856 ⟶ 857:
struct Symbol {
private string name;
string toString() @safe const pure nothrow { return name; }
}
 
Sexp parseSexp(string txt) @safe pure /*nothrow*/ {
static bool isIdentChar(in char c) @safe pure /*nothrow*/ {
return c.isAlpha || "0123456789!@#-".canFind(c);
Line 866 ⟶ 867:
size_t pos = 0;
 
Sexp _parse() /*nothrow*/ {
auto i = pos + 1;
scope (exit)
Line 882 ⟶ 883:
while (txt[i].isNumber && i < txt.length)
i++;
auto aux = txt[pos .. i]; //
return aux.parse!double.Sexp;
}
auto aux = txt[pos .. i]; //
return aux.parse!ulong.Sexp;
} else if (isIdentChar(txt[pos])) {
Line 908 ⟶ 909:
}
 
whiletxt = (txt[pos].find!(not!isWhite);
pos++;
return _parse;
}
Line 936:
"Printed: ".write;
pTest.writeSexp;
writeln;
}</lang>
{{out}}