Skip to content

Instantly share code, notes, and snippets.

@malthe
Created April 12, 2010 07:03
Show Gist options
  • Save malthe/363342 to your computer and use it in GitHub Desktop.
Save malthe/363342 to your computer and use it in GitHub Desktop.
class RapidSMSLexer(RegexLexer):
"""
Lexer for RapidSMS text messages.
"""
name = 'RapidSMS'
aliases = ['sms']
filenames = []
mimetypes = ['application/x-rapidsms']
flags = re.MULTILINE | re.IGNORECASE
tokens = {
'root': [
(r'^>>>\s*', Generic.Prompt),
(r'^<<<\s*', Generic.Prompt),
(r'\+\w+\s*', Name.Label),
include('basic'),
(r'.', Text),
],
'basic': [
(r'".*?"', String.Double),
(r"'.*?'", String.Single),
(r'`.*?`', String.Backtick),
(r'-?\d+', Number),
(r',', Punctuation),
(r'=', Operator),
(r'/\S+', Name),
(r':\w+', Name.Label),
(r'\w:\w+', Text),
(r'([<>|])(\s*)(\w+)', bygroups(Punctuation, Text, Name)),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment