2020-09-20 00:00:50 +08:00
|
|
|
package y
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
var YAML = internal.Register(MustNewLexer(
|
|
|
|
&Config{
|
|
|
|
Name: "YAML",
|
|
|
|
Aliases: []string{"yaml"},
|
|
|
|
Filenames: []string{"*.yaml", "*.yml"},
|
|
|
|
MimeTypes: []string{"text/x-yaml"},
|
|
|
|
},
|
|
|
|
Rules{
|
|
|
|
"root": {
|
|
|
|
Include("whitespace"),
|
2021-03-05 18:06:25 +08:00
|
|
|
{`^---`, Text, nil},
|
2020-09-20 00:00:50 +08:00
|
|
|
{`[\n?]?\s*- `, Text, nil},
|
|
|
|
{`#.*$`, Comment, nil},
|
|
|
|
{`!![^\s]+`, CommentPreproc, nil},
|
|
|
|
{`&[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`\*[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`^%include\s+[^\n\r]+`, CommentPreproc, nil},
|
2021-03-05 18:06:25 +08:00
|
|
|
{`([>|+-]\s+)(\s+)((?:(?:.*?$)(?:[\n\r]*?)?)*)`, ByGroups(StringDoc, StringDoc, StringDoc), nil},
|
2020-09-20 00:00:50 +08:00
|
|
|
Include("key"),
|
|
|
|
Include("value"),
|
|
|
|
{`[?:,\[\]]`, Punctuation, nil},
|
|
|
|
{`.`, Text, nil},
|
|
|
|
},
|
|
|
|
"value": {
|
2021-03-05 18:06:25 +08:00
|
|
|
{Words(``, `\b`, "true", "false", "null"), KeywordConstant, nil},
|
2020-09-20 00:00:50 +08:00
|
|
|
{`"(?:\\.|[^"])*"`, StringDouble, nil},
|
|
|
|
{`'(?:\\.|[^'])*'`, StringSingle, nil},
|
|
|
|
{`\d\d\d\d-\d\d-\d\d([T ]\d\d:\d\d:\d\d(\.\d+)?(Z|\s+[-+]\d+)?)?`, LiteralDate, nil},
|
|
|
|
{`\b[+\-]?(0x[\da-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)\b`, Number, nil},
|
2021-03-05 18:06:25 +08:00
|
|
|
{`\b[\w]+\b`, Text, nil},
|
2020-09-20 00:00:50 +08:00
|
|
|
},
|
|
|
|
"key": {
|
2021-03-05 18:06:25 +08:00
|
|
|
{`"[^"\n].*": `, Keyword, nil},
|
|
|
|
{`(-)( )([^"\n{]*)(:)( )`, ByGroups(Punctuation, Whitespace, Keyword, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)( )`, ByGroups(Keyword, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)(\n)`, ByGroups(Keyword, Punctuation, Whitespace), nil},
|
2020-09-20 00:00:50 +08:00
|
|
|
},
|
|
|
|
"whitespace": {
|
|
|
|
{`\s+`, Whitespace, nil},
|
|
|
|
{`\n+`, Whitespace, nil},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|