diff --git a/include/Lexer.hpp b/include/Lexer.hpp index fabd3dc..1c1044e 100644 --- a/include/Lexer.hpp +++ b/include/Lexer.hpp @@ -204,7 +204,9 @@ namespace std { os<<" "< #include #include +#include namespace ztl{ template void logger(Ts&&...v){ #ifndef NDEBUG - std::cout<<"log["; + std::cout<<"log: "; (std::cout<<...< get_argv(size_t idx){ + if(idx>=__argc){ + return Result(Err("argv's index out of range")); + }else{ + return Result(std::string(__argv[idx])); + } + } + + inline Result get_string_from_file(const std::string &file_path){ + std::ifstream file(file_path); + if (!file) { + return Result(Err("Could not open file: " + file_path)); + } + std::string content((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); + return Result(content); + } } diff --git a/src/main.cpp b/src/main.cpp index 6ce65bd..63c4a7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,11 @@ #include "Lexer.hpp" -#include +#include "Tools.hpp" +#include int main(){ - + std::string content = ztl::get_string_from_file(ztl::get_argv(1).unwrap()).unwrap(); + ztl::logger("Reading file: ", ztl::get_argv(1).unwrap()); + ztl::logger("File content:\n", content); + std::vector tokens = ztl::lexer::lexer(content); + ztl::logger("Tokens parsed:\n", tokens); } \ No newline at end of file diff --git a/tests/main.ztl b/tests/main.ztl new file mode 100644 index 0000000..aabbabe --- /dev/null +++ b/tests/main.ztl @@ -0,0 +1 @@ +print("hello world"); \ No newline at end of file