import color, method, mode, re
from lex import Grammar, PatternRule, RegionRule

class DiffGrammar(Grammar):
    rules = [
        PatternRule(name=r'left', pattern=r"^\-.*\n$"),
        PatternRule(name=r'right', pattern=r"^\+.*\n$"),
        PatternRule(name=r'metadata', pattern=r'^[A-Za-z].*\n$'),
        PatternRule(name=r'seperator', pattern=r'^={67}\n$'),
        PatternRule(name=r'location', pattern=r"^@@ [-+0-9a-z, ]* @@\n$"),
        PatternRule(name=r'common', pattern=r"^.*\n$"),
    ]

class Diff(mode.Fundamental):
    modename = 'diff'
    extensions  = ['.patch', '.diff']
    grammar = DiffGrammar()
    colors = {
        'left':      ('red', 'default', 'bold'),
        'right':     ('blue', 'default', 'bold'),
        'seperator': ('magenta', 'default', 'bold'),
        'metadata':  ('magenta', 'default', 'bold'),
        'location':  ('magenta', 'default', 'bold'),
    }

install = Diff.install