From e24e7f65919518d8329a746f39e39cd48ae747d2 Mon Sep 17 00:00:00 2001 From: Wliu Date: Wed, 1 Feb 2017 17:20:37 -0500 Subject: [PATCH 1/3] Support flow mappings --- grammars/yaml.cson | 160 ++++++++++++++++++++++++++++++++++++++++++ spec/yaml-spec.coffee | 5 -- 2 files changed, 160 insertions(+), 5 deletions(-) diff --git a/grammars/yaml.cson b/grammars/yaml.cson index 382def6..70cbdf6 100644 --- a/grammars/yaml.cson +++ b/grammars/yaml.cson @@ -29,6 +29,9 @@ 'match': '^---' 'name': 'punctuation.definition.directives.end.yaml' } + { + 'include': '#mapping' + } { # hello: > # hello: | @@ -232,6 +235,160 @@ 'escaped_char': 'match': '\\\\.' 'name': 'constant.character.escape.yaml' + 'mapping': + 'begin': '{' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.mapping.begin.yaml' + 'end': '}' + 'endCaptures': + '0': + 'name': 'punctuation.definition.mapping.end.yaml' + 'name': 'meta.mapping.yaml' + 'patterns': [ + { + 'include': '#mapping' + } + { + 'begin': '([^!{@#%&*>,\'"][^#\'"]*?)(:)' + 'beginCaptures': + '1': + 'name': 'entity.name.tag.yaml' + '2': + 'name': 'punctuation.separator.key-value.yaml' + 'end': ',|(?=})' + 'endCaptures': + '0': + 'name': 'punctuation.separator.yaml' + 'patterns': [ + { + 'include': '#mapping-scalar-content' + } + ] + } + { + 'begin': '(?:((\')([^\']*?)(\'))|((")([^"]*?)(")))(:)' + 'beginCaptures': + '1': + 'name': 'string.quoted.single.yaml' + '2': + 'name': 'punctuation.definition.string.begin.yaml' + '3': + 'name': 'entity.name.tag.yaml' + '4': + 'name': 'punctuation.definition.string.end.yaml' + '5': + 'name': 'string.quoted.double.yaml' + '6': + 'name': 'punctuation.definition.string.begin.yaml' + '7': + 'name': 'entity.name.tag.yaml' + '8': + 'name': 'punctuation.definition.string.end.yaml' + '9': + 'name': 'punctuation.separator.key-value.yaml' + 'end': ',|(?=})' + 'endCaptures': + '0': + 'name': 'punctuation.separator.yaml' + 'patterns': [ + { + 'include': '#mapping-scalar-content' + } + ] + } + ] + 'mapping-scalar-content': + 'patterns': [ + # This is mostly the same thing as scalar-content, but with an extra (?=[,}]) lookahead added at the end of each rule + { + 'match': '!(?=\\s)' + 'name': 'punctuation.definition.tag.non-specific.yaml' + } + { + 'include': '#mapping' + } + { + 'match': '(?<=\\s)(true|false|null)(?=\\s*($|[,}]))' + 'name': 'constant.language.yaml' + } + { + 'match': '([0-9]{4}-[0-9]{2}-[0-9]{2})(?=\\s*($|[,}]))' + 'captures': + '1': + 'name': 'constant.other.date.yaml' + } + { + 'match': '(((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f)?)(?=\\s*($|[,}]))' + 'captures': + '1': + 'name': 'constant.numeric.yaml' + } + { + 'begin': '"' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': '"' + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.quoted.double.yaml' + 'patterns': [ + { + 'include': '#escaped_char' + } + { + 'include': '#erb' + } + ] + } + { + # Per http://www.yaml.org/spec/1.2/spec.html#id2788097, only single quotes can be escaped + 'begin': "'" + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': "'" + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.quoted.single.yaml' + 'applyEndPatternLast': true + 'patterns': [ + { + 'match': "''" + 'name': 'constant.character.escape.yaml' + } + { + 'include': '#erb' + } + ] + } + { + 'begin': '`' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': '`' + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.interpolated.yaml' + 'patterns': [ + { + 'include': '#escaped_char' + } + { + 'include': '#erb' + } + ] + } + { + 'match': '[^\\s"\'\\n](?!\\s*#(?!{))([^,{}#\\n]|((? expect(tokens[3]).toEqual value: "#", scopes: ["source.yaml", "comment.line.number-sign.yaml", "punctuation.definition.comment.yaml"] expect(tokens[4]).toEqual value: " This colon breaks syntax highlighting: see?", scopes: ["source.yaml", "comment.line.number-sign.yaml"] - it "does not confuse keys and unquoted strings", -> - {tokens} = grammar.tokenizeLine("- { role: common }") - expect(tokens[0]).toEqual value: "-", scopes: ["source.yaml", "punctuation.definition.entry.yaml"] - expect(tokens[2]).toEqual value: "{ role: common }", scopes: ["source.yaml", "string.unquoted.yaml"] - it "parses colons in key names", -> lines = grammar.tokenizeLines """ colon::colon: 1 From 96c6e689bbab734047710d20d1decaf6d796b93f Mon Sep 17 00:00:00 2001 From: Wliu Date: Wed, 1 Feb 2017 17:27:18 -0500 Subject: [PATCH 2/3] :bug: --- grammars/yaml.cson | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grammars/yaml.cson b/grammars/yaml.cson index 70cbdf6..d059883 100644 --- a/grammars/yaml.cson +++ b/grammars/yaml.cson @@ -250,7 +250,7 @@ 'include': '#mapping' } { - 'begin': '([^!{@#%&*>,\'"][^#\'"]*?)(:)' + 'begin': '([^!{@#%&*>,\'"][^#\'"]*?)(:)\\s+' 'beginCaptures': '1': 'name': 'entity.name.tag.yaml' @@ -267,6 +267,7 @@ ] } { + # JSON-like: no spaces are needed after the key 'begin': '(?:((\')([^\']*?)(\'))|((")([^"]*?)(")))(:)' 'beginCaptures': '1': From ecdebc76ca9c825097e2135ca32e283b7b2451fc Mon Sep 17 00:00:00 2001 From: Wliu Date: Wed, 1 Feb 2017 17:51:23 -0500 Subject: [PATCH 3/3] Support flow sequences --- grammars/yaml.cson | 223 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/grammars/yaml.cson b/grammars/yaml.cson index d059883..f366831 100644 --- a/grammars/yaml.cson +++ b/grammars/yaml.cson @@ -32,6 +32,9 @@ { 'include': '#mapping' } + { + 'include': '#sequence' + } { # hello: > # hello: | @@ -474,6 +477,9 @@ { 'include': '#mapping' } + { + 'include': '#sequence' + } { 'include': '#constants' } @@ -487,6 +493,223 @@ 'include': '#strings' } ] + 'sequence': + 'begin': '\\[' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.sequence.begin.yaml' + 'end': '\\]' + 'endCaptures': + '0': + 'name': 'punctuation.definition.sequence.end.yaml' + 'name': 'meta.sequence.yaml' + 'patterns': [ + { + 'include': '#sequence' + } + { + 'match': ',' + 'name': 'punctuation.separator.yaml' + } + { + 'begin': '([^!{@#%&*>,\'"][^#\'"]*?)(:)\\s+' + 'beginCaptures': + '1': + 'name': 'entity.name.tag.yaml' + '2': + 'name': 'punctuation.separator.key-value.yaml' + 'end': '(?=[,\\]])' + 'patterns': [ + { + 'include': '#sequence-scalar-content' + } + ] + } + { + # JSON-like: no spaces are needed after the key + 'begin': '(?:((\')([^\']*?)(\'))|((")([^"]*?)(")))(:)' + 'beginCaptures': + '1': + 'name': 'string.quoted.single.yaml' + '2': + 'name': 'punctuation.definition.string.begin.yaml' + '3': + 'name': 'entity.name.tag.yaml' + '4': + 'name': 'punctuation.definition.string.end.yaml' + '5': + 'name': 'string.quoted.double.yaml' + '6': + 'name': 'punctuation.definition.string.begin.yaml' + '7': + 'name': 'entity.name.tag.yaml' + '8': + 'name': 'punctuation.definition.string.end.yaml' + '9': + 'name': 'punctuation.separator.key-value.yaml' + 'end': '(?=[,\\]])' + 'patterns': [ + { + 'include': '#sequence-scalar-content' + } + ] + } + { + 'begin': '"' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': '"' + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.quoted.double.yaml' + 'patterns': [ + { + 'include': '#escaped_char' + } + { + 'include': '#erb' + } + ] + } + { + # Per http://www.yaml.org/spec/1.2/spec.html#id2788097, only single quotes can be escaped + 'begin': "'" + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': "'" + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.quoted.single.yaml' + 'applyEndPatternLast': true + 'patterns': [ + { + 'match': "''" + 'name': 'constant.character.escape.yaml' + } + { + 'include': '#erb' + } + ] + } + { + 'begin': '`' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.string.begin.yaml' + 'end': '`' + 'endCaptures': + '0': + 'name': 'punctuation.definition.string.end.yaml' + 'name': 'string.interpolated.yaml' + 'patterns': [ + { + 'include': '#escaped_char' + } + { + 'include': '#erb' + } + ] + } + { + 'match': '[^\\s"\'\\n](?!\\s*#(?!{))([^,\\[\\]#\\n]|((?