42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
|
import lex
|
||
|
|
||
|
class DiffGrammar(lex.Grammar):
|
||
|
GRAMMAR_LIST = [
|
||
|
{'name': "left",
|
||
|
'expr': "(?:^|(?<=\n))\-.*(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
{'name': "right",
|
||
|
'expr': "(?:^|(?<=\n))\+.*(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
#RCS file: /usr/local/cvsroot/TBB_v2/main_application/lib/TBB/EfileServer.pm,v
|
||
|
#retrieving revision 1.57
|
||
|
#diff -u -r1.57 EfileServer.pm
|
||
|
|
||
|
{'name': "cvs metadata",
|
||
|
'expr': "(?:^|(?<=\n))Index: .*\n={67}\nRCS file: .*,v\nretrieving revision [0-9.]+\ndiff -u .*(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
{'name': "svn metadata",
|
||
|
'expr': "(?:^|(?<=\n))Index: .*\n={67}(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
{'name': "location",
|
||
|
'expr': "(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
{'name': "common",
|
||
|
'expr': "(?:^|(?<=\n)).*(?:$|\n)",
|
||
|
'action': lex.make_token},
|
||
|
|
||
|
{'name': "default",
|
||
|
'expr': r'\\.|.|\n',
|
||
|
'action': lex.silent}
|
||
|
]
|
||
|
|
||
|
def _default_rules(self):
|
||
|
"""subclasses can override this to define defaults for a grammar"""
|
||
|
for rdir in DiffGrammar.GRAMMAR_LIST:
|
||
|
self.add_rule(**rdir)
|