From 6fd51861594bb398e718f698710177f28b8f1ae8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 17 Feb 2026 18:40:33 -0500 Subject: [PATCH] Replace p_context_init() with p_context_new()/p_context_delete() --- CHANGELOG.md | 8 +- UPGRADING.md | 13 ++- assets/parser.c.erb | 46 ++++++--- assets/parser.d.erb | 24 ++--- assets/parser.h.erb | 4 +- doc/user_guide.md | 95 +++++++++---------- spec/test_basic_math_grammar.c | 30 +++--- spec/test_basic_math_grammar.d | 26 ++--- spec/test_drop_code_block.c | 7 +- spec/test_drop_code_block.d | 6 +- spec/test_error_positions.c | 47 +++++---- spec/test_error_positions.d | 34 +++---- spec/test_field_aliases.c | 7 +- spec/test_field_aliases.d | 6 +- spec/test_free_tree_token_node_memory.c | 9 +- spec/test_lexer.c | 26 ++--- spec/test_lexer.d | 24 ++--- spec/test_lexer_match_text.c | 7 +- spec/test_lexer_match_text.d | 6 +- spec/test_lexer_modes.c | 12 ++- spec/test_lexer_modes.d | 10 +- spec/test_lexer_multiple_modes.c | 12 ++- spec/test_lexer_multiple_modes.d | 10 +- spec/test_lexer_result_value.c | 16 ++-- spec/test_lexer_result_value.d | 14 +-- spec/test_lexer_unknown_character.c | 14 +-- spec/test_lexer_unknown_character.d | 12 +-- spec/test_match_backslashes.c | 7 +- spec/test_match_backslashes.d | 6 +- spec/test_multiple_parsers.c | 14 +-- spec/test_multiple_parsers.d | 12 +-- .../test_named_optional_rule_component_tree.c | 23 +++-- .../test_named_optional_rule_component_tree.d | 20 ++-- spec/test_optional_rule_component.c | 17 ++-- spec/test_optional_rule_component.d | 14 +-- spec/test_optional_rule_component_tree.c | 23 +++-- spec/test_optional_rule_component_tree.d | 20 ++-- spec/test_parser_identical_rules_lookahead.c | 12 ++- spec/test_parser_identical_rules_lookahead.d | 10 +- spec/test_parser_rule_from_multiple_states.c | 23 +++-- spec/test_parser_rule_from_multiple_states.d | 16 ++-- spec/test_parser_rule_user_code.c | 7 +- spec/test_parser_rule_user_code.d | 6 +- spec/test_parsing_json.c | 53 ++++++----- spec/test_parsing_json.d | 50 +++++----- spec/test_parsing_lists.c | 23 +++-- spec/test_parsing_lists.d | 20 ++-- spec/test_pattern.c | 12 ++- spec/test_pattern.d | 10 +- spec/test_return_token_from_pattern.c | 7 +- spec/test_return_token_from_pattern.d | 6 +- spec/test_start_rule_tree.c | 9 +- spec/test_start_rule_tree.d | 8 +- spec/test_starting_rules.c | 23 +++-- spec/test_starting_rules.d | 20 ++-- spec/test_starting_rules_tree.c | 23 +++-- spec/test_starting_rules_tree.d | 20 ++-- spec/test_tree.c | 23 +++-- spec/test_tree.d | 20 ++-- spec/test_tree_field_aliases.c | 9 +- spec/test_tree_field_aliases.d | 8 +- spec/test_tree_invalid_positions.c | 30 +++--- spec/test_tree_invalid_positions.d | 26 ++--- spec/test_tree_node_memory_remains.c | 9 +- spec/test_tree_node_memory_remains.d | 8 +- spec/test_tree_ps.c | 23 +++-- spec/test_tree_ps.d | 20 ++-- spec/test_tree_token_positions.c | 16 ++-- spec/test_tree_token_positions.d | 14 +-- spec/test_user_code.c | 12 ++- spec/test_user_code.d | 10 +- spec/test_user_context_fields.c | 13 +-- spec/test_user_context_fields.d | 6 +- spec/test_user_terminate.c | 14 +-- spec/test_user_terminate.d | 12 +-- spec/test_user_terminate_lexer.c | 14 +-- spec/test_user_terminate_lexer.d | 12 +-- 77 files changed, 728 insertions(+), 610 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0cff91..f587a34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v4.0.0 + +### Breaking Changes + +- Replace `p_context_init()` with `p_context_new()` and `p_context_delete()`. + ## v3.0.0 ### New Features @@ -12,7 +18,7 @@ - Document `p_lex()` and `p_token_info_t` in user guide (#37) -### Breaking changes +### Breaking Changes - Rename AST generation mode to tree generation mode (see [UPGRADING.md](UPGRADING.md)) diff --git a/UPGRADING.md b/UPGRADING.md index b638dcf..9bc1527 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,17 @@ +## v4.0.0 + +### API Changes + +- Replace any calls to `p_context_init()` with `p_context_new()`. +- Replace any references to the address of a statically allocated context + structure with the pointer returned from `p_context_init()` (e.g. `&context` + -> `context`). +- Add a call to `p_context_delete()` (for C or C++) after lexing/parsing to + reclaim context memory. + ## v3.0.0 -### Grammar changes +### Grammar Changes - Rename `ast;` statement to `tree;`. - Rename `ast_prefix;` statement to `tree_prefix;`. diff --git a/assets/parser.c.erb b/assets/parser.c.erb index 03c7061..b58d511 100644 --- a/assets/parser.c.erb +++ b/assets/parser.c.erb @@ -43,30 +43,48 @@ const char * <%= @grammar.prefix %>token_names[] = { *************************************************************************/ /** - * Initialize lexer/parser context structure. + * Allocate and initialize lexer/parser context structure. + * + * Deinitialize and deallocate with <%= @grammar.prefix %>context_delete(). * - * @param[out] context - * Lexer/parser context structure. * @param input * Text input. * @param input_length * Text input length. + * + * @return Context structure for lexer/parser. */ -void <%= @grammar.prefix %>context_init(<%= @grammar.prefix %>context_t * context, uint8_t const * input, size_t input_length) +<%= @grammar.prefix %>context_t * <%= @grammar.prefix %>context_new(uint8_t const * input, size_t input_length) { - /* New default-initialized context structure. */ - <%= @grammar.prefix %>context_t newcontext; - memset(&newcontext, 0, sizeof(newcontext)); +<% if @cpp %> + <%= @grammar.prefix %>context_t * context = new <%= @grammar.prefix %>context_t(); +<% else %> + <%= @grammar.prefix %>context_t * context = (<%= @grammar.prefix %>context_t *)calloc(1, sizeof(<%= @grammar.prefix %>context_t)); +<% end %> /* Lexer initialization. */ - newcontext.input = input; - newcontext.input_length = input_length; - newcontext.text_position.row = 1u; - newcontext.text_position.col = 1u; - newcontext.mode = <%= @lexer.mode_id("default") %>; + context->input = input; + context->input_length = input_length; + context->text_position.row = 1u; + context->text_position.col = 1u; + context->mode = <%= @lexer.mode_id("default") %>; - /* Copy to the user's context structure. */ - *context = newcontext; + return context; +} + +/** + * Deinitialize and deallocate lexer/parser context structure. + * + * @param context + * Lexer/parser context structure allocated with <%= @grammar.prefix %>context_new(). + */ +void <%= @grammar.prefix %>context_delete(<%= @grammar.prefix %>context_t * context) +{ +<% if @cpp %> + delete context; +<% else %> + free(context); +<% end %> } /************************************************************************** diff --git a/assets/parser.d.erb b/assets/parser.d.erb index 86a48cf..e048cda 100644 --- a/assets/parser.d.erb +++ b/assets/parser.d.erb @@ -225,26 +225,28 @@ private enum size_t INVALID_ID = cast(size_t)-1; *************************************************************************/ /** - * Initialize lexer/parser context structure. * - * @param[out] context - * Lexer/parser context structure. + * Deinitialize and deallocate with <%= @grammar.prefix %>context_delete(). + * * @param input * Text input. + * @param input_length + * Text input length. + * + * @return Context structure for lexer/parser. */ -public void <%= @grammar.prefix %>context_init(<%= @grammar.prefix %>context_t * context, string input) +<%= @grammar.prefix %>context_t * <%= @grammar.prefix %>context_new(string input) { /* New default-initialized context structure. */ - <%= @grammar.prefix %>context_t newcontext; + <%= @grammar.prefix %>context_t * context = new <%= @grammar.prefix %>context_t; /* Lexer initialization. */ - newcontext.input = input; - newcontext.text_position.row = 1u; - newcontext.text_position.col = 1u; - newcontext.mode = <%= @lexer.mode_id("default") %>; + context.input = input; + context.text_position.row = 1u; + context.text_position.col = 1u; + context.mode = <%= @lexer.mode_id("default") %>; - /* Copy to the user's context structure. */ - *context = newcontext; + return context; } /************************************************************************** diff --git a/assets/parser.h.erb b/assets/parser.h.erb index 0be7966..84ed024 100644 --- a/assets/parser.h.erb +++ b/assets/parser.h.erb @@ -184,7 +184,9 @@ typedef struct /** Token names. */ extern const char * <%= @grammar.prefix %>token_names[]; -void <%= @grammar.prefix %>context_init(<%= @grammar.prefix %>context_t * context, uint8_t const * input, size_t input_length); +<%= @grammar.prefix %>context_t * <%= @grammar.prefix %>context_new(uint8_t const * input, size_t input_length); + +void <%= @grammar.prefix %>context_delete(<%= @grammar.prefix %>context_t * context); size_t <%= @grammar.prefix %>decode_code_point(uint8_t const * input, size_t input_length, <%= @grammar.prefix %>code_point_t * out_code_point, uint8_t * out_code_point_length); diff --git a/doc/user_guide.md b/doc/user_guide.md index 709c46e..421dcae 100644 --- a/doc/user_guide.md +++ b/doc/user_guide.md @@ -319,10 +319,9 @@ example parse: ``` string input = "a, ((b)), b"; -p_context_t context; -p_context_init(&context, input); -assert_eq(P_SUCCESS, p_parse(&context)); -Start * start = p_result(&context); +p_context_t * context = p_context_new(input); +assert_eq(P_SUCCESS, p_parse(context)); +Start * start = p_result(context); assert(start.pItems1 !is null); assert(start.pItems !is null); Items * items = start.pItems; @@ -370,10 +369,9 @@ Then the types would be used as such instead: ``` string input = "a, ((b)), b"; -p_context_t context; -p_context_init(&context, input); -assert_eq(P_SUCCESS, p_parse(&context)); -ABCStartXYZ * start = p_result(&context); +p_context_t * context = p_context_new(input); +assert_eq(P_SUCCESS, p_parse(context)); +ABCStartXYZ * start = p_result(context); assert(start.pItems1 !is null); assert(start.pItems !is null); ABCItemsXYZ * items = start.pItems; @@ -843,7 +841,7 @@ prefix myparser_; ``` With a parser generated with this `prefix` statement, instead of calling -`p_context_init()` you would call `myparser_context_init()`. +`p_context_new()` you would call `myparser_context_new()`. The `prefix` statement can be optionally used if you would like to change the prefix used by your generated lexer and parser to something other than the @@ -1025,27 +1023,32 @@ fields `pExpB`, `pExpB3`, and `right` will all point to the same child node ##> Functions -### `p_context_init` +### `p_context_new` -The `p_context_init()` function must be called to initialize the context -structure. +The `p_context_new()` function must be called to allocate and initialize the +context structure. The input to be used for lexing/parsing is passed in when initializing the context structure. C example: ``` -p_context_t context; -p_context_init(&context, input, input_length); +p_context_t * context = p_context_new(input, input_length); ``` D example: ``` -p_context_t context; -p_context_init(&context, input); +p_context_t * context = p_context_new(input); ``` +### `p_context_delete` + +The `p_context_delete()` function must be called to deinitialize and deallocate +a context structure allocated by `p_context_init()`. + +This function is not available for D language since D has a garbage collector. + ### `p_lex` The `p_lex()` function is the main entry point to the lexer. @@ -1057,10 +1060,9 @@ generated lexer in a standalone mode. Example: ``` -p_context_t context; -p_context_init(&context, input, input_length); +p_context_t * context = p_context_new(input, input_length); p_token_info_t token_info; -size_t result = p_lex(&context, &token_info); +size_t result = p_lex(context, &token_info); switch (result) { case P_DECODE_ERROR: @@ -1092,9 +1094,8 @@ It must be passed a pointer to an initialized context structure. Example: ``` -p_context_t context; -p_context_init(&context, input, input_length); -size_t result = p_parse(&context); +p_context_t * context = p_context_new(input, input_length); +size_t result = p_parse(context); ``` When multiple start rules are specified, a separate parse function is generated @@ -1102,7 +1103,7 @@ for each which starts parsing at the given rule. For example, if `Statement` is specified as a start rule: ``` -size_t result = p_parse_Statement(&context); +size_t result = p_parse_Statement(context); ``` In this case, the parser will start parsing with the `Statement` rule. @@ -1133,12 +1134,11 @@ The `p_result()` function can be used to retrieve the final parse value after Example: ``` -p_context_t context; -p_context_init(&context, input, input_length); -size_t result = p_parse(&context); -if (p_parse(&context) == P_SUCCESS) +p_context_t * context = p_context_new(input, input_length); +size_t result = p_parse(context); +if (p_parse(context) == P_SUCCESS) { - result = p_result(&context); + result = p_result(context); } ``` @@ -1150,12 +1150,11 @@ for each which returns the parse result for the corresponding rule. For example, if `Statement` is specified as a start rule: ``` -p_context_t context; -p_context_init(&context, input, input_length); -size_t result = p_parse(&context); -if (p_parse_Statement(&context) == P_SUCCESS) +p_context_t * context = p_context_new(input, input_length); +size_t result = p_parse(context); +if (p_parse_Statement(context) == P_SUCCESS) { - result = p_result_Statement(&context); + result = p_result_Statement(context); } ``` @@ -1170,12 +1169,11 @@ an error occurred. Example: ``` -p_context_t context; -p_context_init(&context, input, input_length); -size_t result = p_parse(&context); -if (p_parse(&context) == P_UNEXPECTED_TOKEN) +p_context_t * context = p_context_new(input, input_length); +size_t result = p_parse(context); +if (p_parse(context) == P_UNEXPECTED_TOKEN) { - p_position_t error_position = p_position(&context); + p_position_t error_position = p_position(context); fprintf(stderr, "Error: unexpected token at row %u column %u\n", error_position.row + 1, error_position.col + 1); } @@ -1192,9 +1190,9 @@ They have no particular meaning to Propane. Example: ``` -if (p_parse(&context) == P_USER_TERMINATED) +if (p_parse(context) == P_USER_TERMINATED) { - size_t user_terminate_code = p_user_terminate_code(&context); + size_t user_terminate_code = p_user_terminate_code(context); } ``` @@ -1208,9 +1206,9 @@ indicate what token the parser was not expecting. Example: ``` -if (p_parse(&context) == P_UNEXPECTED_TOKEN) +if (p_parse(context) == P_UNEXPECTED_TOKEN) { - p_token_t unexpected_token = p_token(&context); + p_token_t unexpected_token = p_token(context); } ``` @@ -1257,7 +1255,7 @@ p_free_tree_Statement(statement_tree); ``` In this case, Propane will free a `Statement` tree structure returned by the -`p_parse_Statement(&context)` function. +`p_parse_Statement(context)` function. ##> Data @@ -1269,14 +1267,13 @@ It is indexed by the token ID. C example: ``` -p_context_t context; -p_context_init(&context, input, input_length); -size_t result = p_parse(&context); -if (p_parse(&context) == P_UNEXPECTED_TOKEN) +p_context_t * context = p_context_new(input, input_length); +size_t result = p_parse(context); +if (p_parse(context) == P_UNEXPECTED_TOKEN) { - p_position_t error_position = p_position(&context); + p_position_t error_position = p_position(context); fprintf(stderr, "Error: unexpected token `%s' at row %u column %u\n", - p_token_names[context.token], + p_token_names[context->token], error_position.row + 1, error_position.col + 1); } ``` diff --git a/spec/test_basic_math_grammar.c b/spec/test_basic_math_grammar.c index 4fa1ce2..347a4b0 100644 --- a/spec/test_basic_math_grammar.c +++ b/spec/test_basic_math_grammar.c @@ -5,25 +5,29 @@ int main() { char const * input = "1 + 2 * 3 + 4"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(11, p_result(&context)); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(11, p_result(context)); + p_context_delete(context); input = "1 * 2 ** 4 * 3"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(48, p_result(&context)); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(48, p_result(context)); + p_context_delete(context); input = "(1 + 2) * 3 + 4"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(13, p_result(&context)); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(13, p_result(context)); + p_context_delete(context); input = "(2 * 2) ** 3 + 4 + 5"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(73, p_result(&context)); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(73, p_result(context)); + p_context_delete(context); return 0; } diff --git a/spec/test_basic_math_grammar.d b/spec/test_basic_math_grammar.d index cc34243..0b6f416 100644 --- a/spec/test_basic_math_grammar.d +++ b/spec/test_basic_math_grammar.d @@ -10,23 +10,23 @@ int main() unittest { string input = "1 + 2 * 3 + 4"; - p_context_t context; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(11, p_result(&context)); + p_context_t * context; + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(11, p_result(context)); input = "1 * 2 ** 4 * 3"; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(48, p_result(&context)); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(48, p_result(context)); input = "(1 + 2) * 3 + 4"; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(13, p_result(&context)); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(13, p_result(context)); input = "(2 * 2) ** 3 + 4 + 5"; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - assert_eq(73, p_result(&context)); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + assert_eq(73, p_result(context)); } diff --git a/spec/test_drop_code_block.c b/spec/test_drop_code_block.c index d6ea1b6..5efca7b 100644 --- a/spec/test_drop_code_block.c +++ b/spec/test_drop_code_block.c @@ -6,9 +6,10 @@ int main() { char const * input = " # comment 1\n# comment 2\na\n"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_drop_code_block.d b/spec/test_drop_code_block.d index bff1c19..3e638ee 100644 --- a/spec/test_drop_code_block.d +++ b/spec/test_drop_code_block.d @@ -10,7 +10,7 @@ int main() unittest { string input = " # comment 1\n# comment 2\na\n"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_error_positions.c b/spec/test_error_positions.c index 7986f83..f0a8623 100644 --- a/spec/test_error_positions.c +++ b/spec/test_error_positions.c @@ -5,38 +5,43 @@ int main() { char const * input = "a 42"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "a\n123\na a"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context).row == 3); - assert(p_position(&context).col == 4); - assert(p_token(&context) == TOKEN_a); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context).row == 3); + assert(p_position(context).col == 4); + assert(p_token(context) == TOKEN_a); + p_context_delete(context); input = "12"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context).row == 1); - assert(p_position(&context).col == 1); - assert(p_token(&context) == TOKEN_num); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context).row == 1); + assert(p_position(context).col == 1); + assert(p_token(context) == TOKEN_num); + p_context_delete(context); input = "a 12\n\nab"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_UNEXPECTED_INPUT); - assert(p_position(&context).row == 3); - assert(p_position(&context).col == 2); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_UNEXPECTED_INPUT); + assert(p_position(context).row == 3); + assert(p_position(context).col == 2); + p_context_delete(context); input = "a 12\n\na\n\n77\na \xAA"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_DECODE_ERROR); - assert(p_position(&context).row == 6); - assert(p_position(&context).col == 5); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_DECODE_ERROR); + assert(p_position(context).row == 6); + assert(p_position(context).col == 5); assert(strcmp(p_token_names[TOKEN_a], "a") == 0); assert(strcmp(p_token_names[TOKEN_num], "num") == 0); + p_context_delete(context); return 0; } diff --git a/spec/test_error_positions.d b/spec/test_error_positions.d index 8d20987..c6e617f 100644 --- a/spec/test_error_positions.d +++ b/spec/test_error_positions.d @@ -9,31 +9,31 @@ int main() unittest { string input = "a 42"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "a\n123\na a"; - p_context_init(&context, input); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context) == p_position_t(3, 4)); - assert(p_token(&context) == TOKEN_a); + context = p_context_new(input); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context) == p_position_t(3, 4)); + assert(p_token(context) == TOKEN_a); input = "12"; - p_context_init(&context, input); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context) == p_position_t(1, 1)); - assert(p_token(&context) == TOKEN_num); + context = p_context_new(input); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context) == p_position_t(1, 1)); + assert(p_token(context) == TOKEN_num); input = "a 12\n\nab"; - p_context_init(&context, input); - assert(p_parse(&context) == P_UNEXPECTED_INPUT); - assert(p_position(&context) == p_position_t(3, 2)); + context = p_context_new(input); + assert(p_parse(context) == P_UNEXPECTED_INPUT); + assert(p_position(context) == p_position_t(3, 2)); input = "a 12\n\na\n\n77\na \xAA"; - p_context_init(&context, input); - assert(p_parse(&context) == P_DECODE_ERROR); - assert(p_position(&context) == p_position_t(6, 5)); + context = p_context_new(input); + assert(p_parse(context) == P_DECODE_ERROR); + assert(p_position(context) == p_position_t(6, 5)); assert(p_token_names[TOKEN_a] == "a"); assert(p_token_names[TOKEN_num] == "num"); diff --git a/spec/test_field_aliases.c b/spec/test_field_aliases.c index d02d7b6..32a92b0 100644 --- a/spec/test_field_aliases.c +++ b/spec/test_field_aliases.c @@ -6,8 +6,9 @@ int main() { char const * input = "foo1\nbar2"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_field_aliases.d b/spec/test_field_aliases.d index 61f3a2f..f706c9e 100644 --- a/spec/test_field_aliases.d +++ b/spec/test_field_aliases.d @@ -9,7 +9,7 @@ int main() unittest { string input = "foo1\nbar2"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_free_tree_token_node_memory.c b/spec/test_free_tree_token_node_memory.c index 041fc75..f973ea7 100644 --- a/spec/test_free_tree_token_node_memory.c +++ b/spec/test_free_tree_token_node_memory.c @@ -6,14 +6,15 @@ int main() { char const * input = "ab"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + Start * start = p_result(context); assert(start->a != NULL); assert(*start->a->pvalue == 1); assert(start->b != NULL); assert(*start->b->pvalue == 2); p_free_tree(start); + p_context_delete(context); } diff --git a/spec/test_lexer.c b/spec/test_lexer.c index ad8d1af..9280078 100644 --- a/spec/test_lexer.c +++ b/spec/test_lexer.c @@ -38,73 +38,75 @@ int main() p_token_info_t token_info; char const * input = "5 + 4 * \n677 + 567"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 1u); assert(token_info.position.col == 1u); assert(token_info.end_position.row == 1u); assert(token_info.end_position.col == 1u); assert(token_info.length == 1u); assert(token_info.token == TOKEN_int); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 1u); assert(token_info.position.col == 3u); assert(token_info.end_position.row == 1u); assert(token_info.end_position.col == 3u); assert(token_info.length == 1u); assert(token_info.token == TOKEN_plus); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 1u); assert(token_info.position.col == 5u); assert(token_info.end_position.row == 1u); assert(token_info.end_position.col == 5u); assert(token_info.length == 1u); assert(token_info.token == TOKEN_int); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 1u); assert(token_info.position.col == 7u); assert(token_info.end_position.row == 1u); assert(token_info.end_position.col == 7u); assert(token_info.length == 1u); assert(token_info.token == TOKEN_times); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 2u); assert(token_info.position.col == 1u); assert(token_info.end_position.row == 2u); assert(token_info.end_position.col == 3u); assert(token_info.length == 3u); assert(token_info.token == TOKEN_int); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 2u); assert(token_info.position.col == 5u); assert(token_info.end_position.row == 2u); assert(token_info.end_position.col == 5u); assert(token_info.length == 1u); assert(token_info.token == TOKEN_plus); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 2u); assert(token_info.position.col == 7u); assert(token_info.end_position.row == 2u); assert(token_info.end_position.col == 9u); assert(token_info.length == 3u); assert(token_info.token == TOKEN_int); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 2u); assert(token_info.position.col == 10u); assert(token_info.end_position.row == 2u); assert(token_info.end_position.col == 10u); assert(token_info.length == 0u); assert(token_info.token == TOKEN___EOF); + p_context_delete(context); - p_context_init(&context, (uint8_t const *)"", 0u); - assert(p_lex(&context, &token_info) == P_SUCCESS); + context = p_context_new((uint8_t const *)"", 0u); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info.position.row == 1u); assert(token_info.position.col == 1u); assert(token_info.end_position.row == 1u); assert(token_info.end_position.col == 1u); assert(token_info.length == 0u); assert(token_info.token == TOKEN___EOF); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer.d b/spec/test_lexer.d index a3c2a1c..05b8bb7 100644 --- a/spec/test_lexer.d +++ b/spec/test_lexer.d @@ -44,26 +44,26 @@ unittest { p_token_info_t token_info; string input = "5 + 4 * \n677 + 567"; - p_context_t context; - p_context_init(&context, input); - assert(p_lex(&context, &token_info) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(1, 1), p_position_t(1, 1), 1, TOKEN_int)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(1, 3), p_position_t(1, 3), 1, TOKEN_plus)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(1, 5), p_position_t(1, 5), 1, TOKEN_int)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(1, 7), p_position_t(1, 7), 1, TOKEN_times)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(2, 1), p_position_t(2, 3), 3, TOKEN_int)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(2, 5), p_position_t(2, 5), 1, TOKEN_plus)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(2, 7), p_position_t(2, 9), 3, TOKEN_int)); - assert(p_lex(&context, &token_info) == P_SUCCESS); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(2, 10), p_position_t(2, 10), 0, TOKEN___EOF)); - p_context_init(&context, ""); - assert(p_lex(&context, &token_info) == P_SUCCESS); + context = p_context_new(""); + assert(p_lex(context, &token_info) == P_SUCCESS); assert(token_info == p_token_info_t(p_position_t(1, 1), p_position_t(1, 1), 0, TOKEN___EOF)); } diff --git a/spec/test_lexer_match_text.c b/spec/test_lexer_match_text.c index e7104d9..23ba01c 100644 --- a/spec/test_lexer_match_text.c +++ b/spec/test_lexer_match_text.c @@ -6,10 +6,11 @@ int main() { char const * input = "identifier_123"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass1\n"); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer_match_text.d b/spec/test_lexer_match_text.d index d4d0a95..8cdf397 100644 --- a/spec/test_lexer_match_text.d +++ b/spec/test_lexer_match_text.d @@ -9,8 +9,8 @@ int main() unittest { string input = `identifier_123`; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass1"); } diff --git a/spec/test_lexer_modes.c b/spec/test_lexer_modes.c index c8e3c90..2d5a344 100644 --- a/spec/test_lexer_modes.c +++ b/spec/test_lexer_modes.c @@ -6,15 +6,17 @@ int main() { char const * input = "abc \"a string\" def"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass1\n"); + p_context_delete(context); input = "abc \"abc def\" def"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass2\n"); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer_modes.d b/spec/test_lexer_modes.d index e6617b9..919ed2a 100644 --- a/spec/test_lexer_modes.d +++ b/spec/test_lexer_modes.d @@ -9,13 +9,13 @@ int main() unittest { string input = `abc "a string" def`; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass1"); input = `abc "abc def" def`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass2"); } diff --git a/spec/test_lexer_multiple_modes.c b/spec/test_lexer_multiple_modes.c index 962104b..552d4d7 100644 --- a/spec/test_lexer_multiple_modes.c +++ b/spec/test_lexer_multiple_modes.c @@ -6,15 +6,17 @@ int main() { char const * input = "abc.def"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass1\n"); + p_context_delete(context); input = "abc . abc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass2\n"); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer_multiple_modes.d b/spec/test_lexer_multiple_modes.d index 36ad01c..2a0d842 100644 --- a/spec/test_lexer_multiple_modes.d +++ b/spec/test_lexer_multiple_modes.d @@ -9,13 +9,13 @@ int main() unittest { string input = `abc.def`; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass1"); input = `abc . abc`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass2"); } diff --git a/spec/test_lexer_result_value.c b/spec/test_lexer_result_value.c index 251c6f2..e589a54 100644 --- a/spec/test_lexer_result_value.c +++ b/spec/test_lexer_result_value.c @@ -5,15 +5,17 @@ int main() { char const * input = "x"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 1u); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 1u); + p_context_delete(context); input = "fabulous"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 8u); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 8u); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer_result_value.d b/spec/test_lexer_result_value.d index 08c7b9a..7fdb163 100644 --- a/spec/test_lexer_result_value.d +++ b/spec/test_lexer_result_value.d @@ -9,13 +9,13 @@ int main() unittest { string input = `x`; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 1u); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 1u); input = `fabulous`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 8u); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 8u); } diff --git a/spec/test_lexer_unknown_character.c b/spec/test_lexer_unknown_character.c index 5b4e4d4..379d508 100644 --- a/spec/test_lexer_unknown_character.c +++ b/spec/test_lexer_unknown_character.c @@ -5,14 +5,16 @@ int main() { char const * input = "x"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_UNEXPECTED_INPUT); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_UNEXPECTED_INPUT); + p_context_delete(context); input = "123"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 123u); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 123u); + p_context_delete(context); return 0; } diff --git a/spec/test_lexer_unknown_character.d b/spec/test_lexer_unknown_character.d index 2812c7c..3af1546 100644 --- a/spec/test_lexer_unknown_character.d +++ b/spec/test_lexer_unknown_character.d @@ -9,12 +9,12 @@ int main() unittest { string input = `x`; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_UNEXPECTED_INPUT); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_UNEXPECTED_INPUT); input = `123`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 123u); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 123u); } diff --git a/spec/test_match_backslashes.c b/spec/test_match_backslashes.c index 9c08216..9bab538 100644 --- a/spec/test_match_backslashes.c +++ b/spec/test_match_backslashes.c @@ -5,9 +5,10 @@ int main() { char const * input = "\a\b\t\n\v\f\rt"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_match_backslashes.d b/spec/test_match_backslashes.d index ea630ef..b3cdcf9 100644 --- a/spec/test_match_backslashes.d +++ b/spec/test_match_backslashes.d @@ -9,7 +9,7 @@ int main() unittest { string input = "\a\b\t\n\v\f\rt"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_multiple_parsers.c b/spec/test_multiple_parsers.c index cad14a7..5b2bdb7 100644 --- a/spec/test_multiple_parsers.c +++ b/spec/test_multiple_parsers.c @@ -6,14 +6,16 @@ int main() { char const * input1 = "a\n1"; - myp1_context_t context1; - myp1_context_init(&context1, (uint8_t const *)input1, strlen(input1)); - assert(myp1_parse(&context1) == MYP1_SUCCESS); + myp1_context_t * context1; + context1 = myp1_context_new((uint8_t const *)input1, strlen(input1)); + assert(myp1_parse(context1) == MYP1_SUCCESS); + myp1_context_delete(context1); char const * input2 = "bcb"; - myp2_context_t context2; - myp2_context_init(&context2, (uint8_t const *)input2, strlen(input2)); - assert(myp2_parse(&context2) == MYP2_SUCCESS); + myp2_context_t * context2; + context2 = myp2_context_new((uint8_t const *)input2, strlen(input2)); + assert(myp2_parse(context2) == MYP2_SUCCESS); + myp2_context_delete(context2); return 0; } diff --git a/spec/test_multiple_parsers.d b/spec/test_multiple_parsers.d index 100172f..284dc7d 100644 --- a/spec/test_multiple_parsers.d +++ b/spec/test_multiple_parsers.d @@ -10,12 +10,12 @@ int main() unittest { string input1 = "a\n1"; - myp1_context_t context1; - myp1_context_init(&context1, input1); - assert(myp1_parse(&context1) == MYP1_SUCCESS); + myp1_context_t * context1; + context1 = myp1_context_new(input1); + assert(myp1_parse(context1) == MYP1_SUCCESS); string input2 = "bcb"; - myp2_context_t context2; - myp2_context_init(&context2, input2); - assert(myp2_parse(&context2) == MYP2_SUCCESS); + myp2_context_t * context2; + context2 = myp2_context_new(input2); + assert(myp2_parse(context2) == MYP2_SUCCESS); } diff --git a/spec/test_named_optional_rule_component_tree.c b/spec/test_named_optional_rule_component_tree.c index b3c45a4..2f7fea8 100644 --- a/spec/test_named_optional_rule_component_tree.c +++ b/spec/test_named_optional_rule_component_tree.c @@ -6,10 +6,10 @@ int main() { char const * input = "b"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert(start->a == NULL); assert(start->pToken2 != NULL); assert_eq(TOKEN_b, start->pToken2->token); @@ -18,11 +18,12 @@ int main() assert(start->r == NULL); p_free_tree(start); + p_context_delete(context); input = "abcd"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start->a != NULL); assert_eq(TOKEN_a, start->pToken1->token); assert(start->pToken2 != NULL); @@ -34,17 +35,19 @@ int main() assert_eq(TOKEN_c, start->pR->pToken1->token); p_free_tree(start); + p_context_delete(context); input = "bdc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start->a == NULL); assert(start->pToken2 != NULL); assert(start->r != NULL); assert_eq(TOKEN_d, start->pR->pToken1->token); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_named_optional_rule_component_tree.d b/spec/test_named_optional_rule_component_tree.d index d0658d3..f43dd83 100644 --- a/spec/test_named_optional_rule_component_tree.d +++ b/spec/test_named_optional_rule_component_tree.d @@ -10,10 +10,10 @@ int main() unittest { string input = "b"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert(start.pToken1 is null); assert(start.pToken2 !is null); assert_eq(TOKEN_b, start.pToken2.token); @@ -22,9 +22,9 @@ unittest assert(start.r is null); input = "abcd"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start.pToken1 != null); assert_eq(TOKEN_a, start.pToken1.token); assert(start.pToken2 != null); @@ -36,9 +36,9 @@ unittest assert_eq(TOKEN_c, start.pR.pToken1.token); input = "bdc"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start.pToken1 is null); assert(start.pToken2 !is null); assert(start.pR !is null); diff --git a/spec/test_optional_rule_component.c b/spec/test_optional_rule_component.c index 584432c..c05cef5 100644 --- a/spec/test_optional_rule_component.c +++ b/spec/test_optional_rule_component.c @@ -5,17 +5,20 @@ int main() { char const * input = "b"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "abcd"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "abdc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_optional_rule_component.d b/spec/test_optional_rule_component.d index dbfcd3c..2b66f8b 100644 --- a/spec/test_optional_rule_component.d +++ b/spec/test_optional_rule_component.d @@ -9,15 +9,15 @@ int main() unittest { string input = "b"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "abcd"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "abdc"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_optional_rule_component_tree.c b/spec/test_optional_rule_component_tree.c index c709298..0b10aad 100644 --- a/spec/test_optional_rule_component_tree.c +++ b/spec/test_optional_rule_component_tree.c @@ -6,10 +6,10 @@ int main() { char const * input = "b"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert(start->pToken1 == NULL); assert(start->pToken2 != NULL); assert_eq(TOKEN_b, start->pToken2->token); @@ -17,11 +17,12 @@ int main() assert(start->pR == NULL); p_free_tree(start); + p_context_delete(context); input = "abcd"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start->pToken1 != NULL); assert_eq(TOKEN_a, start->pToken1->token); assert(start->pToken2 != NULL); @@ -31,17 +32,19 @@ int main() assert_eq(TOKEN_c, start->pR->pToken1->token); p_free_tree(start); + p_context_delete(context); input = "bdc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start->pToken1 == NULL); assert(start->pToken2 != NULL); assert(start->pR != NULL); assert_eq(TOKEN_d, start->pR->pToken1->token); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_optional_rule_component_tree.d b/spec/test_optional_rule_component_tree.d index 1cc83c8..4cd5434 100644 --- a/spec/test_optional_rule_component_tree.d +++ b/spec/test_optional_rule_component_tree.d @@ -10,10 +10,10 @@ int main() unittest { string input = "b"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert(start.pToken1 is null); assert(start.pToken2 !is null); assert_eq(TOKEN_b, start.pToken2.token); @@ -21,9 +21,9 @@ unittest assert(start.pR is null); input = "abcd"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start.pToken1 != null); assert_eq(TOKEN_a, start.pToken1.token); assert(start.pToken2 != null); @@ -33,9 +33,9 @@ unittest assert_eq(TOKEN_c, start.pR.pToken1.token); input = "bdc"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert(start.pToken1 is null); assert(start.pToken2 !is null); assert(start.pR !is null); diff --git a/spec/test_parser_identical_rules_lookahead.c b/spec/test_parser_identical_rules_lookahead.c index c66932d..27afd9d 100644 --- a/spec/test_parser_identical_rules_lookahead.c +++ b/spec/test_parser_identical_rules_lookahead.c @@ -5,13 +5,15 @@ int main() { char const * input = "aba"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "abb"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_parser_identical_rules_lookahead.d b/spec/test_parser_identical_rules_lookahead.d index 3ea08a0..9deca51 100644 --- a/spec/test_parser_identical_rules_lookahead.d +++ b/spec/test_parser_identical_rules_lookahead.d @@ -9,11 +9,11 @@ int main() unittest { string input = "aba"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "abb"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_parser_rule_from_multiple_states.c b/spec/test_parser_rule_from_multiple_states.c index 7af1c7f..2368e80 100644 --- a/spec/test_parser_rule_from_multiple_states.c +++ b/spec/test_parser_rule_from_multiple_states.c @@ -5,20 +5,23 @@ int main() { char const * input = "a"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context).row == 1); - assert(p_position(&context).col == 2); - assert(context.token == TOKEN___EOF); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context).row == 1); + assert(p_position(context).col == 2); + assert(context->token == TOKEN___EOF); + p_context_delete(context); input = "a b"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "bb"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_parser_rule_from_multiple_states.d b/spec/test_parser_rule_from_multiple_states.d index f37f27f..6d67916 100644 --- a/spec/test_parser_rule_from_multiple_states.d +++ b/spec/test_parser_rule_from_multiple_states.d @@ -9,17 +9,17 @@ int main() unittest { string input = "a"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_UNEXPECTED_TOKEN); - assert(p_position(&context) == p_position_t(1, 2)); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_UNEXPECTED_TOKEN); + assert(p_position(context) == p_position_t(1, 2)); assert(context.token == TOKEN___EOF); input = "a b"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "bb"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_parser_rule_user_code.c b/spec/test_parser_rule_user_code.c index d191cc7..3123983 100644 --- a/spec/test_parser_rule_user_code.c +++ b/spec/test_parser_rule_user_code.c @@ -5,9 +5,10 @@ int main() { char const * input = "ab"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_parser_rule_user_code.d b/spec/test_parser_rule_user_code.d index 8866eb0..e38f262 100644 --- a/spec/test_parser_rule_user_code.d +++ b/spec/test_parser_rule_user_code.d @@ -9,7 +9,7 @@ int main() unittest { string input = "ab"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_parsing_json.c b/spec/test_parsing_json.c index 8382e36..e3ae003 100644 --- a/spec/test_parsing_json.c +++ b/spec/test_parsing_json.c @@ -6,51 +6,58 @@ int main() { char const * input = ""; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "{}"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context)->id == JSON_OBJECT); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context)->id == JSON_OBJECT); + p_context_delete(context); input = "[]"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context)->id == JSON_ARRAY); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context)->id == JSON_ARRAY); + p_context_delete(context); input = "-45.6"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context)->id == JSON_NUMBER); - assert(p_result(&context)->number == -45.6); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context)->id == JSON_NUMBER); + assert(p_result(context)->number == -45.6); + p_context_delete(context); input = "2E-2"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context)->id == JSON_NUMBER); - assert(p_result(&context)->number == 0.02); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context)->id == JSON_NUMBER); + assert(p_result(context)->number == 0.02); + p_context_delete(context); input = "{\"hi\":true}"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - JSONValue * o = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + JSONValue * o = p_result(context); assert(o->id == JSON_OBJECT); assert_eq(1, o->object.size); assert(strcmp(o->object.entries[0].name, "hi") == 0); assert(o->object.entries[0].value->id == JSON_TRUE); + p_context_delete(context); input = "{\"ff\": false, \"nn\": null}"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - o = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + o = p_result(context); assert(o->id == JSON_OBJECT); assert_eq(2, o->object.size); assert(strcmp(o->object.entries[0].name, "ff") == 0); assert(o->object.entries[0].value->id == JSON_FALSE); assert(strcmp(o->object.entries[1].name, "nn") == 0); assert(o->object.entries[1].value->id == JSON_NULL); + p_context_delete(context); return 0; } diff --git a/spec/test_parsing_json.d b/spec/test_parsing_json.d index 27fb386..a695a71 100644 --- a/spec/test_parsing_json.d +++ b/spec/test_parsing_json.d @@ -10,45 +10,45 @@ int main() unittest { string input = ``; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = `{}`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(cast(JSONObject)p_result(&context)); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(cast(JSONObject)p_result(context)); input = `[]`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(cast(JSONArray)p_result(&context)); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(cast(JSONArray)p_result(context)); input = `-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); + context = p_context_new(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`; - 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); + context = p_context_new(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}`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(cast(JSONObject)p_result(&context)); - JSONObject o = cast(JSONObject)p_result(&context); + context = p_context_new(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}`; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(cast(JSONObject)p_result(&context)); - o = cast(JSONObject)p_result(&context); + context = p_context_new(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"]); diff --git a/spec/test_parsing_lists.c b/spec/test_parsing_lists.c index e78d8f1..4683f75 100644 --- a/spec/test_parsing_lists.c +++ b/spec/test_parsing_lists.c @@ -5,20 +5,23 @@ int main() { char const * input = "a"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 1u); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 1u); + p_context_delete(context); input = ""; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 0u); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 0u); + p_context_delete(context); input = "aaaaaaaaaaaaaaaa"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 16u); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 16u); + p_context_delete(context); return 0; } diff --git a/spec/test_parsing_lists.d b/spec/test_parsing_lists.d index 86fdd20..1359724 100644 --- a/spec/test_parsing_lists.d +++ b/spec/test_parsing_lists.d @@ -9,18 +9,18 @@ int main() unittest { string input = "a"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 1u); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 1u); input = ""; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 0u); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 0u); input = "aaaaaaaaaaaaaaaa"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - assert(p_result(&context) == 16u); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + assert(p_result(context) == 16u); } diff --git a/spec/test_pattern.c b/spec/test_pattern.c index 193c957..5b48778 100644 --- a/spec/test_pattern.c +++ b/spec/test_pattern.c @@ -6,15 +6,17 @@ int main() { char const * input = "abcdef"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass1\n"); + p_context_delete(context); input = "defabcdef"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass2\n"); + p_context_delete(context); return 0; } diff --git a/spec/test_pattern.d b/spec/test_pattern.d index df62ad4..74f58fe 100644 --- a/spec/test_pattern.d +++ b/spec/test_pattern.d @@ -9,13 +9,13 @@ int main() unittest { string input = "abcdef"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass1"); input = "defabcdef"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass2"); } diff --git a/spec/test_return_token_from_pattern.c b/spec/test_return_token_from_pattern.c index a8be3d2..9f7da09 100644 --- a/spec/test_return_token_from_pattern.c +++ b/spec/test_return_token_from_pattern.c @@ -5,9 +5,10 @@ int main() { char const * input = "defghidef"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); return 0; } diff --git a/spec/test_return_token_from_pattern.d b/spec/test_return_token_from_pattern.d index f14fcd8..b618f8d 100644 --- a/spec/test_return_token_from_pattern.d +++ b/spec/test_return_token_from_pattern.d @@ -9,7 +9,7 @@ int main() unittest { string input = "defghidef"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); } diff --git a/spec/test_start_rule_tree.c b/spec/test_start_rule_tree.c index 025567e..b33b8ab 100644 --- a/spec/test_start_rule_tree.c +++ b/spec/test_start_rule_tree.c @@ -6,14 +6,15 @@ int main() { char const * input = "hi"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - Top * top = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + Top * top = p_result(context); assert(top->pToken != NULL); assert_eq(TOKEN_hi, top->pToken->token); p_free_tree(top); + p_context_delete(context); return 0; } diff --git a/spec/test_start_rule_tree.d b/spec/test_start_rule_tree.d index 4fb95e0..d0a0d4b 100644 --- a/spec/test_start_rule_tree.d +++ b/spec/test_start_rule_tree.d @@ -10,10 +10,10 @@ int main() unittest { string input = "hi"; - p_context_t context; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - Top * top = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + Top * top = p_result(context); assert(top.pToken !is null); assert_eq(TOKEN_hi, top.pToken.token); } diff --git a/spec/test_starting_rules.c b/spec/test_starting_rules.c index 0d23c01..eb8f4bd 100644 --- a/spec/test_starting_rules.c +++ b/spec/test_starting_rules.c @@ -6,22 +6,25 @@ int main() { char const * input = "bbbb"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - int result = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + int result = p_result(context); assert_eq(8, result); + p_context_delete(context); - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse_Bs(&context) == P_SUCCESS); - result = p_result_Bs(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse_Bs(context) == P_SUCCESS); + result = p_result_Bs(context); assert_eq(8, result); + p_context_delete(context); input = "c"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse_R(&context) == P_SUCCESS); - result = p_result_R(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse_R(context) == P_SUCCESS); + result = p_result_R(context); assert_eq(3, result); + p_context_delete(context); return 0; } diff --git a/spec/test_starting_rules.d b/spec/test_starting_rules.d index bb32022..2c1b217 100644 --- a/spec/test_starting_rules.d +++ b/spec/test_starting_rules.d @@ -10,20 +10,20 @@ int main() unittest { string input = "bbbb"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - int result = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + int result = p_result(context); assert(result == 8); - p_context_init(&context, input); - assert(p_parse_Bs(&context) == P_SUCCESS); - result = p_result_Bs(&context); + context = p_context_new(input); + assert(p_parse_Bs(context) == P_SUCCESS); + result = p_result_Bs(context); assert(result == 8); input = "c"; - p_context_init(&context, input); - assert(p_parse_R(&context) == P_SUCCESS); - result = p_result_R(&context); + context = p_context_new(input); + assert(p_parse_R(context) == P_SUCCESS); + result = p_result_R(context); assert(result == 3); } diff --git a/spec/test_starting_rules_tree.c b/spec/test_starting_rules_tree.c index 2b5403a..ed739c6 100644 --- a/spec/test_starting_rules_tree.c +++ b/spec/test_starting_rules_tree.c @@ -6,32 +6,35 @@ int main() { char const * input = "bbbb"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_not_null(start->bs); assert_not_null(start->bs->b); assert_not_null(start->bs->bs->b); assert_not_null(start->bs->bs->bs->b); assert_not_null(start->bs->bs->bs->bs->b); p_free_tree(start); + p_context_delete(context); - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse_Bs(&context) == P_SUCCESS); - Bs * bs = p_result_Bs(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse_Bs(context) == P_SUCCESS); + Bs * bs = p_result_Bs(context); assert_not_null(bs->b); assert_not_null(bs->bs->b); assert_not_null(bs->bs->bs->b); assert_not_null(bs->bs->bs->bs->b); p_free_tree_Bs(bs); + p_context_delete(context); input = "c"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse_R(&context) == P_SUCCESS); - R * r = p_result_R(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse_R(context) == P_SUCCESS); + R * r = p_result_R(context); assert_not_null(r->c); p_free_tree_R(r); + p_context_delete(context); return 0; } diff --git a/spec/test_starting_rules_tree.d b/spec/test_starting_rules_tree.d index 4738132..2d619bc 100644 --- a/spec/test_starting_rules_tree.d +++ b/spec/test_starting_rules_tree.d @@ -10,27 +10,27 @@ int main() unittest { string input = "bbbb"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert(start.bs); assert(start.bs.b); assert(start.bs.bs.b); assert(start.bs.bs.bs.b); assert(start.bs.bs.bs.bs.b); - p_context_init(&context, input); - assert(p_parse_Bs(&context) == P_SUCCESS); - Bs * bs = p_result_Bs(&context); + context = p_context_new(input); + assert(p_parse_Bs(context) == P_SUCCESS); + Bs * bs = p_result_Bs(context); assert(bs.b); assert(bs.bs.b); assert(bs.bs.bs.b); assert(bs.bs.bs.bs.b); input = "c"; - p_context_init(&context, input); - assert(p_parse_R(&context) == P_SUCCESS); - R * r = p_result_R(&context); + context = p_context_new(input); + assert(p_parse_R(context) == P_SUCCESS); + R * r = p_result_R(context); assert(r.c); } diff --git a/spec/test_tree.c b/spec/test_tree.c index 883030b..42d2bc5 100644 --- a/spec/test_tree.c +++ b/spec/test_tree.c @@ -6,10 +6,10 @@ int main() { char const * input = "a, ((b)), b"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + Start * start = p_result(context); assert(start->pItems1 != NULL); assert(start->pItems != NULL); Items * items = start->pItems; @@ -34,19 +34,21 @@ int main() assert(itemsmore->pItemsMore == NULL); p_free_tree(start); + p_context_delete(context); input = ""; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start->pItems == NULL); p_free_tree(start); + p_context_delete(context); input = "2 1"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start->pItems != NULL); assert(start->pItems->pItem != NULL); assert(start->pItems->pItem->pDual != NULL); @@ -56,6 +58,7 @@ int main() assert(start->pItems->pItem->pDual->pOne1 == NULL); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_tree.d b/spec/test_tree.d index caf6ad5..53d8569 100644 --- a/spec/test_tree.d +++ b/spec/test_tree.d @@ -10,10 +10,10 @@ int main() unittest { string input = "a, ((b)), b"; - p_context_t context; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + Start * start = p_result(context); assert(start.pItems1 !is null); assert(start.pItems !is null); Items * items = start.pItems; @@ -38,15 +38,15 @@ unittest assert(itemsmore.pItemsMore is null); input = ""; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start.pItems is null); input = "2 1"; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start.pItems !is null); assert(start.pItems.pItem !is null); assert(start.pItems.pItem.pDual !is null); diff --git a/spec/test_tree_field_aliases.c b/spec/test_tree_field_aliases.c index 0a3f51a..2aec19e 100644 --- a/spec/test_tree_field_aliases.c +++ b/spec/test_tree_field_aliases.c @@ -6,16 +6,17 @@ int main() { char const * input = "\na\nb\nc"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(TOKEN_a, start->first->pToken->token); assert_eq(TOKEN_b, start->second->pToken->token); assert_eq(TOKEN_c, start->third->pToken->token); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_tree_field_aliases.d b/spec/test_tree_field_aliases.d index 907946e..bcf0e85 100644 --- a/spec/test_tree_field_aliases.d +++ b/spec/test_tree_field_aliases.d @@ -10,10 +10,10 @@ int main() unittest { string input = "\na\nb\nc"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(TOKEN_a, start.first.pToken.token); assert_eq(TOKEN_b, start.second.pToken.token); diff --git a/spec/test_tree_invalid_positions.c b/spec/test_tree_invalid_positions.c index 454bb3a..ba268ce 100644 --- a/spec/test_tree_invalid_positions.c +++ b/spec/test_tree_invalid_positions.c @@ -6,10 +6,10 @@ int main() { char const * input = "\na\n bb ccc"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(2, start->pT1->pToken->position.row); assert_eq(1, start->pT1->pToken->position.col); @@ -31,11 +31,12 @@ int main() assert_eq(8, start->end_position.col); p_free_tree(start); + p_context_delete(context); input = "a\nbb"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start->pT1->pToken->position.row); assert_eq(1, start->pT1->pToken->position.col); @@ -57,11 +58,12 @@ int main() assert_eq(2, start->end_position.col); p_free_tree(start); + p_context_delete(context); input = "a\nc\nc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start->pT1->pToken->position.row); assert_eq(1, start->pT1->pToken->position.col); @@ -83,11 +85,12 @@ int main() assert_eq(1, start->end_position.col); p_free_tree(start); + p_context_delete(context); input = "a"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start->pT1->pToken->position.row); assert_eq(1, start->pT1->pToken->position.col); @@ -105,6 +108,7 @@ int main() assert_eq(1, start->end_position.col); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_tree_invalid_positions.d b/spec/test_tree_invalid_positions.d index 19fc744..b6010dd 100644 --- a/spec/test_tree_invalid_positions.d +++ b/spec/test_tree_invalid_positions.d @@ -10,10 +10,10 @@ int main() unittest { string input = "\na\n bb ccc"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(2, start.pT1.pToken.position.row); assert_eq(1, start.pT1.pToken.position.col); @@ -35,9 +35,9 @@ unittest assert_eq(8, start.end_position.col); input = "a\nbb"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start.pT1.pToken.position.row); assert_eq(1, start.pT1.pToken.position.col); @@ -59,9 +59,9 @@ unittest assert_eq(2, start.end_position.col); input = "a\nc\nc"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start.pT1.pToken.position.row); assert_eq(1, start.pT1.pToken.position.col); @@ -83,9 +83,9 @@ unittest assert_eq(1, start.end_position.col); input = "a"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(1, start.pT1.pToken.position.row); assert_eq(1, start.pT1.pToken.position.col); diff --git a/spec/test_tree_node_memory_remains.c b/spec/test_tree_node_memory_remains.c index 2c8a65f..65d16b3 100644 --- a/spec/test_tree_node_memory_remains.c +++ b/spec/test_tree_node_memory_remains.c @@ -369,11 +369,11 @@ int main(int argc, char * argv[]) {"size_t_to_ulong", TOKEN_ulong}, {"main", TOKEN_int}, }; - p_context_t context; - p_context_init(&context, (const uint8_t *)input, strlen(input)); - size_t result = p_parse(&context); + p_context_t * context; + context = p_context_new((const uint8_t *)input, strlen(input)); + size_t result = p_parse(context); assert_eq(P_SUCCESS, result); - PModule * pmod = p_result(&context); + PModule * pmod = p_result(context); PModuleItems * pmis = pmod->pModuleItems; PFunctionDefinition ** pfds; size_t n_pfds = 0u; @@ -413,6 +413,7 @@ int main(int argc, char * argv[]) free(pfds); p_free_tree(pmod); + p_context_delete(context); return 0; } diff --git a/spec/test_tree_node_memory_remains.d b/spec/test_tree_node_memory_remains.d index 8612ac3..7b83448 100644 --- a/spec/test_tree_node_memory_remains.d +++ b/spec/test_tree_node_memory_remains.d @@ -374,11 +374,11 @@ def main() -> int Expected("size_t_to_ulong", TOKEN_ulong), Expected("main", TOKEN_int), ]; - p_context_t context; - p_context_init(&context, input); - size_t result = p_parse(&context); + p_context_t * context; + context = p_context_new(input); + size_t result = p_parse(context); assert_eq(P_SUCCESS, result); - PModule * pmod = p_result(&context); + PModule * pmod = p_result(context); PModuleItems * pmis = pmod.pModuleItems; PFunctionDefinition *[] pfds; while (pmis !is null) diff --git a/spec/test_tree_ps.c b/spec/test_tree_ps.c index 62ec7cc..09c966d 100644 --- a/spec/test_tree_ps.c +++ b/spec/test_tree_ps.c @@ -6,10 +6,10 @@ int main() { char const * input = "a, ((b)), b"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - PStartS * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + PStartS * start = p_result(context); assert(start->pItems1 != NULL); assert(start->pItems != NULL); PItemsS * items = start->pItems; @@ -34,19 +34,21 @@ int main() assert(itemsmore->pItemsMore == NULL); p_free_tree(start); + p_context_delete(context); input = ""; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start->pItems == NULL); p_free_tree(start); + p_context_delete(context); input = "2 1"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start->pItems != NULL); assert(start->pItems->pItem != NULL); assert(start->pItems->pItem->pDual != NULL); @@ -56,6 +58,7 @@ int main() assert(start->pItems->pItem->pDual->pOne1 == NULL); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_tree_ps.d b/spec/test_tree_ps.d index 8d01e6f..e331243 100644 --- a/spec/test_tree_ps.d +++ b/spec/test_tree_ps.d @@ -10,10 +10,10 @@ int main() unittest { string input = "a, ((b)), b"; - p_context_t context; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - PStartS * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + PStartS * start = p_result(context); assert(start.pItems1 !is null); assert(start.pItems !is null); PItemsS * items = start.pItems; @@ -38,15 +38,15 @@ unittest assert(itemsmore.pItemsMore is null); input = ""; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start.pItems is null); input = "2 1"; - p_context_init(&context, input); - assert_eq(P_SUCCESS, p_parse(&context)); - start = p_result(&context); + context = p_context_new(input); + assert_eq(P_SUCCESS, p_parse(context)); + start = p_result(context); assert(start.pItems !is null); assert(start.pItems.pItem !is null); assert(start.pItems.pItem.pDual !is null); diff --git a/spec/test_tree_token_positions.c b/spec/test_tree_token_positions.c index 8d68776..aaa6aec 100644 --- a/spec/test_tree_token_positions.c +++ b/spec/test_tree_token_positions.c @@ -6,10 +6,10 @@ int main() { char const * input = "abbccc"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(1, start->pT1->pToken->position.row); assert_eq(1, start->pT1->pToken->position.col); @@ -44,11 +44,12 @@ int main() assert_eq(6, start->end_position.col); p_free_tree(start); + p_context_delete(context); input = "\n\n bb\nc\ncc\n\n a"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(3, start->pT1->pToken->position.row); assert_eq(3, start->pT1->pToken->position.col); @@ -83,6 +84,7 @@ int main() assert_eq(6, start->end_position.col); p_free_tree(start); + p_context_delete(context); return 0; } diff --git a/spec/test_tree_token_positions.d b/spec/test_tree_token_positions.d index e5930d7..84a085e 100644 --- a/spec/test_tree_token_positions.d +++ b/spec/test_tree_token_positions.d @@ -10,10 +10,10 @@ int main() unittest { string input = "abbccc"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - Start * start = p_result(&context); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + Start * start = p_result(context); assert_eq(1, start.pT1.pToken.position.row); assert_eq(1, start.pT1.pToken.position.col); @@ -48,9 +48,9 @@ unittest assert_eq(6, start.end_position.col); input = "\n\n bb\nc\ncc\n\n a"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); - start = p_result(&context); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); + start = p_result(context); assert_eq(3, start.pT1.pToken.position.row); assert_eq(3, start.pT1.pToken.position.col); diff --git a/spec/test_user_code.c b/spec/test_user_code.c index cd853bc..ad93316 100644 --- a/spec/test_user_code.c +++ b/spec/test_user_code.c @@ -6,15 +6,17 @@ int main() { char const * input = "abcdef"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass1\n"); + p_context_delete(context); input = "abcabcdef"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); printf("pass2\n"); + p_context_delete(context); return 0; } diff --git a/spec/test_user_code.d b/spec/test_user_code.d index 18e182d..8245cbf 100644 --- a/spec/test_user_code.d +++ b/spec/test_user_code.d @@ -9,13 +9,13 @@ int main() unittest { string input = "abcdef"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass1"); input = "abcabcdef"; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); writeln("pass2"); } diff --git a/spec/test_user_context_fields.c b/spec/test_user_context_fields.c index 003cc23..ae7a6d2 100644 --- a/spec/test_user_context_fields.c +++ b/spec/test_user_context_fields.c @@ -7,13 +7,14 @@ int main() { char const * input = "aaa\n\n\na\n # comment 1\na a aa\n\naa\n# comment 2\na\n"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); - fprintf(stderr, "comments: %s", context.comments); - fprintf(stderr, "acount: %u\n", context.acount); - free(context.comments); + fprintf(stderr, "comments: %s", context->comments); + fprintf(stderr, "acount: %u\n", context->acount); + free(context->comments); + p_context_delete(context); return 0; } diff --git a/spec/test_user_context_fields.d b/spec/test_user_context_fields.d index aabb10f..b742d0b 100644 --- a/spec/test_user_context_fields.d +++ b/spec/test_user_context_fields.d @@ -10,9 +10,9 @@ int main() unittest { string input = "aaa\n\n\na\n # comment 1\na a aa\n\naa\n# comment 2\na\n"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); stderr.writeln("comments: ", context.comments); stderr.writeln("acount: ", context.acount); diff --git a/spec/test_user_terminate.c b/spec/test_user_terminate.c index 87a537b..03c7b57 100644 --- a/spec/test_user_terminate.c +++ b/spec/test_user_terminate.c @@ -6,14 +6,16 @@ int main() { char const * input = "aacc"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "abc"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_USER_TERMINATED); - assert(p_user_terminate_code(&context) == 4200); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_USER_TERMINATED); + assert(p_user_terminate_code(context) == 4200); + p_context_delete(context); return 0; } diff --git a/spec/test_user_terminate.d b/spec/test_user_terminate.d index a05faff..108d373 100644 --- a/spec/test_user_terminate.d +++ b/spec/test_user_terminate.d @@ -9,12 +9,12 @@ int main() unittest { string input = "aacc"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "abc"; - p_context_init(&context, input); - assert(p_parse(&context) == P_USER_TERMINATED); - assert(p_user_terminate_code(&context) == 4200); + context = p_context_new(input); + assert(p_parse(context) == P_USER_TERMINATED); + assert(p_user_terminate_code(context) == 4200); } diff --git a/spec/test_user_terminate_lexer.c b/spec/test_user_terminate_lexer.c index ca25400..22d38ef 100644 --- a/spec/test_user_terminate_lexer.c +++ b/spec/test_user_terminate_lexer.c @@ -6,14 +6,16 @@ int main() { char const * input = "a"; - p_context_t context; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_SUCCESS); + p_context_delete(context); input = "b"; - p_context_init(&context, (uint8_t const *)input, strlen(input)); - assert(p_parse(&context) == P_USER_TERMINATED); - assert(p_user_terminate_code(&context) == 8675309); + context = p_context_new((uint8_t const *)input, strlen(input)); + assert(p_parse(context) == P_USER_TERMINATED); + assert(p_user_terminate_code(context) == 8675309); + p_context_delete(context); return 0; } diff --git a/spec/test_user_terminate_lexer.d b/spec/test_user_terminate_lexer.d index 5de5280..56ac134 100644 --- a/spec/test_user_terminate_lexer.d +++ b/spec/test_user_terminate_lexer.d @@ -9,12 +9,12 @@ int main() unittest { string input = "a"; - p_context_t context; - p_context_init(&context, input); - assert(p_parse(&context) == P_SUCCESS); + p_context_t * context; + context = p_context_new(input); + assert(p_parse(context) == P_SUCCESS); input = "b"; - p_context_init(&context, input); - assert(p_parse(&context) == P_USER_TERMINATED); - assert(p_user_terminate_code(&context) == 8675309); + context = p_context_new(input); + assert(p_parse(context) == P_USER_TERMINATED); + assert(p_user_terminate_code(context) == 8675309); }