1 package p
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var ProtocolBuffer = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Protocol Buffer",
12 Aliases: []string{"protobuf", "proto"},
13 Filenames: []string{"*.proto"},
14 MimeTypes: []string{},
15 },
16 protocolBufferRules,
17 ))
18
19 func protocolBufferRules() Rules {
20 return Rules{
21 "root": {
22 {`[ \t]+`, Text, nil},
23 {`[,;{}\[\]()<>]`, Punctuation, nil},
24 {`/(\\\n)?/(\n|(.|\n)*?[^\\]\n)`, CommentSingle, nil},
25 {`/(\\\n)?\*(.|\n)*?\*(\\\n)?/`, CommentMultiline, nil},
26 {Words(`\b`, `\b`, `import`, `option`, `optional`, `required`, `repeated`, `default`, `packed`, `ctype`, `extensions`, `to`, `max`, `rpc`, `returns`, `oneof`), Keyword, nil},
27 {Words(``, `\b`, `int32`, `int64`, `uint32`, `uint64`, `sint32`, `sint64`, `fixed32`, `fixed64`, `sfixed32`, `sfixed64`, `float`, `double`, `bool`, `string`, `bytes`), KeywordType, nil},
28 {`(true|false)\b`, KeywordConstant, nil},
29 {`(package)(\s+)`, ByGroups(KeywordNamespace, Text), Push("package")},
30 {`(message|extend)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("message")},
31 {`(enum|group|service)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("type")},
32 {`\".*?\"`, LiteralString, nil},
33 {`\'.*?\'`, LiteralString, nil},
34 {`(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*`, LiteralNumberFloat, nil},
35 {`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil},
36 {`(\-?(inf|nan))\b`, LiteralNumberFloat, nil},
37 {`0x[0-9a-fA-F]+[LlUu]*`, LiteralNumberHex, nil},
38 {`0[0-7]+[LlUu]*`, LiteralNumberOct, nil},
39 {`\d+[LlUu]*`, LiteralNumberInteger, nil},
40 {`[+-=]`, Operator, nil},
41 {`([a-zA-Z_][\w.]*)([ \t]*)(=)`, ByGroups(Name, Text, Operator), nil},
42 {`[a-zA-Z_][\w.]*`, Name, nil},
43 },
44 "package": {
45 {`[a-zA-Z_]\w*`, NameNamespace, Pop(1)},
46 Default(Pop(1)),
47 },
48 "message": {
49 {`[a-zA-Z_]\w*`, NameClass, Pop(1)},
50 Default(Pop(1)),
51 },
52 "type": {
53 {`[a-zA-Z_]\w*`, Name, Pop(1)},
54 Default(Pop(1)),
55 },
56 }
57 }
58
View as plain text