Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created December 23, 2008 20:26
Show Gist options
  • Save ngerakines/39440 to your computer and use it in GitHub Desktop.
Save ngerakines/39440 to your computer and use it in GitHub Desktop.
class PBLexer(RegexLexer):
"""
A simple Protocol Buffer lexer useful for parsing .proto files.
Contributed by Nick Gerakines <[email protected]>.
"""
name = 'ProtocolBuffers'
aliases = ['pb']
filenames = ['*.proto']
mimetypes = ['text/pb']
tokens = {
'root': [
(r'(message)(\s+)(\w+)', bygroups(Keyword.Reserved, Text.Whitespace, Name.Class)),
(r'(required|optional|repeated)', Keyword.Reserved),
(r'(string|int32)', Keyword.Type),
(r'({|})', Punctuation),
(r'([^ ]*)(\s+)(=)(\s+)(\d+);', bygroups(Name.Label, Text.Whitespace, Punctuation, Text.Whitespace, Number.Integer)),
(r'=', Operator),
(r';', Operator),
(r'//.*?$', Comment),
(r'[0-9]+', Number.Integer),
(r'\s+', Text.Whitespace),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment