Switch to new API - close #8
The new API is more C-like and will allow consistency across all future supported language targets.
This commit is contained in:
parent
e0e5e87338
commit
7a1b4064c1
File diff suppressed because it is too large
Load Diff
@ -203,7 +203,7 @@ class Propane
|
||||
unless mode_id
|
||||
raise Error.new("Lexer mode '#{mode_name}' not found")
|
||||
end
|
||||
"m_mode = #{mode_id}u"
|
||||
"context.mode = #{mode_id}u"
|
||||
end
|
||||
end
|
||||
code
|
||||
|
@ -12,31 +12,31 @@ unittest
|
||||
CodePoint code_point;
|
||||
ubyte code_point_length;
|
||||
|
||||
result = Decoder.decode_code_point("5", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("5", &code_point, &code_point_length);
|
||||
assert(result == P_SUCCESS);
|
||||
assert(code_point == '5');
|
||||
assert(code_point_length == 1u);
|
||||
|
||||
result = Decoder.decode_code_point("", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("", &code_point, &code_point_length);
|
||||
assert(result == P_EOF);
|
||||
|
||||
result = Decoder.decode_code_point("\xC2\xA9", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("\xC2\xA9", &code_point, &code_point_length);
|
||||
assert(result == P_SUCCESS);
|
||||
assert(code_point == 0xA9u);
|
||||
assert(code_point_length == 2u);
|
||||
|
||||
result = Decoder.decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length);
|
||||
assert(result == P_SUCCESS);
|
||||
assert(code_point == 0x1F9E1u);
|
||||
assert(code_point_length == 4u);
|
||||
|
||||
result = Decoder.decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length);
|
||||
assert(result == P_DECODE_ERROR);
|
||||
|
||||
result = Decoder.decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length);
|
||||
assert(result == P_DECODE_ERROR);
|
||||
|
||||
result = Decoder.decode_code_point("\xfe", &code_point, &code_point_length);
|
||||
result = p_decode_code_point("\xfe", &code_point, &code_point_length);
|
||||
assert(result == P_DECODE_ERROR);
|
||||
}
|
||||
|
||||
@ -44,25 +44,26 @@ unittest
|
||||
{
|
||||
TokenInfo token_info;
|
||||
string input = "5 + 4 * \n677 + 567";
|
||||
Lexer lexer = new Lexer(input);
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(0, 0), 1, TOKEN_int));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(0, 2), 1, TOKEN_plus));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(0, 4), 1, TOKEN_int));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(0, 6), 1, TOKEN_times));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(1, 0), 3, TOKEN_int));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(1, 4), 1, TOKEN_plus));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(1, 6), 3, TOKEN_int));
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(1, 9), 0, TOKEN___EOF));
|
||||
|
||||
lexer = new Lexer("");
|
||||
assert(lexer.lex_token(&token_info) == P_SUCCESS);
|
||||
p_context_init(&context, "");
|
||||
assert(p_lex(&context, &token_info) == P_SUCCESS);
|
||||
assert(token_info == TokenInfo(Position(0, 0), 0, TOKEN___EOF));
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "aba";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
|
||||
input = "abb";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
}
|
||||
|
@ -9,14 +9,15 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "a";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_UNEXPECTED_TOKEN);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_UNEXPECTED_TOKEN);
|
||||
|
||||
input = "a b";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
|
||||
input = "bb";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = `identifier_123`;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass1");
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = `abc "a string" def`;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass1");
|
||||
|
||||
input = `abc "abc def" def`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass2");
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = `x`;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 1u);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 1u);
|
||||
|
||||
input = `fabulous`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 8u);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 8u);
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = `x`;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_UNEXPECTED_INPUT);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_UNEXPECTED_INPUT);
|
||||
|
||||
input = `123`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 123u);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 123u);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "ab";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
}
|
||||
|
@ -10,44 +10,45 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = ``;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
|
||||
input = `{}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
|
||||
input = `[]`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONArray)parser.result);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONArray)p_result(&context));
|
||||
|
||||
input = `-45.6`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONNumber)parser.result);
|
||||
assert((cast(JSONNumber)parser.result).value == -45.6);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONNumber)p_result(&context));
|
||||
assert((cast(JSONNumber)p_result(&context)).value == -45.6);
|
||||
|
||||
input = `2E-2`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONNumber)parser.result);
|
||||
assert((cast(JSONNumber)parser.result).value == 0.02);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONNumber)p_result(&context));
|
||||
assert((cast(JSONNumber)p_result(&context)).value == 0.02);
|
||||
|
||||
input = `{"hi":true}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
JSONObject o = cast(JSONObject)parser.result;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
JSONObject o = cast(JSONObject)p_result(&context);
|
||||
assert(o.value["hi"]);
|
||||
assert(cast(JSONTrue)o.value["hi"]);
|
||||
|
||||
input = `{"ff": false, "nn": null}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
o = cast(JSONObject)parser.result;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
o = cast(JSONObject)p_result(&context);
|
||||
assert(o.value["ff"]);
|
||||
assert(cast(JSONFalse)o.value["ff"]);
|
||||
assert(o.value["nn"]);
|
||||
|
@ -9,17 +9,18 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "a";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 1u);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 1u);
|
||||
|
||||
input = "";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 0u);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 0u);
|
||||
|
||||
input = "aaaaaaaaaaaaaaaa";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(parser.result == 16u);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(p_result(&context) == 16u);
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "abcdef";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass1");
|
||||
|
||||
input = "defabcdef";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass2");
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "defghidef";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
}
|
||||
|
@ -9,12 +9,13 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = "abcdef";
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass1");
|
||||
|
||||
input = "abcabcdef";
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
writeln("pass2");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user