#include <iostream>
#include <regex>
#include <string>
int main(){
std::string input = "num i = 10;\nstr s = \"hello lol\";\n\nfnc fx(): num {\n print(\"lol\");\n ret 20;\n}\n\nnum x = fx();";
const std::regex lex("(\\s|;|\\(|\\)|{|})+(?=(?:[^\\'\"]*[\\'\"][^\\'\"]*[\\'\"])*[^\\'\"]*$)");
std::cout << "EzScript >" << std::endl;
std::string s1 = std::regex_replace(input, lex, "\n");
std::string s2 = std::regex_replace(s1, "\n+", "\n");
std::cout << s2 << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmVnZXg+CiNpbmNsdWRlIDxzdHJpbmc+CgppbnQgbWFpbigpewoJc3RkOjpzdHJpbmcgaW5wdXQgPSAgIm51bSBpID0gMTA7XG5zdHIgcyA9IFwiaGVsbG8gbG9sXCI7XG5cbmZuYyBmeCgpOiBudW0ge1xuCXByaW50KFwibG9sXCIpO1xuCXJldCAyMDtcbn1cblxubnVtIHggPSBmeCgpOyI7CgoJY29uc3Qgc3RkOjpyZWdleCBsZXgoIihcXHN8O3xcXCh8XFwpfHt8fSkrKD89KD86W15cXCdcIl0qW1xcJ1wiXVteXFwnXCJdKltcXCdcIl0pKlteXFwnXCJdKiQpIik7CgoJc3RkOjpjb3V0IDw8ICJFelNjcmlwdCA+IiA8PCBzdGQ6OmVuZGw7CgkKCXN0ZDo6c3RyaW5nIHMxID0gc3RkOjpyZWdleF9yZXBsYWNlKGlucHV0LCBsZXgsICJcbiIpOwoJc3RkOjpzdHJpbmcgczIgPSBzdGQ6OnJlZ2V4X3JlcGxhY2UoczEsICJcbisiLCAiXG4iKTsKCQoJc3RkOjpjb3V0IDw8IHMyIDw8IHN0ZDo6ZW5kbDsKCQoJcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main()’:
prog.cpp:13:53: error: no matching function for call to ‘regex_replace(std::__cxx11::string&, const char [3], const char [2])’
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.h:2331:5: note: candidate: ‘template<class _Out_iter, class _Bi_iter, class _Rx_traits, class _Ch_type, class _St, class _Sa> _Out_iter std::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const std::__cxx11::basic_string<_Ch_type, _St, _Sa>&, std::regex_constants::match_flag_type)’
regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.h:2331:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: candidate expects 6 arguments, 3 provided
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/bits/regex.h:2839,
from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.tcc:465:5: note: candidate: ‘template<class _Out_iter, class _Bi_iter, class _Rx_traits, class _Ch_type> _Out_iter std::regex_replace(_Out_iter, _Bi_iter, _Bi_iter, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const _Ch_type*, std::regex_constants::match_flag_type)’
regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.tcc:465:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: candidate expects 6 arguments, 3 provided
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.h:2376:5: note: candidate: ‘template<class _Rx_traits, class _Ch_type, class _St, class _Sa, class _Fst, class _Fsa> std::__cxx11::basic_string<_Ch_type, _St, _Sa> std::regex_replace(const std::__cxx11::basic_string<_Ch_type, _St, _Sa>&, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const std::__cxx11::basic_string<_Ch_type, _Fst, _Fsa>&, std::regex_constants::match_flag_type)’
regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.h:2376:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: mismatched types ‘const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>’ and ‘const char [3]’
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.h:2402:5: note: candidate: ‘template<class _Rx_traits, class _Ch_type, class _St, class _Sa> std::__cxx11::basic_string<_Ch_type, _St, _Sa> std::regex_replace(const std::__cxx11::basic_string<_Ch_type, _St, _Sa>&, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const _Ch_type*, std::regex_constants::match_flag_type)’
regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.h:2402:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: mismatched types ‘const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>’ and ‘const char [3]’
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.h:2428:5: note: candidate: ‘template<class _Rx_traits, class _Ch_type, class _St, class _Sa> std::__cxx11::basic_string<_Ch_type> std::regex_replace(const _Ch_type*, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const std::__cxx11::basic_string<_Ch_type, _St, _Sa>&, std::regex_constants::match_flag_type)’
regex_replace(const _Ch_type* __s,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.h:2428:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: mismatched types ‘const _Ch_type*’ and ‘std::__cxx11::basic_string<char>’
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^
In file included from /usr/include/c++/8/regex:62,
from prog.cpp:2:
/usr/include/c++/8/bits/regex.h:2454:5: note: candidate: ‘template<class _Rx_traits, class _Ch_type> std::__cxx11::basic_string<_Ch_type> std::regex_replace(const _Ch_type*, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, const _Ch_type*, std::regex_constants::match_flag_type)’
regex_replace(const _Ch_type* __s,
^~~~~~~~~~~~~
/usr/include/c++/8/bits/regex.h:2454:5: note: template argument deduction/substitution failed:
prog.cpp:13:53: note: mismatched types ‘const _Ch_type*’ and ‘std::__cxx11::basic_string<char>’
std::string s2 = std::regex_replace(s1, "\n+", "\n");
^