Rename lexer and parser State structs to avoid conflicts

This commit is contained in:
Josh Holtrop 2023-07-10 11:21:45 -04:00
parent 1c50d37a3e
commit f973e9dc2c

View File

@ -149,8 +149,8 @@ class <%= @classname %>
static class Lexer
{
alias StateID = <%= get_type_for(@lexer.state_table.size) %>;
enum StateID INVALID_STATE_ID = <%= @lexer.state_table.size %>u;
alias LexerStateID = <%= get_type_for(@lexer.state_table.size) %>;
enum LexerStateID INVALID_LEXER_STATE_ID = <%= @lexer.state_table.size %>u;
<% user_code_id_count = (@grammar.patterns.map(&:code_id).compact.max || 0) + 1 %>
alias UserCodeID = <%= get_type_for(user_code_id_count) %>;
enum UserCodeID INVALID_USER_CODE_ID = <%= user_code_id_count %>u;
@ -159,10 +159,10 @@ class <%= @classname %>
{
CodePoint first;
CodePoint last;
StateID destination_state;
LexerStateID destination_state;
}
private struct State
private struct LexerState
{
<%= get_type_for(@lexer.transition_table.size - 1) %> transition_table_index;
<%= get_type_for(@lexer.state_table.map {|ste| ste[:n_transitions]}.max) %> n_transitions;
@ -184,21 +184,21 @@ class <%= @classname %>
<% end %>
];
private static immutable State[] states = [
private static immutable LexerState[] states = [
<% @lexer.state_table.each do |state_table_entry| %>
State(<%= state_table_entry[:transition_table_index] %>u,
<%= state_table_entry[:n_transitions] %>u,
LexerState(<%= state_table_entry[:transition_table_index] %>u,
<%= state_table_entry[:n_transitions] %>u,
<% if state_table_entry[:token] %>
Token(<%= state_table_entry[:token] %>u),
Token(<%= state_table_entry[:token] %>u),
<% else %>
INVALID_TOKEN_ID,
INVALID_TOKEN_ID,
<% end %>
<% if state_table_entry[:code_id] %>
<%= state_table_entry[:code_id] %>u,
<%= state_table_entry[:code_id] %>u,
<% else %>
INVALID_USER_CODE_ID,
INVALID_USER_CODE_ID,
<% end %>
<%= state_table_entry[:accepts] %>),
<%= state_table_entry[:accepts] %>),
<% end %>
];
@ -343,7 +343,7 @@ class <%= @classname %>
{
size_t length;
Position delta_position;
const(State) * accepting_state;
const(LexerState) * accepting_state;
}
/**
@ -371,8 +371,8 @@ class <%= @classname %>
switch (result)
{
case P_SUCCESS:
StateID transition_state = transition(current_state, code_point);
if (transition_state != INVALID_STATE_ID)
LexerStateID transition_state = transition(current_state, code_point);
if (transition_state != INVALID_LEXER_STATE_ID)
{
attempt_match.length += code_point_length;
if (code_point == '\n')
@ -430,7 +430,7 @@ class <%= @classname %>
}
}
private StateID transition(uint current_state, uint code_point)
private LexerStateID transition(uint current_state, uint code_point)
{
uint transition_table_index = states[current_state].transition_table_index;
for (uint i = 0u; i < states[current_state].n_transitions; i++)
@ -441,7 +441,7 @@ class <%= @classname %>
return transitions[transition_table_index + i].destination_state;
}
}
return INVALID_STATE_ID;
return INVALID_LEXER_STATE_ID;
}
}
@ -461,7 +461,7 @@ class <%= @classname %>
uint n_states;
}
private struct State
private struct ParserState
{
uint shift_table_index;
uint n_shift_entries;
@ -492,9 +492,9 @@ class <%= @classname %>
<% end %>
];
private static immutable State[] states = [
private static immutable ParserState[] states = [
<% @parser.state_table.each do |state| %>
State(<%= state[:shift_index] %>u, <%= state[:n_shifts] %>u, <%= state[:reduce_index] %>u, <%= state[:n_reduces] %>u),
ParserState(<%= state[:shift_index] %>u, <%= state[:n_shifts] %>u, <%= state[:reduce_index] %>u, <%= state[:n_reduces] %>u),
<% end %>
];