unicode
This commit is contained in:
@@ -20,7 +20,7 @@ static bool run_test_case(const Token* token, const std::string& input, bool exp
|
|||||||
if (status_ok && match_ok) {
|
if (status_ok && match_ok) {
|
||||||
std::cout << "[PASS] Input: \"" << input << "\" -> "
|
std::cout << "[PASS] Input: \"" << input << "\" -> "
|
||||||
<< (res.success ? "SUCCESS" : "FAILURE")
|
<< (res.success ? "SUCCESS" : "FAILURE")
|
||||||
<< (res.success ? (" (Matched: \"" + utf8::toUTF8(res.flatMatch()) + "\")") : "")
|
<< (res.success ? (" (Matched: \"" + unicode::toUTF8(res.flatMatch()) + "\")") : "")
|
||||||
<< "\n";
|
<< "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ static bool run_test_case(const Token* token, const std::string& input, bool exp
|
|||||||
std::cerr << "[FAIL] Input: \"" << input << "\"\n"
|
std::cerr << "[FAIL] Input: \"" << input << "\"\n"
|
||||||
<< " Expected Success: " << (expectedSuccess ? "true" : "false") << ", Got: " << (res.success ? "true" : "false") << "\n";
|
<< " Expected Success: " << (expectedSuccess ? "true" : "false") << ", Got: " << (res.success ? "true" : "false") << "\n";
|
||||||
if (expectedSuccess && !expectedMatch.empty()) {
|
if (expectedSuccess && !expectedMatch.empty()) {
|
||||||
std::cerr << " Expected Match: \"" << utf8::toUTF8(expectedMatch) << "\", Got: \"" << utf8::toUTF8(res.flatMatch()) << "\"\n";
|
std::cerr << " Expected Match: \"" << unicode::toUTF8(expectedMatch) << "\", Got: \"" << unicode::toUTF8(res.flatMatch()) << "\"\n";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "TextReader.hpp"
|
#include "TextReader.hpp"
|
||||||
|
|
||||||
#include <spider/compiler/text/utf8.hpp>
|
#include <spider/compiler/text/unicode.hpp>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ namespace spider {
|
|||||||
// instead of whatever that was, convert to UTF-32
|
// instead of whatever that was, convert to UTF-32
|
||||||
// and then do an easy compare!
|
// and then do an easy compare!
|
||||||
std::u32string str;
|
std::u32string str;
|
||||||
if(!utf8::toUTF32(chars, str)) throw std::runtime_error("Specified invalid UTF-8 string!");
|
if(!unicode::toUTF32(chars, str)) throw std::runtime_error("Specified invalid UTF-8 string!");
|
||||||
return eat(str);
|
return eat(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ namespace spider {
|
|||||||
if (err) return false;
|
if (err) return false;
|
||||||
if (eof) return false;
|
if (eof) return false;
|
||||||
|
|
||||||
isize chsize = utf8::seqlen(u8(bytes[bindex]));
|
isize chsize = unicode::seqlen(u8(bytes[bindex]));
|
||||||
if(chsize == 0) {
|
if(chsize == 0) {
|
||||||
err = true;
|
err = true;
|
||||||
errmsg = "Invalid start of UTF-8 sequence.";
|
errmsg = "Invalid start of UTF-8 sequence.";
|
||||||
@@ -158,7 +158,7 @@ namespace spider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u32 decodedChar;
|
u32 decodedChar;
|
||||||
if(!utf8::decodeArr(bytes, chsize, decodedChar)) {
|
if(!unicode::decodeArr(bytes, chsize, decodedChar)) {
|
||||||
err = true;
|
err = true;
|
||||||
errmsg = "Invalid UTF-8 sequence.";
|
errmsg = "Invalid UTF-8 sequence.";
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace spider {
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
LitToken::LitToken(std::string_view lit) {
|
LitToken::LitToken(std::string_view lit) {
|
||||||
if (!utf8::toUTF32(lit, literal)) throw std::runtime_error("Illegal UTF8 literal!");
|
if (!unicode::toUTF32(lit, literal)) throw std::runtime_error("Illegal UTF8 literal!");
|
||||||
}
|
}
|
||||||
|
|
||||||
LitToken::LitToken(std::u32string lit) : literal(std::move(lit)) {}
|
LitToken::LitToken(std::u32string lit) : literal(std::move(lit)) {}
|
||||||
@@ -116,7 +116,7 @@ namespace spider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.success = !r.match.empty();
|
r.success = !r.match.empty();
|
||||||
if(r.success) std::cout << "[fn] matched: " << utf8::toUTF8(r.flatMatch()) << std::endl;
|
if(r.success) std::cout << "[fn] matched: " << unicode::toUTF8(r.flatMatch()) << std::endl;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ namespace spider {
|
|||||||
// Short-circuit branch: return immediately on first valid choice match
|
// Short-circuit branch: return immediately on first valid choice match
|
||||||
TokenResult res = token_ref->test(ctx);
|
TokenResult res = token_ref->test(ctx);
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
std::cout << "[or] matched: " << utf8::toUTF8(res.flatMatch()) << std::endl;
|
std::cout << "[or] matched: " << unicode::toUTF8(res.flatMatch()) << std::endl;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ namespace spider {
|
|||||||
TokenResult res = target->test(ctx);
|
TokenResult res = target->test(ctx);
|
||||||
|
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
std::cout << "[~] matched: " << utf8::toUTF8(res.flatMatch()) << std::endl;
|
std::cout << "[~] matched: " << unicode::toUTF8(res.flatMatch()) << std::endl;
|
||||||
return res; // Option matched exactly 1 instance successfully
|
return res; // Option matched exactly 1 instance successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ namespace spider {
|
|||||||
// Repetition rules (* token) always evaluate to successful
|
// Repetition rules (* token) always evaluate to successful
|
||||||
// completion state, even with 0 matches.
|
// completion state, even with 0 matches.
|
||||||
r.success = true;
|
r.success = true;
|
||||||
std::cout << "[*] matched: " << utf8::toUTF8(r.flatMatch()) << std::endl;
|
std::cout << "[*] matched: " << unicode::toUTF8(r.flatMatch()) << std::endl;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user