Do not generate token names for drop tokens

This commit is contained in:
Josh Holtrop 2021-06-26 16:16:18 -04:00
parent 61dd5bc5a0
commit 93cb25df62
2 changed files with 14 additions and 2 deletions

View File

@ -6,8 +6,10 @@ class <%= classname %>
{ {
enum enum
{ {
<% @grammar.tokens.each do |token| %> <% @grammar.tokens.each_with_index do |token, index| %>
TOKEN_<%= token.c_name %>, <% if token.name %>
TOKEN_<%= token.c_name %> = <%= index %>,
<% end %>
<% end %> <% end %>
} }

View File

@ -62,6 +62,16 @@ module Imbecile
state_table = [] state_table = []
states = enumerate states = enumerate
states.each do |state, id| states.each do |state, id|
accepts =
if state.accepts
if state.accepts.name
state.accepts.id
else
0xFFFFFFFE # drop token
end
else
0xFFFFFFFF # not an accepting state
end
state_table << { state_table << {
transition_table_index: transition_table.size, transition_table_index: transition_table.size,
n_transitions: state.transitions.size, n_transitions: state.transitions.size,