propane/assets/parser.d.erb
2021-06-24 15:06:10 -04:00

43 lines
925 B
Plaintext

<% if @grammar.modulename %>
module <%= @grammar.modulename %>;
<% end %>
class <%= classname %>
{
enum
{
<% @grammar.tokens.each do |token| %>
TOKEN_<%= token.c_name %>,
<% end %>
}
private struct Transition
{
uint first;
uint last;
uint destination;
}
private struct LexerState
{
Transition[] transitions;
size_t accepts;
}
private static const LexerState lexer_states[] = [
<% lexer_dfa.enumerate.each do |state, index| %>
LexerState([
<% state.transitions.each do |transition| %>
Transition(<%= transition.code_point_range.first %>, <%= transition.code_point_range.last %>, <%= lexer_dfa.enumerate[transition.destination] %>),
<% end %>
],
<% if state.accepts %>
<%= state.accepts.id %>,
<% else %>
cast(size_t)-1,
<% end %>
),
<% end %>
];
}