1package c
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Chaiscript lexer.
9var Chaiscript = internal.Register(MustNewLexer(
10 &Config{
11 Name: "ChaiScript",
12 Aliases: []string{"chai", "chaiscript"},
13 Filenames: []string{"*.chai"},
14 MimeTypes: []string{"text/x-chaiscript", "application/x-chaiscript"},
15 DotAll: true,
16 },
17 Rules{
18 "commentsandwhitespace": {
19 {`\s+`, Text, nil},
20 {`//.*?\n`, CommentSingle, nil},
21 {`/\*.*?\*/`, CommentMultiline, nil},
22 {`^\#.*?\n`, CommentSingle, nil},
23 },
24 "slashstartsregex": {
25 Include("commentsandwhitespace"),
26 {`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
27 {`(?=/)`, Text, Push("#pop", "badregex")},
28 Default(Pop(1)),
29 },
30 "badregex": {
31 {`\n`, Text, Pop(1)},
32 },
33 "root": {
34 Include("commentsandwhitespace"),
35 {`\n`, Text, nil},
36 {`[^\S\n]+`, Text, nil},
37 {`\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?`, Operator, Push("slashstartsregex")},
38 {`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
39 {`[})\].]`, Punctuation, nil},
40 {`[=+\-*/]`, Operator, nil},
41 {`(for|in|while|do|break|return|continue|if|else|throw|try|catch)\b`, Keyword, Push("slashstartsregex")},
42 {`(var)\b`, KeywordDeclaration, Push("slashstartsregex")},
43 {`(attr|def|fun)\b`, KeywordReserved, nil},
44 {`(true|false)\b`, KeywordConstant, nil},
45 {`(eval|throw)\b`, NameBuiltin, nil},
46 {"`\\S+`", NameBuiltin, nil},
47 {`[$a-zA-Z_]\w*`, NameOther, nil},
48 {`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
49 {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
50 {`[0-9]+`, LiteralNumberInteger, nil},
51 {`"`, LiteralStringDouble, Push("dqstring")},
52 {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
53 },
54 "dqstring": {
55 {`\$\{[^"}]+?\}`, LiteralStringInterpol, nil},
56 {`\$`, LiteralStringDouble, nil},
57 {`\\\\`, LiteralStringDouble, nil},
58 {`\\"`, LiteralStringDouble, nil},
59 {`[^\\"$]+`, LiteralStringDouble, nil},
60 {`"`, LiteralStringDouble, Pop(1)},
61 },
62 },
63))