Replace p_context_init() with p_context_new()/p_context_delete()
This commit is contained in:
1 parent
9f2fe6f84b
commit
6fd5186159
77 files changed
+728
-610
No files matched your search
+32
-14
@@ -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 %>
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
+13
-11
@@ -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;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
+3
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user