chroma-markdown/vendor/github.com/alecthomas/chroma/lexers/y/yaml.go

59 lines
1.9 KiB
Go
Raw Normal View History

package y
2017-10-22 05:37:38 +02:00
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/internal"
2017-10-22 05:37:38 +02:00
)
var YAML = internal.Register(MustNewLazyLexer(
2017-10-22 05:37:38 +02:00
&Config{
Name: "YAML",
Aliases: []string{"yaml"},
Filenames: []string{"*.yaml", "*.yml"},
MimeTypes: []string{"text/x-yaml"},
},
yamlRules,
))
func yamlRules() Rules {
return Rules{
2017-10-22 05:37:38 +02:00
"root": {
Include("whitespace"),
{`^---`, NameNamespace, nil},
{`^\.\.\.`, NameNamespace, nil},
{`[\n?]?\s*- `, Text, nil},
{`#.*$`, Comment, nil},
{`!![^\s]+`, CommentPreproc, nil},
{`&[^\s]+`, CommentPreproc, nil},
{`\*[^\s]+`, CommentPreproc, nil},
2017-10-22 05:37:38 +02:00
{`^%include\s+[^\n\r]+`, CommentPreproc, nil},
Include("key"),
2017-10-22 05:37:38 +02:00
Include("value"),
{`[?:,\[\]]`, Punctuation, nil},
{`.`, Text, nil},
},
"value": {
{`([>|](?:[+-])?)(\n(^ {1,})(?:.*\n*(?:^\3 *).*)*)`, ByGroups(Punctuation, StringDoc, Whitespace), nil},
{Words(``, `\b`, "true", "True", "TRUE", "false", "False", "FALSE", "null",
"y", "Y", "yes", "Yes", "YES", "n", "N", "no", "No", "NO",
"on", "On", "ON", "off", "Off", "OFF"), KeywordConstant, nil},
2017-10-22 05:37:38 +02: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},
{`([^\{\}\[\]\?,\:\!\-\*&\@].*)( )+(#.*)`, ByGroups(Literal, Whitespace, Comment), nil},
{`[^\{\}\[\]\?,\:\!\-\*&\@].*`, Literal, nil},
2017-10-22 05:37:38 +02:00
},
"key": {
{`"[^"\n].*": `, NameTag, nil},
{`(-)( )([^"\n{]*)(:)( )`, ByGroups(Punctuation, Whitespace, NameTag, Punctuation, Whitespace), nil},
{`([^"\n{]*)(:)( )`, ByGroups(NameTag, Punctuation, Whitespace), nil},
{`([^"\n{]*)(:)(\n)`, ByGroups(NameTag, Punctuation, Whitespace), nil},
},
2017-10-22 05:37:38 +02:00
"whitespace": {
{`\s+`, Whitespace, nil},
{`\n+`, Whitespace, nil},
2017-10-22 05:37:38 +02:00
},
}
}