2007-06-13 22:38:46 -04:00
|
|
|
import lex, lex_text
|
2007-03-06 10:05:38 -05:00
|
|
|
|
|
|
|
class MuttGrammar(lex.Grammar):
|
|
|
|
GRAMMAR_LIST = [
|
|
|
|
{'name': 'header',
|
|
|
|
'expr': r'(?:^|(?<=\n))(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'quote1',
|
|
|
|
'expr': r'(?:^|(?<=\n))(?:(?: *>){3})*(?: *>){1} *(?:[^ >\n][^\n]*)?(?:$|\n)',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'quote2',
|
|
|
|
'expr': r'(?:^|(?<=\n))(?:(?: *>){3})*(?: *>){2} *(?:[^ >\n][^\n]*)?(?:$|\n)',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'quote3',
|
|
|
|
'expr': r'(?:^|(?<=\n))(?:(?: *>){3})*(?: *>){3} *(?:[^ >\n][^\n]*)?(?:$|\n)',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'email',
|
|
|
|
'expr': r'(?:^|(?<=[ :\n]))<?[^<>@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'url',
|
|
|
|
'expr': r'(?:^|(?<=[ \n]))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+',
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'continued word',
|
|
|
|
'expr': r"""([a-zA-Z][a-zA-Z-']*[a-zA-Z])-\n *([a-zA-Z][a-zA-Z-]*[a-zA-Z])""",
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex_text.make_token_spell,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'word',
|
|
|
|
'expr': r"""(?:[a-zA-Z][-']?)*[a-zA-Z]""",
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex_text.make_token_spell,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'name': 'stuff',
|
|
|
|
'expr': r"""[^ \n]+""",
|
2007-06-13 22:38:46 -04:00
|
|
|
'action': lex.make_token,
|
2007-03-06 10:05:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
{'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 self.GRAMMAR_LIST:
|
|
|
|
self.add_rule(**rdir)
|