From b83a015e0bf71a12ea75b013607b7c6e26355f23 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sun, 24 Sep 2017 21:57:29 +1000 Subject: [PATCH] More YAML tweaks. --- lexers/yaml.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lexers/yaml.go b/lexers/yaml.go index 52e6e3a..7a7a9ea 100644 --- a/lexers/yaml.go +++ b/lexers/yaml.go @@ -13,18 +13,26 @@ var YAML = Register(MustNewLexer( }, Rules{ "root": { - {`\s+`, Whitespace, nil}, + Include("whitespace"), {`#.*`, Comment, nil}, - {`!![^\s]+`, CommentPreproc, nil}, - {`&[^\s]+`, CommentPreproc, nil}, - {`\*[^\s]+`, CommentPreproc, nil}, - {Words(``, `\b`, "true", "false", "null"), KeywordConstant, nil}, - {`"(?:\\.|[^"])+"`, StringDouble, nil}, - {`\d\d\d\d-\d\d-\d\d([T ]\d\d:\d\d:\d\d(\.\d+)?(Z|\s+[-+]\d+)?)?`, LiteralDate, nil}, + {`![^\s]+`, CommentPreproc, nil}, + {`\s&[^\s]+`, CommentPreproc, nil}, + {`\s\*[^\s]+`, CommentPreproc, nil}, + {`^%include\s+[^\n\r]+`, CommentPreproc, nil}, {`([>|])(\s+)((?:(?:.*?$)(?:[\n\r]*?\2)?)*)`, ByGroups(StringDoc, StringDoc, StringDoc), nil}, - {`[+\-]?(0x[\da-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)\b`, Number, nil}, + 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}, + }, + "whitespace": { + {`\s+`, Whitespace, nil}, + }, }, ))