1 package t
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Thrift = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Thrift",
12 Aliases: []string{"thrift"},
13 Filenames: []string{"*.thrift"},
14 MimeTypes: []string{"application/x-thrift"},
15 },
16 thriftRules,
17 ))
18
19 func thriftRules() Rules {
20 return Rules{
21 "root": {
22 Include("whitespace"),
23 Include("comments"),
24 {`"`, LiteralStringDouble, Combined("stringescape", "dqs")},
25 {`\'`, LiteralStringSingle, Combined("stringescape", "sqs")},
26 {`(namespace)(\s+)`, ByGroups(KeywordNamespace, TextWhitespace), Push("namespace")},
27 {`(enum|union|struct|service|exception)(\s+)`, ByGroups(KeywordDeclaration, TextWhitespace), Push("class")},
28 {`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
29 Include("keywords"),
30 Include("numbers"),
31 {`[&=]`, Operator, nil},
32 {`[:;,{}()<>\[\]]`, Punctuation, nil},
33 {`[a-zA-Z_](\.\w|\w)*`, Name, nil},
34 },
35 "whitespace": {
36 {`\n`, TextWhitespace, nil},
37 {`\s+`, TextWhitespace, nil},
38 },
39 "comments": {
40 {`#.*$`, Comment, nil},
41 {`//.*?\n`, Comment, nil},
42 {`/\*[\w\W]*?\*/`, CommentMultiline, nil},
43 },
44 "stringescape": {
45 {`\\([\\nrt"\'])`, LiteralStringEscape, nil},
46 },
47 "dqs": {
48 {`"`, LiteralStringDouble, Pop(1)},
49 {`[^\\"\n]+`, LiteralStringDouble, nil},
50 },
51 "sqs": {
52 {`'`, LiteralStringSingle, Pop(1)},
53 {`[^\\\'\n]+`, LiteralStringSingle, nil},
54 },
55 "namespace": {
56 {`[a-z*](\.\w|\w)*`, NameNamespace, Pop(1)},
57 Default(Pop(1)),
58 },
59 "class": {
60 {`[a-zA-Z_]\w*`, NameClass, Pop(1)},
61 Default(Pop(1)),
62 },
63 "keywords": {
64 {`(async|oneway|extends|throws|required|optional)\b`, Keyword, nil},
65 {`(true|false)\b`, KeywordConstant, nil},
66 {`(const|typedef)\b`, KeywordDeclaration, nil},
67 {Words(``, `\b`, `cpp_namespace`, `cpp_include`, `cpp_type`, `java_package`, `cocoa_prefix`, `csharp_namespace`, `delphi_namespace`, `php_namespace`, `py_module`, `perl_package`, `ruby_namespace`, `smalltalk_category`, `smalltalk_prefix`, `xsd_all`, `xsd_optional`, `xsd_nillable`, `xsd_namespace`, `xsd_attrs`, `include`), KeywordNamespace, nil},
68 {Words(``, `\b`, `void`, `bool`, `byte`, `i16`, `i32`, `i64`, `double`, `string`, `binary`, `map`, `list`, `set`, `slist`, `senum`), KeywordType, nil},
69 {Words(`\b`, `\b`, `BEGIN`, `END`, `__CLASS__`, `__DIR__`, `__FILE__`, `__FUNCTION__`, `__LINE__`, `__METHOD__`, `__NAMESPACE__`, `abstract`, `alias`, `and`, `args`, `as`, `assert`, `begin`, `break`, `case`, `catch`, `class`, `clone`, `continue`, `declare`, `def`, `default`, `del`, `delete`, `do`, `dynamic`, `elif`, `else`, `elseif`, `elsif`, `end`, `enddeclare`, `endfor`, `endforeach`, `endif`, `endswitch`, `endwhile`, `ensure`, `except`, `exec`, `finally`, `float`, `for`, `foreach`, `function`, `global`, `goto`, `if`, `implements`, `import`, `in`, `inline`, `instanceof`, `interface`, `is`, `lambda`, `module`, `native`, `new`, `next`, `nil`, `not`, `or`, `pass`, `public`, `print`, `private`, `protected`, `raise`, `redo`, `rescue`, `retry`, `register`, `return`, `self`, `sizeof`, `static`, `super`, `switch`, `synchronized`, `then`, `this`, `throw`, `transient`, `try`, `undef`, `unless`, `unsigned`, `until`, `use`, `var`, `virtual`, `volatile`, `when`, `while`, `with`, `xor`, `yield`), KeywordReserved, nil},
70 },
71 "numbers": {
72 {`[+-]?(\d+\.\d+([eE][+-]?\d+)?|\.?\d+[eE][+-]?\d+)`, LiteralNumberFloat, nil},
73 {`[+-]?0x[0-9A-Fa-f]+`, LiteralNumberHex, nil},
74 {`[+-]?[0-9]+`, LiteralNumberInteger, nil},
75 },
76 }
77 }
78
View as plain text