1 package r
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Reasonml = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "ReasonML",
12 Aliases: []string{"reason", "reasonml"},
13 Filenames: []string{"*.re", "*.rei"},
14 MimeTypes: []string{"text/x-reasonml"},
15 },
16 reasonmlRules,
17 ))
18
19 func reasonmlRules() Rules {
20 return Rules{
21 "escape-sequence": {
22 {`\\[\\"\'ntbr]`, LiteralStringEscape, nil},
23 {`\\[0-9]{3}`, LiteralStringEscape, nil},
24 {`\\x[0-9a-fA-F]{2}`, LiteralStringEscape, nil},
25 },
26 "root": {
27 {`\s+`, Text, nil},
28 {`false|true|\(\)|\[\]`, NameBuiltinPseudo, nil},
29 {`\b([A-Z][\w\']*)(?=\s*\.)`, NameNamespace, Push("dotted")},
30 {`\b([A-Z][\w\']*)`, NameClass, nil},
31 {`//.*?\n`, CommentSingle, nil},
32 {`\/\*(?![\/])`, CommentMultiline, Push("comment")},
33 {`\b(as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|false|for|fun|esfun|function|functor|if|in|include|inherit|initializer|lazy|let|switch|module|pub|mutable|new|nonrec|object|of|open|pri|rec|sig|struct|then|to|true|try|type|val|virtual|when|while|with)\b`, Keyword, nil},
34 {"(~|\\}|\\|]|\\||\\|\\||\\{<|\\{|`|_|]|\\[\\||\\[>|\\[<|\\[|\\?\\?|\\?|>\\}|>]|>|=|<-|<|;;|;|:>|:=|::|:|\\.\\.\\.|\\.\\.|\\.|=>|-\\.|-|,|\\+|\\*|\\)|\\(|&&|&|#|!=)", OperatorWord, nil},
35 {`([=<>@^|&+\*/$%-]|[!?~])?[!$%&*+\./:<=>?@^|~-]`, Operator, nil},
36 {`\b(and|asr|land|lor|lsl|lsr|lxor|mod|or)\b`, OperatorWord, nil},
37 {`\b(unit|int|float|bool|string|char|list|array)\b`, KeywordType, nil},
38 {`[^\W\d][\w']*`, Name, nil},
39 {`-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)`, LiteralNumberFloat, nil},
40 {`0[xX][\da-fA-F][\da-fA-F_]*`, LiteralNumberHex, nil},
41 {`0[oO][0-7][0-7_]*`, LiteralNumberOct, nil},
42 {`0[bB][01][01_]*`, LiteralNumberBin, nil},
43 {`\d[\d_]*`, LiteralNumberInteger, nil},
44 {`'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'`, LiteralStringChar, nil},
45 {`'.'`, LiteralStringChar, nil},
46 {`'`, Keyword, nil},
47 {`"`, LiteralStringDouble, Push("string")},
48 {`[~?][a-z][\w\']*:`, NameVariable, nil},
49 },
50 "comment": {
51 {`[^\/*]+`, CommentMultiline, nil},
52 {`\/\*`, CommentMultiline, Push()},
53 {`\*\/`, CommentMultiline, Pop(1)},
54 {`[\*]`, CommentMultiline, nil},
55 },
56 "string": {
57 {`[^\\"]+`, LiteralStringDouble, nil},
58 Include("escape-sequence"),
59 {`\\\n`, LiteralStringDouble, nil},
60 {`"`, LiteralStringDouble, Pop(1)},
61 },
62 "dotted": {
63 {`\s+`, Text, nil},
64 {`\.`, Punctuation, nil},
65 {`[A-Z][\w\']*(?=\s*\.)`, NameNamespace, nil},
66 {`[A-Z][\w\']*`, NameClass, Pop(1)},
67 {`[a-z_][\w\']*`, Name, Pop(1)},
68 Default(Pop(1)),
69 },
70 }
71 }
72
View as plain text