mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
✨ add cmakelists.txt
This commit is contained in:
+24
-24
@@ -21,14 +21,14 @@ struct span {
|
||||
struct for_reset {
|
||||
CONSOLE_SCREEN_BUFFER_INFO scr;
|
||||
for_reset() {
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&scr);
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &scr);
|
||||
}
|
||||
} reset_ter_color;
|
||||
#endif
|
||||
|
||||
std::ostream& back_white(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0xf0);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xf0);
|
||||
#else
|
||||
s<<"\033[7m";
|
||||
#endif
|
||||
@@ -37,7 +37,7 @@ std::ostream& back_white(std::ostream& s) {
|
||||
|
||||
std::ostream& red(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0c);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0c);
|
||||
#else
|
||||
s<<"\033[91;1m";
|
||||
#endif
|
||||
@@ -46,7 +46,7 @@ std::ostream& red(std::ostream& s) {
|
||||
|
||||
std::ostream& cyan(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x03);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x03);
|
||||
#else
|
||||
s<<"\033[36;1m";
|
||||
#endif
|
||||
@@ -55,7 +55,7 @@ std::ostream& cyan(std::ostream& s) {
|
||||
|
||||
std::ostream& orange(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0e);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0e);
|
||||
#else
|
||||
s<<"\033[93;1m";
|
||||
#endif
|
||||
@@ -64,7 +64,7 @@ std::ostream& orange(std::ostream& s) {
|
||||
|
||||
std::ostream& white(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0f);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0f);
|
||||
#else
|
||||
s<<"\033[0m\033[1m";
|
||||
#endif
|
||||
@@ -73,7 +73,7 @@ std::ostream& white(std::ostream& s) {
|
||||
|
||||
std::ostream& reset(std::ostream& s) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),reset_ter_color.scr.wAttributes);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), reset_ter_color.scr.wAttributes);
|
||||
#else
|
||||
s<<"\033[0m";
|
||||
#endif
|
||||
@@ -99,7 +99,7 @@ private:
|
||||
string identation(usize len) {
|
||||
return string(len,' ');
|
||||
}
|
||||
string leftpad(u32 num,usize len) {
|
||||
string leftpad(u32 num, usize len) {
|
||||
string tmp=std::to_string(num);
|
||||
while(tmp.length()<len) {
|
||||
tmp=" "+tmp;
|
||||
@@ -108,9 +108,9 @@ private:
|
||||
}
|
||||
public:
|
||||
error():cnt(0) {}
|
||||
void fatal(const string&,const string&);
|
||||
void err(const string&,const string&);
|
||||
void err(const string&,const span&,const string&);
|
||||
void fatal(const string&, const string&);
|
||||
void err(const string&, const string&);
|
||||
void err(const string&, const span&, const string&);
|
||||
|
||||
void chkerr() const {
|
||||
if (cnt) {
|
||||
@@ -128,7 +128,7 @@ void flstream::load(const string& f) {
|
||||
}
|
||||
|
||||
res.clear();
|
||||
std::ifstream in(f,std::ios::binary);
|
||||
std::ifstream in(f, std::ios::binary);
|
||||
if (in.fail()) {
|
||||
std::cerr<<red<<"src: "<<reset<<"cannot open <"<<f<<">\n";
|
||||
std::exit(1);
|
||||
@@ -136,12 +136,12 @@ void flstream::load(const string& f) {
|
||||
|
||||
while(!in.eof()) {
|
||||
string line;
|
||||
std::getline(in,line);
|
||||
std::getline(in, line);
|
||||
res.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
void error::fatal(const string& stage,const string& info) {
|
||||
void error::fatal(const string& stage, const string& info) {
|
||||
std::cerr<<red<<stage<<": "<<white<<info<<reset<<"\n";
|
||||
if (file.length()) {
|
||||
std::cerr<<cyan<<" --> "<<red<<file<<reset<<"\n\n";
|
||||
@@ -151,7 +151,7 @@ void error::fatal(const string& stage,const string& info) {
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
void error::err(const string& stage,const string& info) {
|
||||
void error::err(const string& stage, const string& info) {
|
||||
++cnt;
|
||||
std::cerr<<red<<stage<<": "<<white<<info<<reset<<"\n";
|
||||
if (file.length()) {
|
||||
@@ -161,7 +161,7 @@ void error::err(const string& stage,const string& info) {
|
||||
}
|
||||
}
|
||||
|
||||
void error::err(const string& stage,const span& loc,const string& info) {
|
||||
void error::err(const string& stage, const span& loc, const string& info) {
|
||||
// load error occurred file into string lines
|
||||
load(loc.file);
|
||||
|
||||
@@ -174,7 +174,7 @@ void error::err(const string& stage,const span& loc,const string& info) {
|
||||
const usize maxlen=std::to_string(loc.end_line).length();
|
||||
const string iden=identation(maxlen);
|
||||
|
||||
for(u32 line=loc.begin_line;line<=loc.end_line;++line) {
|
||||
for(u32 line=loc.begin_line; line<=loc.end_line; ++line) {
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
@@ -192,29 +192,29 @@ void error::err(const string& stage,const span& loc,const string& info) {
|
||||
}
|
||||
|
||||
const string& code=res[line-1];
|
||||
std::cerr<<cyan<<leftpad(line,maxlen)<<" | "<<reset<<code<<"\n";
|
||||
std::cerr<<cyan<<leftpad(line, maxlen)<<" | "<<reset<<code<<"\n";
|
||||
// output underline
|
||||
std::cerr<<cyan<<iden<<" | "<<reset;
|
||||
if (loc.begin_line==loc.end_line) {
|
||||
for(u32 i=0;i<loc.begin_column;++i) {
|
||||
for(u32 i=0; i<loc.begin_column; ++i) {
|
||||
std::cerr<<char(" \t"[code[i]=='\t']);
|
||||
}
|
||||
for(u32 i=loc.begin_column;i<loc.end_column;++i) {
|
||||
for(u32 i=loc.begin_column ;i<loc.end_column; ++i) {
|
||||
std::cerr<<red<<(code[i]=='\t'?"^^^^":"^")<<reset;
|
||||
}
|
||||
} else if (line==loc.begin_line) {
|
||||
for(u32 i=0;i<loc.begin_column;++i) {
|
||||
for(u32 i=0; i<loc.begin_column; ++i) {
|
||||
std::cerr<<char(" \t"[code[i]=='\t']);
|
||||
}
|
||||
for(u32 i=loc.begin_column;i<code.size();++i) {
|
||||
for(u32 i=loc.begin_column; i<code.size(); ++i) {
|
||||
std::cerr<<red<<(code[i]=='\t'?"^^^^":"^")<<reset;
|
||||
}
|
||||
} else if (loc.begin_line<line && line<loc.end_line) {
|
||||
for(u32 i=0;i<code.size();++i) {
|
||||
for(u32 i=0; i<code.size(); ++i) {
|
||||
std::cerr<<red<<(code[i]=='\t'?"^^^^":"^");
|
||||
}
|
||||
} else {
|
||||
for(u32 i=0;i<loc.end_column;++i) {
|
||||
for(u32 i=0; i<loc.end_column; ++i) {
|
||||
std::cerr<<red<<(code[i]=='\t'?"^^^^":"^");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user