import string import color, mode2 from lex3 import Grammar, PatternRule, RegionRule class HexGrammar(Grammar): rules = [ PatternRule(r'zero', r"00"), PatternRule(r'printable', r"[2-7][0-9a-f]"), PatternRule(r'byte', r'[0-f][0-f]'), ] class Hex(mode2.Fundamental): grammar = HexGrammar colors = { 'zero': ('magenta', 'default'), 'printable': ('green', 'default'), 'byte': ('white', 'default'), } def __init__(self, w): mode2.Fundamental.__init__(self, w) # create all the insert actions for the basic text input for c in string.letters + string.digits + string.punctuation: if c in string.hexdigits: self.add_binding('overwrite-char-%s' % c.lower(), c) else: self.del_binding(c) def name(self): return "Hex"