43 lines
918 B
Plaintext
43 lines
918 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 dest;
|
|
}
|
|
|
|
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 %>
|
|
];
|
|
}
|