2020-07-01 03:04:03 +05:30
|
|
|
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"),
|
2020-07-27 22:48:02 +05:30
|
|
|
{`^---`, NameNamespace, nil},
|
|
|
|
{`^\.\.\.`, NameNamespace, nil},
|
2020-07-01 03:04:03 +05:30
|
|
|
{`[\n?]?\s*- `, Text, nil},
|
|
|
|
{`#.*$`, Comment, nil},
|
|
|
|
{`!![^\s]+`, CommentPreproc, nil},
|
|
|
|
{`&[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`\*[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`^%include\s+[^\n\r]+`, CommentPreproc, nil},
|
2020-07-27 22:48:02 +05:30
|
|
|
{`[>|](?:[+-])?\s(?:^(?:[ \n]{1})+.*\n?)*$`, StringDoc, nil},
|
2020-07-01 03:04:03 +05:30
|
|
|
Include("key"),
|
|
|
|
Include("value"),
|
|
|
|
{`[?:,\[\]]`, Punctuation, nil},
|
|
|
|
{`.`, Text, nil},
|
|
|
|
},
|
|
|
|
"value": {
|
2020-07-27 22:48:02 +05:30
|
|
|
{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},
|
2020-07-01 03:04:03 +05:30
|
|
|
{`"(?:\\.|[^"])*"`, 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-07-27 22:48:02 +05:30
|
|
|
{`[^\{\}\[\]\?,\:\!\-\*&\@].*`, Literal, nil},
|
2020-07-01 03:04:03 +05:30
|
|
|
},
|
|
|
|
"key": {
|
2020-07-27 22:48:02 +05:30
|
|
|
{`"[^"\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-07-01 03:04:03 +05:30
|
|
|
},
|
|
|
|
"whitespace": {
|
|
|
|
{`\s+`, Whitespace, nil},
|
|
|
|
{`\n+`, Whitespace, nil},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|