pmacs3/mode/hex.py

31 lines
885 B
Python
Raw Normal View History

2007-10-12 22:58:17 -04:00
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)
2007-10-12 22:58:17 -04:00
# 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"