1 package y
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8 var YAML = internal.Register(MustNewLazyLexer(
9 &Config{
10 Name: "YAML",
11 Aliases: []string{"yaml"},
12 Filenames: []string{"*.yaml", "*.yml"},
13 MimeTypes: []string{"text/x-yaml"},
14 },
15 yamlRules,
16 ))
17
18 func yamlRules() Rules {
19 return Rules{
20 "root": {
21 Include("whitespace"),
22 {`^---`, NameNamespace, nil},
23 {`^\.\.\.`, NameNamespace, nil},
24 {`[\n?]?\s*- `, Text, nil},
25 {`#.*$`, Comment, nil},
26 {`!![^\s]+`, CommentPreproc, nil},
27 {`&[^\s]+`, CommentPreproc, nil},
28 {`\*[^\s]+`, CommentPreproc, nil},
29 {`^%include\s+[^\n\r]+`, CommentPreproc, nil},
30 Include("key"),
31 Include("value"),
32 {`[?:,\[\]]`, Punctuation, nil},
33 {`.`, Text, nil},
34 },
35 "value": {
36 {`([>|](?:[+-])?)(\n(^ {1,})(?:.*\n*(?:^\3 *).*)*)`, ByGroups(Punctuation, StringDoc, Whitespace), nil},
37 {Words(``, `\b`, "true", "True", "TRUE", "false", "False", "FALSE", "null",
38 "y", "Y", "yes", "Yes", "YES", "n", "N", "no", "No", "NO",
39 "on", "On", "ON", "off", "Off", "OFF"), KeywordConstant, nil},
40 {`"(?:\\.|[^"])*"`, StringDouble, nil},
41 {`'(?:\\.|[^'])*'`, StringSingle, nil},
42 {`\d\d\d\d-\d\d-\d\d([T ]\d\d:\d\d:\d\d(\.\d+)?(Z|\s+[-+]\d+)?)?`, LiteralDate, nil},
43 {`\b[+\-]?(0x[\da-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)\b`, Number, nil},
44 {`([^\{\}\[\]\?,\:\!\-\*&\@].*)( )+(#.*)`, ByGroups(Literal, Whitespace, Comment), nil},
45 {`[^\{\}\[\]\?,\:\!\-\*&\@].*`, Literal, nil},
46 },
47 "key": {
48 {`"[^"\n].*": `, NameTag, nil},
49 {`(-)( )([^"\n{]*)(:)( )`, ByGroups(Punctuation, Whitespace, NameTag, Punctuation, Whitespace), nil},
50 {`([^"\n{]*)(:)( )`, ByGroups(NameTag, Punctuation, Whitespace), nil},
51 {`([^"\n{]*)(:)(\n)`, ByGroups(NameTag, Punctuation, Whitespace), nil},
52 },
53 "whitespace": {
54 {`\s+`, Whitespace, nil},
55 {`\n+`, Whitespace, nil},
56 },
57 }
58 }
59
View as plain text