2018-03-19 17:08:44 +01:00
|
|
|
package y
|
2017-10-22 05:37:38 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
2018-03-19 17:08:44 +01:00
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
2017-10-22 05:37:38 +02:00
|
|
|
)
|
|
|
|
|
2018-03-19 17:08:44 +01:00
|
|
|
var YAML = internal.Register(MustNewLexer(
|
2017-10-22 05:37:38 +02:00
|
|
|
&Config{
|
|
|
|
Name: "YAML",
|
|
|
|
Aliases: []string{"yaml"},
|
|
|
|
Filenames: []string{"*.yaml", "*.yml"},
|
|
|
|
MimeTypes: []string{"text/x-yaml"},
|
|
|
|
},
|
|
|
|
Rules{
|
|
|
|
"root": {
|
|
|
|
Include("whitespace"),
|
2020-05-09 22:49:03 +02:00
|
|
|
{`^---`, Text, nil},
|
|
|
|
{`[\n?]?\s*- `, Text, nil},
|
|
|
|
{`#.*$`, Comment, nil},
|
2018-03-19 17:08:44 +01:00
|
|
|
{`!![^\s]+`, CommentPreproc, nil},
|
|
|
|
{`&[^\s]+`, CommentPreproc, nil},
|
|
|
|
{`\*[^\s]+`, CommentPreproc, nil},
|
2017-10-22 05:37:38 +02:00
|
|
|
{`^%include\s+[^\n\r]+`, CommentPreproc, nil},
|
2019-02-18 19:29:11 +01:00
|
|
|
{`([>|+-]\s+)(\s+)((?:(?:.*?$)(?:[\n\r]*?)?)*)`, ByGroups(StringDoc, StringDoc, StringDoc), nil},
|
2020-05-09 22:49:03 +02:00
|
|
|
Include("key"),
|
2017-10-22 05:37:38 +02:00
|
|
|
Include("value"),
|
|
|
|
{`[?:,\[\]]`, Punctuation, nil},
|
|
|
|
{`.`, Text, nil},
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
{Words(``, `\b`, "true", "false", "null"), KeywordConstant, nil},
|
|
|
|
{`"(?:\\.|[^"])*"`, 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},
|
2018-03-19 17:08:44 +01:00
|
|
|
{`\b[\w]+\b`, Text, nil},
|
2017-10-22 05:37:38 +02:00
|
|
|
},
|
2020-05-09 22:49:03 +02:00
|
|
|
"key": {
|
|
|
|
{`"[^"\n].*": `, Keyword, nil},
|
|
|
|
{`(-)( )([^"\n{]*)(:)( )`, ByGroups(Punctuation, Whitespace, Keyword, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)( )`, ByGroups(Keyword, Punctuation, Whitespace), nil},
|
|
|
|
{`([^"\n{]*)(:)(\n)`, ByGroups(Keyword, Punctuation, Whitespace), nil},
|
|
|
|
},
|
2017-10-22 05:37:38 +02:00
|
|
|
"whitespace": {
|
|
|
|
{`\s+`, Whitespace, nil},
|
2020-05-09 22:49:03 +02:00
|
|
|
{`\n+`, Whitespace, nil},
|
2017-10-22 05:37:38 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|