Add some token constants
This commit is contained in:
parent
aae7bc188c
commit
4beb3d2016
@ -17,6 +17,15 @@ require_relative "imbecile/version"
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -63,19 +63,17 @@ module Imbecile
|
||||
states = enumerate
|
||||
states.each do |state, id|
|
||||
accepts =
|
||||
if state.accepts
|
||||
if state.accepts.name
|
||||
state.accepts.id
|
||||
else
|
||||
0xFFFFFFFE # drop token
|
||||
end
|
||||
if state.accepts.nil?
|
||||
TOKEN_NONE
|
||||
elsif state.accepts.name
|
||||
state.accepts.id
|
||||
else
|
||||
0xFFFFFFFF # not an accepting state
|
||||
TOKEN_DROP
|
||||
end
|
||||
state_table << {
|
||||
transition_table_index: transition_table.size,
|
||||
n_transitions: state.transitions.size,
|
||||
accepts: state.accepts ? state.accepts.id : 0xFFFFFFFF,
|
||||
accepts: accepts,
|
||||
}
|
||||
state.transitions.each do |transition|
|
||||
transition_table << {
|
||||
|
Loading…
x
Reference in New Issue
Block a user