1package t
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Thrift lexer.
 9var Thrift = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "Thrift",
12		Aliases:   []string{"thrift"},
13		Filenames: []string{"*.thrift"},
14		MimeTypes: []string{"application/x-thrift"},
15	},
16	Rules{
17		"root": {
18			Include("whitespace"),
19			Include("comments"),
20			{`"`, LiteralStringDouble, Combined("stringescape", "dqs")},
21			{`\'`, LiteralStringSingle, Combined("stringescape", "sqs")},
22			{`(namespace)(\s+)`, ByGroups(KeywordNamespace, TextWhitespace), Push("namespace")},
23			{`(enum|union|struct|service|exception)(\s+)`, ByGroups(KeywordDeclaration, TextWhitespace), Push("class")},
24			{`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
25			Include("keywords"),
26			Include("numbers"),
27			{`[&=]`, Operator, nil},
28			{`[:;,{}()<>\[\]]`, Punctuation, nil},
29			{`[a-zA-Z_](\.\w|\w)*`, Name, nil},
30		},
31		"whitespace": {
32			{`\n`, TextWhitespace, nil},
33			{`\s+`, TextWhitespace, nil},
34		},
35		"comments": {
36			{`#.*$`, Comment, nil},
37			{`//.*?\n`, Comment, nil},
38			{`/\*[\w\W]*?\*/`, CommentMultiline, nil},
39		},
40		"stringescape": {
41			{`\\([\\nrt"\'])`, LiteralStringEscape, nil},
42		},
43		"dqs": {
44			{`"`, LiteralStringDouble, Pop(1)},
45			{`[^\\"\n]+`, LiteralStringDouble, nil},
46		},
47		"sqs": {
48			{`'`, LiteralStringSingle, Pop(1)},
49			{`[^\\\'\n]+`, LiteralStringSingle, nil},
50		},
51		"namespace": {
52			{`[a-z*](\.\w|\w)*`, NameNamespace, Pop(1)},
53			Default(Pop(1)),
54		},
55		"class": {
56			{`[a-zA-Z_]\w*`, NameClass, Pop(1)},
57			Default(Pop(1)),
58		},
59		"keywords": {
60			{`(async|oneway|extends|throws|required|optional)\b`, Keyword, nil},
61			{`(true|false)\b`, KeywordConstant, nil},
62			{`(const|typedef)\b`, KeywordDeclaration, nil},
63			{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},
64			{Words(``, `\b`, `void`, `bool`, `byte`, `i16`, `i32`, `i64`, `double`, `string`, `binary`, `map`, `list`, `set`, `slist`, `senum`), KeywordType, nil},
65			{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},
66		},
67		"numbers": {
68			{`[+-]?(\d+\.\d+([eE][+-]?\d+)?|\.?\d+[eE][+-]?\d+)`, LiteralNumberFloat, nil},
69			{`[+-]?0x[0-9A-Fa-f]+`, LiteralNumberHex, nil},
70			{`[+-]?[0-9]+`, LiteralNumberInteger, nil},
71		},
72	},
73))