fixes
This commit is contained in:
parent
6e2eb11bf9
commit
e1465ae786
32
Readme.md
32
Readme.md
|
|
@ -1,21 +1,28 @@
|
|||
|
||||
### TODO
|
||||
- construct list for parse-csv in csvparse.cpp instead of ml.cpp
|
||||
- support for strings with " included
|
||||
- update openssl libs
|
||||
- documentation
|
||||
- add url of source/inspiration to clib/*.cpp
|
||||
- load std lib when starting
|
||||
- add more command line args
|
||||
- split into more files
|
||||
- prejmenovat ivaluize
|
||||
- add some debug support??
|
||||
- add instrumentation (time, nr of evals, debug info, debug environment etc)
|
||||
|
||||
#### Functionality
|
||||
- readline
|
||||
- cvs read
|
||||
- url read
|
||||
- json
|
||||
- execute system command
|
||||
- printf
|
||||
- env
|
||||
- support for including lib
|
||||
- date support
|
||||
- file functions
|
||||
- name it here
|
||||
- string funtions
|
||||
- name it here
|
||||
- add hash datatype
|
||||
|
||||
|
||||
#### Performance
|
||||
|
|
@ -28,3 +35,20 @@
|
|||
time ./build/ml -c '(include "../example.lisp") (print (fact 1000))'
|
||||
./build/ml -f debug.lisp
|
||||
```
|
||||
|
||||
### Links
|
||||
https://www.tutorialspoint.com/lisp/index.htm
|
||||
https://github.com/adam-mcdaniel/wisp
|
||||
|
||||
https://github.com/dropbox/json11
|
||||
|
||||
#### std::vector
|
||||
https://stackoverflow.com/questions/12271017/initial-capacity-of-vector-in-c
|
||||
https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html
|
||||
|
||||
#### parse http headers in c++
|
||||
```
|
||||
^(?:((?:https?|s?ftp):)\/\/)([^:\/\s]+)(?::(\d*))?(?:\/([^\s?#]+)?([?][^?#]*)?(#.*)?)?
|
||||
```
|
||||
|
||||
https://stackoverflow.com/questions/25896916/parse-http-headers-in-c
|
||||
|
|
|
|||
54
ml.cpp
54
ml.cpp
|
|
@ -117,20 +117,6 @@ bool is_symbol(char ch) {
|
|||
return (isalpha(ch) || ispunct(ch)) && ch != '(' && ch != ')' && ch != '"' && ch != '\'';
|
||||
}
|
||||
|
||||
// std::regex int_underscored_regex("[0-9][0-9_]+[0-9]");
|
||||
std::regex int_regex("[0-9]+");
|
||||
std::regex double_regex("[0-9]+\\.[0-9]+");
|
||||
|
||||
// Is string representing int value
|
||||
bool is_string_int(const std::string &str) {
|
||||
return std::regex_match(str, int_regex);
|
||||
}
|
||||
|
||||
// Is string representing float value
|
||||
bool is_string_float(const std::string &str) {
|
||||
return std::regex_match(str, double_regex);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// LISP CONSTRUCTS ////////////////////////////////////////////////////////////
|
||||
|
|
@ -1148,30 +1134,7 @@ namespace builtin {
|
|||
std::vector<std::vector<std::string> > parsed_data; // TODO some default size here
|
||||
csv.parseCSV(args[0].as_string(), parsed_data);
|
||||
|
||||
int rows = parsed_data.size();
|
||||
int cols = rows > 0 ? parsed_data[0].size() : 0;
|
||||
|
||||
std::vector<MlValue> result;
|
||||
|
||||
if (rows > 0 && cols > 0) {
|
||||
for (int r = 0; r < rows; r++) {
|
||||
std::vector<MlValue> row;
|
||||
for (int c = 0; c < cols; c++) {
|
||||
std::string value = parsed_data[r][c];
|
||||
if (is_string_int(value)) {
|
||||
row.push_back(MlValue(stoi(value)));
|
||||
}
|
||||
if (is_string_float(value)) {
|
||||
row.push_back(MlValue(std::stod(value)));
|
||||
} else {
|
||||
row.push_back(MlValue::string(value));
|
||||
}
|
||||
}
|
||||
result.push_back(row);
|
||||
}
|
||||
}
|
||||
|
||||
return MlValue(result);
|
||||
return csv.ivalualize(parsed_data);
|
||||
}
|
||||
|
||||
// Get the contents of a file
|
||||
|
|
@ -1208,21 +1171,22 @@ namespace builtin {
|
|||
eval_args(args, env);
|
||||
|
||||
// PERF optimize it for memory usage and performance
|
||||
// TODO handle second parameter (headers)
|
||||
if (args.size() != 1)
|
||||
throw MlError(MlValue("read_url", read_url), env, args.size() > 1 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
if (args.size() < 1 || args.size() > 2)
|
||||
throw MlError(MlValue("read_url", read_url), env, args.size() < 1 ? TOO_FEW_ARGS : TOO_MANY_ARGS);
|
||||
|
||||
std::unordered_map<std::string, std::string> headers = {};
|
||||
HttpClient client;
|
||||
|
||||
if (args.size() == 2) {
|
||||
// do magick here
|
||||
// for (auto i = map.begin(); i != map.end(); ++i) {
|
||||
// headers[i->first] = i->second.getString();
|
||||
// }
|
||||
for(const auto& pair_list: args[1].as_list()[0].as_list()) {
|
||||
// TODO check its 2 string elements list
|
||||
const auto& pair = pair_list.as_list();
|
||||
headers[pair[0].as_string()] = pair[1].as_string();
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<int, std::string> result = client.doGetRequest(args[0].as_string(), headers);
|
||||
// TODO add helper function for this
|
||||
std::vector<MlValue> lst;
|
||||
lst.push_back(MlValue(result.first));
|
||||
lst.push_back(MlValue::string(result.second));
|
||||
|
|
|
|||
Loading…
Reference in New Issue