from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, PatternMatchRule class DiffGrammar(Grammar): rules = [ PatternRule('diff.left', r"^\-.*\n$"), PatternRule('diff.right', r"^\+.*\n$"), PatternRule('diff.metadata', r'^[A-Za-z].*\n$'), PatternRule('diff.seperator', r'^={67}\n$'), PatternRule('diff.location', r"^@@ [-+0-9a-z, ]* @@\n$"), PatternRule('diff.common', r"^.*\n$"), ] class Diff(Fundamental): name = 'diff' extensions = ['.patch', '.diff', '.rej'] grammar = DiffGrammar() colors = { 'diff.left': ('red', 'default', 'bold'), 'diff.right': ('blue', 'default', 'bold'), 'diff.seperator': ('magenta', 'default', 'bold'), 'diff.metadata': ('magenta', 'default', 'bold'), 'diff.location': ('magenta', 'default', 'bold'), } class Diff3Line(Grammar): rules = [PatternMatchRule('x', r'^( )(.*)\n$', 'pre', 'data')] class Diff3Grammar(Grammar): rules = [ PatternRule('diff.seperator', r'^====\n$'), RegionRule('diff.part1', r"^1:\d+,\d+[a-z]\n$", Diff3Line, '^(?=[^ ])'), RegionRule('diff.part2', r"^2:\d+,\d+[a-z]\n$", Diff3Line, '^(?=[^ ])'), RegionRule('diff.part3', r"^3:\d+,\d+[a-z]\n$", Diff3Line, '^(?=[^ ])'), PatternRule('diff.common', r"^.*\n$"), ] class Diff3(Fundamental): name = 'diff3' extensions = ['.diff3'] grammar = Diff3Grammar() colors = { 'diff.part1.start': ('yellow', 'default', 'bold'), 'diff.part1.pre': ('default', 'red', 'bold'), 'diff.part2.start': ('yellow', 'default', 'bold'), 'diff.part2.pre': ('default', 'green', 'bold'), 'diff.part3.start': ('yellow', 'default', 'bold'), 'diff.part3.pre': ('default', 'blue', 'bold'), } def install(*args, **kwargs): Diff.install(*args, **kwargs) Diff3.install(*args, **kwargs)