| 34 | inline namespace MIGRAPHX_INLINE_NS { |
| 35 | |
| 36 | static std::vector<std::string_view> json_tokenize(const std::string& s) |
| 37 | { |
| 38 | std::vector<lexer> lexers; |
| 39 | |
| 40 | // Quote |
| 41 | lexers.push_back([](const char* start, const char* end) { |
| 42 | if(*start != '\"') |
| 43 | return start; |
| 44 | ++start; |
| 45 | while((start != end) and (*start != '\"')) |
| 46 | { |
| 47 | if(*start == '\\') |
| 48 | start++; |
| 49 | start++; |
| 50 | } |
| 51 | |
| 52 | return ++start; |
| 53 | }); |
| 54 | |
| 55 | // Line comments |
| 56 | lexers.push_back([](const char* start, const char* end) { |
| 57 | if(*start == '#') |
| 58 | start++; |
| 59 | else if((start + 1) < end and start[0] == '/' and start[1] == '/') |
| 60 | start += 2; |
| 61 | else |
| 62 | return start; |
| 63 | return std::find_if(start, end, [&](char c) { return c == '\n'; }); |
| 64 | }); |
| 65 | |
| 66 | // Whitespace |
| 67 | lexers.push_back(lex_while(&isspace)); |
| 68 | |
| 69 | // Punctation |
| 70 | lexers.push_back(lex_if(&ispunct)); |
| 71 | |
| 72 | // Identifier/number |
| 73 | lexers.push_back(lex_while([](char c) { |
| 74 | return (isalnum(c) != 0 or contains({'_', '.', '+'}, c)); |
| 75 | })); |
| 76 | |
| 77 | return tokenize(s.data(), s.data() + s.length(), lexers); |
| 78 | } |
| 79 | |
| 80 | std::string convert_to_json(const std::string& str) |
| 81 | { |