Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

Commit

Permalink
Add: untyp
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatgec committed Dec 27, 2020
1 parent 5cf2bb6 commit c761418
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 33 deletions.
13 changes: 8 additions & 5 deletions flascript/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ FInterpreter::FlaScriptImporter(std::string file, std::string get) {
*/
void
FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) {
FTools seq;
Tokenizer token;
std::string strarg;
std::istringstream argline(arg);
Expand Down Expand Up @@ -195,7 +196,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) {
BOLD_RED_COLOR
std::cout << "error: ";

get_data = FlaScript::EscapeSeq(get_data);
get_data = seq.EscapeSeq(get_data);

BOLD_LIGHT_WHITE_COLOR
std::cout << get_data + "\n";
Expand All @@ -214,7 +215,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) {
BOLD_YELLOW_COLOR
std::cout << "warning: ";

get_data = FlaScript::EscapeSeq(get_data);
get_data = seq.EscapeSeq(get_data);

BOLD_LIGHT_WHITE_COLOR
std::cout << get_data + "\n";
Expand All @@ -231,7 +232,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) {
BOLD_LIGHT_GREEN_COLOR
std::cout << "success: ";

get_data = FlaScript::EscapeSeq(get_data);
get_data = seq.EscapeSeq(get_data);

BOLD_LIGHT_WHITE_COLOR
std::cout << get_data + "\n";
Expand Down Expand Up @@ -402,7 +403,7 @@ FInterpreter::FlaScriptInterpreterWithArg(std::string file, std::string arg) {
std::string get_data = var.GetVariable(get_name);

if(get_name != "error") {
get_data = FlaScript::EscapeSeq(get_data);
get_data = seq.EscapeSeq(get_data);

var.Equal(get_name, get_data);
}
Expand Down Expand Up @@ -1127,7 +1128,9 @@ FInterpreter::FlaScriptInterpreter(flascript_t &data) {
std::string get_data = var.GetVariable(get_name);

if(get_name != "error") {
get_data = FlaScript::EscapeSeq(get_data);
FTools seq;

get_data = seq.EscapeSeq(get_data);

var.Equal(get_name, get_data);
}
Expand Down
29 changes: 20 additions & 9 deletions flascript/Interpreter/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ FPrint::Print(std::string file, std::string arg) {
FInterpreter inp;
FFunction func;
FVariable var;
FTools seq;

if(inp.FindObject(arg, "fprintf") == true || inp.FindObject(arg, "fprintln") == true) { // fprintf(<%string>[:"test":, :"hello":])
std::string assign, type;
Expand Down Expand Up @@ -107,12 +108,20 @@ FPrint::Print(std::string file, std::string arg) {
std::string assign;
stringtools::GetBtwString(arg, "(", ")", assign);

if(assign == "string") {
stringtools::GetBtwString(arg, " \"", "\"", assign);
assign = FlaScript::EscapeSeq(assign);

if(assign != "error")
std::cout << assign;
if(assign[0] == '"' || assign == "string" || assign == "untyp") {

if(assign == "string") {
stringtools::GetBtwString(arg, "\"", "\"", assign);
assign = seq.EscapeSeq(assign);
} else if(assign == "untyp") {
stringtools::GetBtwString(arg, "\"", "\"", assign);
assign = seq.StandardSeq(assign);
} else {
stringtools::GetBtwString(assign, "\"", "\"", assign);
assign = seq.EscapeSeq(assign);
}

if(assign != "error") std::cout << assign;
} else if(inp.FindObject(assign, "var") == true) {
stringtools::GetBtwString(assign, "[", "]", assign);

Expand Down Expand Up @@ -273,7 +282,7 @@ FPrint::Print(std::string file, std::string arg) {
stringtools::GetBtwString(arg, " \"", "\"", assign);

if(assign != "error") {
assign = FlaScript::EscapeSeq(assign);
assign = seq.EscapeSeq(assign);

std::cout << assign << "\n";
} else
Expand All @@ -293,7 +302,7 @@ FPrint::Print(std::string file, std::string arg) {
stringtools::GetBtwString(get, " ", ":", color);
stringtools::GetBtwString(arg, " \"", "\" <-", assign);

assign = FlaScript::EscapeSeq(assign);
assign = seq.EscapeSeq(assign);

if(assign == "error") {
stringtools::GetBtwString(arg, " \"", "\"", assign);
Expand All @@ -319,7 +328,7 @@ FPrint::Print(std::string file, std::string arg) {
stringtools::GetBtwString(get, " ", ":", color);
stringtools::GetBtwString(arg, " \"", "\" <-", assign);

assign = FlaScript::EscapeSeq(assign);
assign = seq.EscapeSeq(assign);

if(assign == "error") {
stringtools::GetBtwString(arg, " \"", "\"", assign);
Expand All @@ -335,6 +344,8 @@ FPrint::Print(std::string file, std::string arg) {
if (t != var_.end()) // Found
std::cout << t->second;
}
} else {
/* error, undefined type */
}
}
}
Expand Down
37 changes: 21 additions & 16 deletions flascript/Interpreter/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,15 @@
#endif

void
FlaScript::TextBackground(int color) {
FTools::TextBackground(int color) {
printf("%c[%dm", ESC, 40+color);
}



std::string
FlaScript::EscapeSeq(std::string data) {
stringtools::replaceAll(data, "\\033", "\033");
stringtools::replaceAll(data, "\\x1", "\x1");
stringtools::replaceAll(data, "\\x2", "\x2");
stringtools::replaceAll(data, "\\x3", "\x3");

stringtools::replaceAll(data, "\\n", "\n");
stringtools::replaceAll(data, "\\t", "\t");
stringtools::replaceAll(data, "\\a", "\a");
stringtools::replaceAll(data, "\\b", "\b");
stringtools::replaceAll(data, "\\v", "\v");
stringtools::replaceAll(data, "\\r", "\r");
FTools::EscapeSeq(std::string data) {
data = Sequence(data);

if(stringtools::Count(data, '{') == stringtools::Count(data, '}')) {
if(stringtools::Count(data, '{') == stringtools::Count(data, '}')) {
unsigned i = stringtools::Count(data, '{');
FVariable var;

Expand All @@ -68,3 +56,20 @@ FlaScript::EscapeSeq(std::string data) {

return data;
}

std::string
FTools::Sequence(std::string data) {
stringtools::replaceAll(data, "\\033", "\033");
stringtools::replaceAll(data, "\\x1", "\x1");
stringtools::replaceAll(data, "\\x2", "\x2");
stringtools::replaceAll(data, "\\x3", "\x3");

stringtools::replaceAll(data, "\\n", "\n");
stringtools::replaceAll(data, "\\t", "\t");
stringtools::replaceAll(data, "\\a", "\a");
stringtools::replaceAll(data, "\\b", "\b");
stringtools::replaceAll(data, "\\v", "\v");
stringtools::replaceAll(data, "\\r", "\r");

return data;
}
8 changes: 7 additions & 1 deletion include/Interpreter/Tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
#include <iostream>
#include <cstring>

namespace FlaScript {
class FTools {
public:
void TextBackground(int);

std::string EscapeSeq(std::string data);
std::string Sequence(std::string data);

std::string StandardSeq(std::string data) {
return Sequence(data);
}
};

#endif // TOOLS_HPP
6 changes: 4 additions & 2 deletions test.fls
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
main() -> main {
var(string) -> FlaHello, developerFla -> pop <-

print(string) -> "String: {pop}\n"
print(untyp) -> "Variable: {pop}\n"
print("String: {pop}\n")

@pop_front -> pop <
@pop_front -> pop <
Expand All @@ -11,5 +12,6 @@ main() -> main {
@pop_back -> pop <
@pop_back -> pop <

print(string) -> "String: {pop}\n"
print(string) "String: {pop}\n"

} main;

0 comments on commit c761418

Please sign in to comment.