Add p_result_*() and p_free_ast_*() functions for each start node
This commit is contained in:
parent
7122bdc2db
commit
87890a3d77
@ -1111,16 +1111,27 @@ size_t <%= @grammar.prefix %>parse(<%= @grammar.prefix %>context_t * context)
|
|||||||
*/
|
*/
|
||||||
<% if @grammar.ast %>
|
<% if @grammar.ast %>
|
||||||
<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return (<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> *) context->parse_result;
|
||||||
|
}
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return (<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> *) context->parse_result;
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
<%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
||||||
<% end %>
|
|
||||||
{
|
{
|
||||||
<% if @grammar.ast %>
|
|
||||||
return (<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> *) context->parse_result;
|
|
||||||
<% else %>
|
|
||||||
return context->parse_result.v_<%= start_rule_type[0] %>;
|
return context->parse_result.v_<%= start_rule_type[0] %>;
|
||||||
<% end %>
|
|
||||||
}
|
}
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
<%= start_rule_type(i)[1] %> <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return context->parse_result.v_<%= start_rule_type(i)[0] %>;
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current text input position.
|
* Get the current text input position.
|
||||||
@ -1188,4 +1199,14 @@ void <%= @grammar.prefix %>free_ast(<%= @grammar.ast_prefix %><%= @grammar.start
|
|||||||
{
|
{
|
||||||
free_ast_node((ASTNode *)ast);
|
free_ast_node((ASTNode *)ast);
|
||||||
}
|
}
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free all AST node memory.
|
||||||
|
*/
|
||||||
|
void <%= @grammar.prefix %>free_ast_<%= start_rule %>(<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> * ast)
|
||||||
|
{
|
||||||
|
free_ast_node((ASTNode *)ast);
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -1157,16 +1157,27 @@ public size_t <%= @grammar.prefix %>parse(<%= @grammar.prefix %>context_t * cont
|
|||||||
*/
|
*/
|
||||||
<% if @grammar.ast %>
|
<% if @grammar.ast %>
|
||||||
public <%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
public <%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return cast(<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> *)context.parse_result;
|
||||||
|
}
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
public <%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return cast(<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> *)context.parse_result;
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
public <%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
public <%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context)
|
||||||
<% end %>
|
|
||||||
{
|
{
|
||||||
<% if @grammar.ast %>
|
|
||||||
return cast(<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> *)context.parse_result;
|
|
||||||
<% else %>
|
|
||||||
return context.parse_result.v_<%= start_rule_type[0] %>;
|
return context.parse_result.v_<%= start_rule_type[0] %>;
|
||||||
<% end %>
|
|
||||||
}
|
}
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
public <%= start_rule_type(i)[1] %> <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context)
|
||||||
|
{
|
||||||
|
return context.parse_result.v_<%= start_rule_type(i)[0] %>;
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current text input position.
|
* Get the current text input position.
|
||||||
|
|||||||
@ -192,10 +192,21 @@ size_t <%= @grammar.prefix %>parse(<%= @grammar.prefix %>context_t * context);
|
|||||||
|
|
||||||
<% if @grammar.ast %>
|
<% if @grammar.ast %>
|
||||||
<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context);
|
<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context);
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
void <%= @grammar.prefix %>free_ast(<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * ast);
|
<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> * <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context);
|
||||||
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context);
|
<%= start_rule_type[1] %> <%= @grammar.prefix %>result(<%= @grammar.prefix %>context_t * context);
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
<%= start_rule_type(i)[1] %> <%= @grammar.prefix %>result_<%= start_rule %>(<%= @grammar.prefix %>context_t * context);
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @grammar.ast %>
|
||||||
|
void <%= @grammar.prefix %>free_ast(<%= @grammar.ast_prefix %><%= @grammar.start_rules[0] %><%= @grammar.ast_suffix %> * ast);
|
||||||
|
<% @grammar.start_rules.each_with_index do |start_rule, i| %>
|
||||||
|
void <%= @grammar.prefix %>free_ast_<%= start_rule %>(<%= @grammar.ast_prefix %><%= start_rule %><%= @grammar.ast_suffix %> * ast);
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= @grammar.prefix %>position_t <%= @grammar.prefix %>position(<%= @grammar.prefix %>context_t * context);
|
<%= @grammar.prefix %>position_t <%= @grammar.prefix %>position(<%= @grammar.prefix %>context_t * context);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user