Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Last active August 29, 2015 13:57
Show Gist options
  • Save IlanFrumer/9358414 to your computer and use it in GitHub Desktop.
Save IlanFrumer/9358414 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>proto</string>
</array>
<key>keyEquivalent</key>
<string>^~P</string>
<key>name</key>
<string>Protocol Buffers</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\b(default|enum|extend|extensions|message|option|package|rpc|returns|service)\b</string>
<key>name</key>
<string>keyword.operator.proto</string>
</dict>
<dict>
<key>begin</key>
<string>//</string>
<key>end</key>
<string>$</string>
<key>name</key>
<string>comment.line.double-slash.proto</string>
</dict>
<dict>
<key>begin</key>
<string>"</string>
<key>end</key>
<string>"</string>
<key>name</key>
<string>string.quoted.double.proto</string>
</dict>
<dict>
<key>match</key>
<string>\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\b</string>
<key>name</key>
<string>storage.type.proto</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.proto</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.type.proto</string>
</dict>
</dict>
<key>match</key>
<string>\b(repeated|required|optional)\s+(\w+)\b</string>
</dict>
<dict>
<key>match</key>
<string>^(import)\s</string>
<key>name</key>
<string>keyword.control.import.proto</string>
</dict>
<dict>
<key>match</key>
<string>\b((([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|F|f)?\b</string>
<key>name</key>
<string>constant.numeric.proto</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.function.proto</string>
</dict>
</dict>
<key>match</key>
<string>\b([a-zA-Z0-9_\.]*?)\(</string>
</dict>
<dict>
<key>begin</key>
<string>/\*</string>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.proto</string>
</dict>
</dict>
<key>end</key>
<string>\*/</string>
<key>name</key>
<string>comment.block.proto</string>
</dict>
<dict>
<key>begin</key>
<string>//</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.proto</string>
</dict>
</dict>
<key>end</key>
<string>$\n?</string>
<key>name</key>
<string>comment.line.double-slash.proto</string>
</dict>
</array>
<key>scopeName</key>
<string>source.proto</string>
<key>uuid</key>
<string>D6B0BFD2-F416-4E91-8C53-CD71EA3EE951</string>
</dict>
</plist>
{
"fileTypes": [
"proto"
],
"keyEquivalent": "^~P",
"name": "Protocol Buffers",
"patterns": [
{
"match": "\\b(default|enum|extend|extensions|message|option|package|rpc|returns|service)\\b",
"name": "keyword.operator.proto"
},
{
"begin": "//",
"end": "$",
"name": "comment.line.double-slash.proto"
},
{
"begin": "\"",
"end": "\"",
"name": "string.quoted.double.proto"
},
{
"match": "\\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\\b",
"name": "storage.type.proto"
},
{
"captures": {
"1": {
"name": "keyword.operator.proto"
},
"2": {
"name": "storage.type.proto"
}
},
"match": "\\b(repeated|required|optional)\\s+(\\w+)\\b"
},
{
"match": "^(import)\\s",
"name": "keyword.control.import.proto"
},
{
"match": "\\b((([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(L|l|F|f)?\\b",
"name": "constant.numeric.proto"
},
{
"captures": {
"1": {
"name": "entity.name.function.proto"
}
},
"match": "\\b([a-zA-Z0-9_\\.]*?)\\("
},
{
"begin": "/\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.proto"
}
},
"end": "\\*/",
"name": "comment.block.proto"
},
{
"begin": "//",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.proto"
}
},
"end": "$\\n?",
"name": "comment.line.double-slash.proto"
}
],
"scopeName": "source.proto",
"uuid": "D6B0BFD2-F416-4E91-8C53-CD71EA3EE951"
}
@IlanFrumer
Copy link
Author

Resources

Language Grammars & list of all scopes ( nested ):

http://manual.macromates.com/en/language_grammars#naming_conventions

Sublime plugin which convert between plist <-> json

https://github.com/facelessuser/SerializedDataConverter

Sublime Text uses Oniguruma‘s syntax for regular expressions in syntax definitions:

http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

Syntax Definitions: Sublime docs:

http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html?highlight=syntax


How Syntax Definitions Work

At their core, syntax definitions are arrays of regular expressions paired with scope names. Sublime Text will try to match these patterns against a buffer’s text and attach the corresponding scope name to all occurrences. These pairs of regular expressions and scope names are known as rules.

Rules are applied in order, one line at a time. Each rule consumes the matched text region, which therefore will be excluded from the next rule’s matching attempt (save for a few exceptions). In practical terms, this means that you should take care to go from more specific rules to more general ones when you create a new syntax definition. Otherwise, a greedy regular expression might swallow parts you’d like to have styled differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment