Remove outer namespacing class

This commit is contained in:
Josh Holtrop 2023-07-10 22:54:33 -04:00
parent 78ce7fb77a
commit eee6513384
14 changed files with 638 additions and 625 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,61 +9,60 @@ int main()
unittest unittest
{ {
size_t result; size_t result;
Testparser.CodePoint code_point; CodePoint code_point;
ubyte code_point_length; ubyte code_point_length;
result = Testparser.Decoder.decode_code_point("5", &code_point, &code_point_length); result = Decoder.decode_code_point("5", &code_point, &code_point_length);
assert(result == Testparser.P_SUCCESS); assert(result == P_SUCCESS);
assert(code_point == '5'); assert(code_point == '5');
assert(code_point_length == 1u); assert(code_point_length == 1u);
result = Testparser.Decoder.decode_code_point("", &code_point, &code_point_length); result = Decoder.decode_code_point("", &code_point, &code_point_length);
assert(result == Testparser.P_EOF); assert(result == P_EOF);
result = Testparser.Decoder.decode_code_point("\xC2\xA9", &code_point, &code_point_length); result = Decoder.decode_code_point("\xC2\xA9", &code_point, &code_point_length);
assert(result == Testparser.P_SUCCESS); assert(result == P_SUCCESS);
assert(code_point == 0xA9u); assert(code_point == 0xA9u);
assert(code_point_length == 2u); assert(code_point_length == 2u);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length); result = Decoder.decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length);
assert(result == Testparser.P_SUCCESS); assert(result == P_SUCCESS);
assert(code_point == 0x1F9E1u); assert(code_point == 0x1F9E1u);
assert(code_point_length == 4u); assert(code_point_length == 4u);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length); result = Decoder.decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length);
assert(result == Testparser.P_DECODE_ERROR); assert(result == P_DECODE_ERROR);
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length); result = Decoder.decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length);
assert(result == Testparser.P_DECODE_ERROR); assert(result == P_DECODE_ERROR);
result = Testparser.Decoder.decode_code_point("\xfe", &code_point, &code_point_length); result = Decoder.decode_code_point("\xfe", &code_point, &code_point_length);
assert(result == Testparser.P_DECODE_ERROR); assert(result == P_DECODE_ERROR);
} }
unittest unittest
{ {
alias TokenInfo = Testparser.Lexer.TokenInfo;
TokenInfo token_info; TokenInfo token_info;
string input = "5 + 4 * \n677 + 567"; string input = "5 + 4 * \n677 + 567";
Testparser.Lexer lexer = new Testparser.Lexer(input); Lexer lexer = new Lexer(input);
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(0, 0), 1, Testparser.TOKEN_int)); assert(token_info == TokenInfo(Position(0, 0), 1, TOKEN_int));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(0, 2), 1, Testparser.TOKEN_plus)); assert(token_info == TokenInfo(Position(0, 2), 1, TOKEN_plus));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(0, 4), 1, Testparser.TOKEN_int)); assert(token_info == TokenInfo(Position(0, 4), 1, TOKEN_int));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(0, 6), 1, Testparser.TOKEN_times)); assert(token_info == TokenInfo(Position(0, 6), 1, TOKEN_times));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(1, 0), 3, Testparser.TOKEN_int)); assert(token_info == TokenInfo(Position(1, 0), 3, TOKEN_int));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(1, 4), 1, Testparser.TOKEN_plus)); assert(token_info == TokenInfo(Position(1, 4), 1, TOKEN_plus));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(1, 6), 3, Testparser.TOKEN_int)); assert(token_info == TokenInfo(Position(1, 6), 3, TOKEN_int));
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(1, 9), 0, Testparser.TOKEN___EOF)); assert(token_info == TokenInfo(Position(1, 9), 0, TOKEN___EOF));
lexer = new Testparser.Lexer(""); lexer = new Lexer("");
assert(lexer.lex_token(&token_info) == Testparser.P_TOKEN); assert(lexer.lex_token(&token_info) == P_TOKEN);
assert(token_info == TokenInfo(Testparser.Position(0, 0), 0, Testparser.TOKEN___EOF)); assert(token_info == TokenInfo(Position(0, 0), 0, TOKEN___EOF));
} }

View File

@ -9,10 +9,10 @@ int main()
unittest unittest
{ {
string input = "aba"; string input = "aba";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
input = "abb"; input = "abb";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
} }

View File

@ -9,14 +9,14 @@ int main()
unittest unittest
{ {
string input = "a"; string input = "a";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_UNEXPECTED_TOKEN); assert(parser.parse() == P_UNEXPECTED_TOKEN);
input = "a b"; input = "a b";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
input = "bb"; input = "bb";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
} }

View File

@ -9,7 +9,7 @@ int main()
unittest unittest
{ {
string input = `identifier_123`; string input = `identifier_123`;
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass1"); writeln("pass1");
} }

View File

@ -9,12 +9,12 @@ int main()
unittest unittest
{ {
string input = `abc "a string" def`; string input = `abc "a string" def`;
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass1"); writeln("pass1");
input = `abc "abc def" def`; input = `abc "abc def" def`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass2"); writeln("pass2");
} }

View File

@ -9,12 +9,12 @@ int main()
unittest unittest
{ {
string input = `x`; string input = `x`;
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 1u); assert(parser.result == 1u);
input = `fabulous`; input = `fabulous`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 8u); assert(parser.result == 8u);
} }

View File

@ -9,11 +9,11 @@ int main()
unittest unittest
{ {
string input = `x`; string input = `x`;
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_UNEXPECTED_INPUT); assert(parser.parse() == P_UNEXPECTED_INPUT);
input = `123`; input = `123`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 123u); assert(parser.result == 123u);
} }

View File

@ -9,6 +9,6 @@ int main()
unittest unittest
{ {
string input = "ab"; string input = "ab";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
} }

View File

@ -10,42 +10,42 @@ int main()
unittest unittest
{ {
string input = ``; string input = ``;
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
input = `{}`; input = `{}`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONObject)parser.result); assert(cast(JSONObject)parser.result);
input = `[]`; input = `[]`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONArray)parser.result); assert(cast(JSONArray)parser.result);
input = `-45.6`; input = `-45.6`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONNumber)parser.result); assert(cast(JSONNumber)parser.result);
assert((cast(JSONNumber)parser.result).value == -45.6); assert((cast(JSONNumber)parser.result).value == -45.6);
input = `2E-2`; input = `2E-2`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONNumber)parser.result); assert(cast(JSONNumber)parser.result);
assert((cast(JSONNumber)parser.result).value == 0.02); assert((cast(JSONNumber)parser.result).value == 0.02);
input = `{"hi":true}`; input = `{"hi":true}`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONObject)parser.result); assert(cast(JSONObject)parser.result);
JSONObject o = cast(JSONObject)parser.result; JSONObject o = cast(JSONObject)parser.result;
assert(o.value["hi"]); assert(o.value["hi"]);
assert(cast(JSONTrue)o.value["hi"]); assert(cast(JSONTrue)o.value["hi"]);
input = `{"ff": false, "nn": null}`; input = `{"ff": false, "nn": null}`;
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(cast(JSONObject)parser.result); assert(cast(JSONObject)parser.result);
o = cast(JSONObject)parser.result; o = cast(JSONObject)parser.result;
assert(o.value["ff"]); assert(o.value["ff"]);

View File

@ -9,17 +9,17 @@ int main()
unittest unittest
{ {
string input = "a"; string input = "a";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 1u); assert(parser.result == 1u);
input = ""; input = "";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 0u); assert(parser.result == 0u);
input = "aaaaaaaaaaaaaaaa"; input = "aaaaaaaaaaaaaaaa";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
assert(parser.result == 16u); assert(parser.result == 16u);
} }

View File

@ -9,12 +9,12 @@ int main()
unittest unittest
{ {
string input = "abcdef"; string input = "abcdef";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass1"); writeln("pass1");
input = "defabcdef"; input = "defabcdef";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass2"); writeln("pass2");
} }

View File

@ -9,6 +9,6 @@ int main()
unittest unittest
{ {
string input = "defghidef"; string input = "defghidef";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
} }

View File

@ -9,12 +9,12 @@ int main()
unittest unittest
{ {
string input = "abcdef"; string input = "abcdef";
auto parser = new Testparser.Parser(input); auto parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass1"); writeln("pass1");
input = "abcabcdef"; input = "abcabcdef";
parser = new Testparser.Parser(input); parser = new Parser(input);
assert(parser.parse() == Testparser.P_SUCCESS); assert(parser.parse() == P_SUCCESS);
writeln("pass2"); writeln("pass2");
} }