Show non-printable characters better in NFA#to_s

This commit is contained in:
Josh Holtrop 2021-05-21 14:39:02 -04:00
parent 952bffc33c
commit 3a1650906e

View File

@ -49,6 +49,13 @@ module Imbecile
end end
def to_s def to_s
chr = lambda do |value|
if value < 32 || value > 127
"{#{value}}"
else
value.chr
end
end
rv = "" rv = ""
states = {start_state => 0} states = {start_state => 0}
to_visit = [start_state] to_visit = [start_state]
@ -66,9 +73,9 @@ module Imbecile
if range.nil? if range.nil?
range_s = "nil" range_s = "nil"
else else
range_s = range.first.chr range_s = chr[range.first]
if range.size > 1 if range.size > 1
range_s += "-" + range.last.chr range_s += "-" + chr[range.last]
end end
end end
accepts_s = dest_state.accepts ? " *" : "" accepts_s = dest_state.accepts ? " *" : ""