2019-10-27 17:04:31 +01:00
|
|
|
package y
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
|
|
)
|
|
|
|
|
2021-04-28 18:35:32 +02:00
|
|
|
var YAML = internal.Register(MustNewLazyLexer(
|
2019-10-27 17:04:31 +01:00
|
|
|
&Config{
|
|
|
|
Name: "YAML",
|
|
|
|
Aliases: []string{"yaml"},
|
|
|
|
Filenames: []string{"*.yaml", "*.yml"},
|
|
|
|
MimeTypes: []string{"text/x-yaml"},
|
|
|
|
},
|
2021-04-28 18:35:32 +02:00
|
|
|
yamlRules,
|
|
|
|
))
|
|
|
|
|
|
|
|
func yamlRules() Rules {
|
|
|
|
return Rules{
|
2019-10-27 17:04:31 +01:00
|
|
|
"root": {
|
|
|
|
Include("whitespace"),
|
2020-08-08 16:29:29 +02:00
|
|
|
{`^---`, NameNamespace, nil},
|
|
|
|
{`^\.\.\.`, NameNamespace, nil},
|
2020-01-20 18:34:48 +01:00
|
|
|
{`[\n?]?\s*- `, Text, nil},
|
|
|
|
{`#.*$`, Comment, nil},
|
2019-10-27 17:04:31 +01:00
|
|
|
{`!![^\s]+`, CommentPreproc, nil},
|
|
|
|
{`&[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`\*[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`^%include\s+[^\n\r]+`, CommentPreproc, nil},
|
2020-01-20 18:34:48 +01:00
|
|
|
Include("key"),
|
2019-10-27 17:04:31 +01:00
|
|
|
Include("value"),
|
|
|
|
{`[?:,\[\]]`, Punctuation, nil},
|
|
|
|
{`.`, Text, nil},
|
|
|
|
},
|
|
|
|
"value": {
|
2020-11-03 23:59:56 +01:00
|
|
|
{`([>|](?:[+-])?)(\n(^ {1,})(?:.*\n*(?:^\3 *).*)*)`, ByGroups(Punctuation, StringDoc, Whitespace), nil},
|
2020-08-08 16:29:29 +02:00
|
|
|
{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},
|
2019-10-27 17:04:31 +01: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},
|
2020-11-03 23:59:56 +01:00
|
|
|
{`([^\{\}\[\]\?,\:\!\-\*&\@].*)( )+(#.*)`, ByGroups(Literal, Whitespace, Comment), nil},
|
2020-08-08 16:29:29 +02:00
|
|
|
{`[^\{\}\[\]\?,\:\!\-\*&\@].*`, Literal, nil},
|
2019-10-27 17:04:31 +01:00
|
|
|
},
|
2020-01-20 18:34:48 +01:00
|
|
|
"key": {
|
2020-08-08 16:29:29 +02:00
|
|
|
{`"[^"\n].*": `, NameTag, nil},
|
|
|
|
{`(-)( )([^"\n{]*)(:)( )`, ByGroups(Punctuation, Whitespace, NameTag, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)( )`, ByGroups(NameTag, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)(\n)`, ByGroups(NameTag, Punctuation, Whitespace), nil},
|
2020-01-20 18:34:48 +01:00
|
|
|
},
|
2019-10-27 17:04:31 +01:00
|
|
|
"whitespace": {
|
|
|
|
{`\s+`, Whitespace, nil},
|
2020-01-20 18:34:48 +01:00
|
|
|
{`\n+`, Whitespace, nil},
|
2019-10-27 17:04:31 +01:00
|
|
|
},
|
2021-04-28 18:35:32 +02:00
|
|
|
}
|
|
|
|
}
|