1package r
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Ragel lexer.
9var Ragel = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Ragel",
12 Aliases: []string{"ragel"},
13 Filenames: []string{},
14 MimeTypes: []string{},
15 },
16 Rules{
17 "whitespace": {
18 {`\s+`, TextWhitespace, nil},
19 },
20 "comments": {
21 {`\#.*$`, Comment, nil},
22 },
23 "keywords": {
24 {`(access|action|alphtype)\b`, Keyword, nil},
25 {`(getkey|write|machine|include)\b`, Keyword, nil},
26 {`(any|ascii|extend|alpha|digit|alnum|lower|upper)\b`, Keyword, nil},
27 {`(xdigit|cntrl|graph|print|punct|space|zlen|empty)\b`, Keyword, nil},
28 },
29 "numbers": {
30 {`0x[0-9A-Fa-f]+`, LiteralNumberHex, nil},
31 {`[+-]?[0-9]+`, LiteralNumberInteger, nil},
32 },
33 "literals": {
34 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
35 {`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
36 {`\[(\\\\|\\\]|[^\]])*\]`, LiteralString, nil},
37 {`/(?!\*)(\\\\|\\/|[^/])*/`, LiteralStringRegex, nil},
38 },
39 "identifiers": {
40 {`[a-zA-Z_]\w*`, NameVariable, nil},
41 },
42 "operators": {
43 {`,`, Operator, nil},
44 {`\||&|--?`, Operator, nil},
45 {`\.|<:|:>>?`, Operator, nil},
46 {`:`, Operator, nil},
47 {`->`, Operator, nil},
48 {`(>|\$|%|<|@|<>)(/|eof\b)`, Operator, nil},
49 {`(>|\$|%|<|@|<>)(!|err\b)`, Operator, nil},
50 {`(>|\$|%|<|@|<>)(\^|lerr\b)`, Operator, nil},
51 {`(>|\$|%|<|@|<>)(~|to\b)`, Operator, nil},
52 {`(>|\$|%|<|@|<>)(\*|from\b)`, Operator, nil},
53 {`>|@|\$|%`, Operator, nil},
54 {`\*|\?|\+|\{[0-9]*,[0-9]*\}`, Operator, nil},
55 {`!|\^`, Operator, nil},
56 {`\(|\)`, Operator, nil},
57 },
58 "root": {
59 Include("literals"),
60 Include("whitespace"),
61 Include("comments"),
62 Include("keywords"),
63 Include("numbers"),
64 Include("identifiers"),
65 Include("operators"),
66 {`\{`, Punctuation, Push("host")},
67 {`=`, Operator, nil},
68 {`;`, Punctuation, nil},
69 },
70 "host": {
71 {`([^{}\'"/#]+|[^\\]\\[{}]|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|\#.*$\n?|/(?!\*)(\\\\|\\/|[^/])*/|/)+`, Other, nil},
72 {`\{`, Punctuation, Push()},
73 {`\}`, Punctuation, Pop(1)},
74 },
75 },
76))