update
This commit is contained in:
parent
65bc648860
commit
185c7f785c
@ -204,7 +204,9 @@ namespace std {
|
|||||||
os<<" "<<v[v.size()-1];
|
os<<" "<<v[v.size()-1];
|
||||||
}else{
|
}else{
|
||||||
os<<"}";
|
os<<"}";
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
os<<"}";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,14 +6,15 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include<fstream>
|
||||||
|
|
||||||
namespace ztl{
|
namespace ztl{
|
||||||
template<class ...Ts>
|
template<class ...Ts>
|
||||||
void logger(Ts&&...v){
|
void logger(Ts&&...v){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::cout<<"log[";
|
std::cout<<"log: ";
|
||||||
(std::cout<<...<<v);
|
(std::cout<<...<<v);
|
||||||
std::cout<<"]\n";
|
std::cout<<"\n";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,5 +77,22 @@ namespace ztl{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Result<std::string> get_argv(size_t idx){
|
||||||
|
if(idx>=__argc){
|
||||||
|
return Result<std::string>(Err("argv's index out of range"));
|
||||||
|
}else{
|
||||||
|
return Result<std::string>(std::string(__argv[idx]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Result<std::string> get_string_from_file(const std::string &file_path){
|
||||||
|
std::ifstream file(file_path);
|
||||||
|
if (!file) {
|
||||||
|
return Result<std::string>(Err("Could not open file: " + file_path));
|
||||||
|
}
|
||||||
|
std::string content((std::istreambuf_iterator<char>(file)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
return Result<std::string>(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
#include "Lexer.hpp"
|
#include "Lexer.hpp"
|
||||||
#include <iostream>
|
#include "Tools.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
int main(){
|
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<ztl::lexer::Token> tokens = ztl::lexer::lexer(content);
|
||||||
|
ztl::logger("Tokens parsed:\n", tokens);
|
||||||
}
|
}
|
1
tests/main.ztl
Normal file
1
tests/main.ztl
Normal file
@ -0,0 +1 @@
|
|||||||
|
print("hello world");
|
Loading…
Reference in New Issue
Block a user