Add some token constants

This commit is contained in:
josh committed 2021-06-27 23:09:42 -04:00
1 parent aae7bc188c
commit 4beb3d2016
2 files changed
+14 -7

No files matched your search

+9
View File
@@ -17,6 +17,15 @@ require_relative "imbecile/version"
module Imbecile module Imbecile
# Decoding error.
TOKEN_DECODE_ERROR = 0xFFFFFFFD
# Token ID for a "dropped" token.
TOKEN_DROP = 0xFFFFFFFE
# Invalid token ID.
TOKEN_NONE = 0xFFFFFFFF
class Error < RuntimeError class Error < RuntimeError
end end
+5 -7
View File
@@ -63,19 +63,17 @@ module Imbecile
states = enumerate states = enumerate
states.each do |state, id| states.each do |state, id|
accepts = accepts =
if state.accepts if state.accepts.nil?
if state.accepts.name TOKEN_NONE
elsif state.accepts.name
state.accepts.id state.accepts.id
else else
0xFFFFFFFE # drop token TOKEN_DROP
end
else
0xFFFFFFFF # not an accepting state
end 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,
accepts: state.accepts ? state.accepts.id : 0xFFFFFFFF, accepts: accepts,
} }
state.transitions.each do |transition| state.transitions.each do |transition|
transition_table << { transition_table << {