1 | package lexers
|
---|
2 |
|
---|
3 | import (
|
---|
4 | . "github.com/alecthomas/chroma/v2" // nolint
|
---|
5 | )
|
---|
6 |
|
---|
7 | // Chapel lexer.
|
---|
8 | var Chapel = Register(MustNewLexer(
|
---|
9 | &Config{
|
---|
10 | Name: "Chapel",
|
---|
11 | Aliases: []string{"chapel", "chpl"},
|
---|
12 | Filenames: []string{"*.chpl"},
|
---|
13 | MimeTypes: []string{},
|
---|
14 | },
|
---|
15 | func() Rules {
|
---|
16 | return Rules{
|
---|
17 | "root": {
|
---|
18 | {`\n`, TextWhitespace, nil},
|
---|
19 | {`\s+`, TextWhitespace, nil},
|
---|
20 | {`\\\n`, Text, nil},
|
---|
21 | {`//(.*?)\n`, CommentSingle, nil},
|
---|
22 | {`/(\\\n)?[*](.|\n)*?[*](\\\n)?/`, CommentMultiline, nil},
|
---|
23 | {Words(``, `\b`, `config`, `const`, `in`, `inout`, `out`, `param`, `ref`, `type`, `var`), KeywordDeclaration, nil},
|
---|
24 | {Words(``, `\b`, `false`, `nil`, `none`, `true`), KeywordConstant, nil},
|
---|
25 | {Words(``, `\b`, `bool`, `bytes`, `complex`, `imag`, `int`, `locale`, `nothing`, `opaque`, `range`, `real`, `string`, `uint`, `void`), KeywordType, nil},
|
---|
26 | {Words(``, `\b`, `atomic`, `single`, `sync`, `borrowed`, `owned`, `shared`, `unmanaged`, `align`, `as`, `begin`, `break`, `by`, `catch`, `cobegin`, `coforall`, `continue`, `defer`, `delete`, `dmapped`, `do`, `domain`, `else`, `enum`, `except`, `export`, `extern`, `for`, `forall`, `foreach`, `forwarding`, `if`, `implements`, `import`, `index`, `init`, `inline`, `label`, `lambda`, `let`, `lifetime`, `local`, `new`, `noinit`, `on`, `only`, `otherwise`, `override`, `pragma`, `primitive`, `private`, `prototype`, `public`, `reduce`, `require`, `return`, `scan`, `select`, `serial`, `sparse`, `subdomain`, `then`, `this`, `throw`, `throws`, `try`, `use`, `when`, `where`, `while`, `with`, `yield`, `zip`), Keyword, nil},
|
---|
27 | {`(iter)(\s+)`, ByGroups(Keyword, TextWhitespace), Push("procname")},
|
---|
28 | {`(proc)(\s+)`, ByGroups(Keyword, TextWhitespace), Push("procname")},
|
---|
29 | {`(operator)(\s+)`, ByGroups(Keyword, TextWhitespace), Push("procname")},
|
---|
30 | {`(class|interface|module|record|union)(\s+)`, ByGroups(Keyword, TextWhitespace), Push("classname")},
|
---|
31 | {`\d+i`, LiteralNumber, nil},
|
---|
32 | {`\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil},
|
---|
33 | {`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil},
|
---|
34 | {`\d+[Ee][-+]\d+i`, LiteralNumber, nil},
|
---|
35 | {`(\d*\.\d+)([eE][+-]?[0-9]+)?i?`, LiteralNumberFloat, nil},
|
---|
36 | {`\d+[eE][+-]?[0-9]+i?`, LiteralNumberFloat, nil},
|
---|
37 | {`0[bB][01]+`, LiteralNumberBin, nil},
|
---|
38 | {`0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil},
|
---|
39 | {`0[oO][0-7]+`, LiteralNumberOct, nil},
|
---|
40 | {`[0-9]+`, LiteralNumberInteger, nil},
|
---|
41 | {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
|
---|
42 | {`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
|
---|
43 | {`(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|<=>|<~>|\.\.|by|#|\.\.\.|&&|\|\||!|&|\||\^|~|<<|>>|==|!=|<=|>=|<|>|[+\-*/%]|\*\*)`, Operator, nil},
|
---|
44 | {`[:;,.?()\[\]{}]`, Punctuation, nil},
|
---|
45 | {`[a-zA-Z_][\w$]*`, NameOther, nil},
|
---|
46 | },
|
---|
47 | "classname": {
|
---|
48 | {`[a-zA-Z_][\w$]*`, NameClass, Pop(1)},
|
---|
49 | },
|
---|
50 | "procname": {
|
---|
51 | {`([a-zA-Z_][.\w$]*|\~[a-zA-Z_][.\w$]*|[+*/!~%<>=&^|\-:]{1,2})`, NameFunction, Pop(1)},
|
---|
52 | {`\(`, Punctuation, Push("receivertype")},
|
---|
53 | {`\)+\.`, Punctuation, nil},
|
---|
54 | },
|
---|
55 | "receivertype": {
|
---|
56 | {Words(``, `\b`, `atomic`, `single`, `sync`, `borrowed`, `owned`, `shared`, `unmanaged`), Keyword, nil},
|
---|
57 | {Words(``, `\b`, `bool`, `bytes`, `complex`, `imag`, `int`, `locale`, `nothing`, `opaque`, `range`, `real`, `string`, `uint`, `void`), KeywordType, nil},
|
---|
58 | {`[^()]*`, NameOther, Pop(1)},
|
---|
59 | },
|
---|
60 | }
|
---|
61 | },
|
---|
62 | ))
|
---|