On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote:
import std.stdio, std.range,std.file;
import std.string:strip;
import dparse.ast;
import dparse.lexer;
import dparse.parser : parseModule;
import dparse.rollback_allocator : RollbackAllocator;
import core.stdcpp.vector;
import core.stdcpp.string;
void push(ref vector!string l,string i){
l.push_back(i);
}
string Rff(string a){
return readText(a);
}
void Wf(string a,string b){
std.file.write(a,b);
}
void toF(ref vector!string b,string a){
writeln("toV");writeln(b.length);
string d;
foreach(ref string e;b)d~=e~"\n";
Wf(a,d);
}
void Qwk(ref vector!string b){
while(1){
auto t=b.back();if(t.length!=0)break;
b.pop_back();
}
}
void Pr(ref vector!string b){
foreach(ref string a;b)writeln(a);
}//
void toV(string a,ref vector!string b){
auto f=File(a,"r");
while(!f.eof()){
string l=strip(f.readln());push(b,l);
}
Qwk(b);
}//
string du(char c,int i){
char[]n;n.length=i;n[]=c;return n.idup;
}
string Jjc(int l,string b){
string a=du('+',l);return a~b;
}
class V : ASTVisitor
{
alias visit = ASTVisitor.visit;
vector!string f=[];
int l;
override void visit(const FunctionDeclaration decl)
{
writeln(' '.repeat(l * 4), decl.name.text);
f.push_back(decl.name.text);
l++;
scope (exit) l--;
decl.accept(this);
}
void _out(string s){
string b=s~".t";toF(f,b);
}
}
void ff(string B,string s)
{
LexerConfig config;
auto cache = StringCache(StringCache.defaultBucketCount);
auto tokens = getTokensForParser(B, config, &cache);
RollbackAllocator rba;
auto m = parseModule(tokens,s, &rba);
auto v= new V();
v.visit(m);v._out(s);
}
void gg(string a){
vector!string d=[];toV(a,d);
Pr(d);//3,OK
foreach(e;d){
string b=e;//.1
string m=readText(b);ff(m,b);
}
}
void main(){
string a="filename.txt";
gg(a);
}
A fully compiled version is too tiring, mainly due to the need to change the Chinese function name.
Some names are simply changed, otherwise it would be too tiring.