Skip to content

Commit

Permalink
Fix embedding yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Oct 21, 2024
1 parent 53d38bb commit c42cf86
Show file tree
Hide file tree
Showing 3 changed files with 315 additions and 20 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
"keyword.control.flow"
]
},
{
"scopeName": "source.yaml.embedded",
"path": "./syntaxes/yaml-embedded.tmLanguage.json"
},
{
"scopeName": "source.yaml.1.3",
"path": "./syntaxes/yaml-1.3.tmLanguage.json"
Expand Down
303 changes: 303 additions & 0 deletions syntaxes/yaml-embedded.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
{
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
"scopeName": "source.yaml.embedded",
"name": "YAML embedded",
"patterns": [
{ "include": "source.yaml.1.2#byte-order-mark" },
{ "include": "#directives" },
{ "include": "#document" },
{ "include": "#block-sequence" },
{ "include": "#block-mapping" },
{ "include": "#block-map-key-explicit" },
{ "include": "#block-map-value" },
{ "include": "#block-scalar" },
{ "include": "source.yaml.1.2#anchor-property" },
{ "include": "source.yaml.1.2#tag-property" },
{ "include": "#alias" },
{ "include": "source.yaml.1.2#double" },
{ "include": "source.yaml.1.2#single" },
{ "include": "source.yaml.1.2#flow-mapping" },
{ "include": "source.yaml.1.2#flow-sequence" },
{ "include": "#block-plain-out" },
{ "include": "#presentation-detail" }
],
"repository": {
"directives": {
"comment": "https://yaml.org/spec/1.2.2/#68-directives",
"patterns": [
{
"comment": "https://yaml.org/spec/1.2.2/#681-yaml-directives",
"begin": "(?>^|\\G)(%)(YAML)([\t ]+)([0-9]+\\.[0-9]*)",
"end": "$",
"beginCaptures": {
"1": { "name": "punctuation.definition.directive.begin.yaml" },
"2": { "name": "keyword.other.directive.yaml.yaml" },
"3": { "name": "punctuation.whitespace.separator.yaml" },
"4": { "name": "constant.numeric.yaml-version.yaml" }
},
"name": "meta.directives.yaml",
"patterns": [ { "include": "#presentation-detail" } ]
},
{
"comment": "https://yaml.org/spec/1.2.2/#682-tag-directives",
"begin": "(?>^|\\G)(%)(TAG)(?>([\t ]++)((!)(?>[0-9A-Za-z-]*+(!))?+))?+",
"end": "$",
"beginCaptures": {
"comment": "https://yaml.org/spec/1.2.2/#rule-c-tag-handle",
"1": { "name": "punctuation.definition.directive.begin.yaml" },
"2": { "name": "keyword.other.directive.tag.yaml" },
"3": { "name": "punctuation.whitespace.separator.yaml" },
"4": { "name": "storage.type.tag-handle.yaml" },
"5": { "name": "punctuation.definition.tag.begin.yaml" },
"6": { "name": "punctuation.definition.tag.end.yaml" }
},
"patterns": [
{
"comment": "technically the beginning should only validate against a valid uri scheme [A-Za-z][A-Za-z0-9.+-]*",
"begin": "\\G[\t ]++(?!#)",
"end": "(?=[\r\n\t ])",
"beginCaptures": { "0": { "name": "punctuation.whitespace.separator.yaml" } },
"contentName": "support.type.tag-prefix.yaml",
"patterns": [
{
"match": "%[0-9a-fA-F]{2}",
"name": "constant.character.escape.unicode.8-bit.yaml"
},
{
"match": "%[^\r\n\t ]{2,0}",
"name": "invalid.illegal.constant.character.escape.unicode.8-bit.yaml"
},
{
"match": "\\G[,\\[\\]{}]",
"name": "invalid.illegal.character.uri.yaml"
},
{ "include": "source.yaml#non-printable" },
{
"match": "[^\r\n\t a-zA-Z0-9-#;/?:@&=+$,_.!~*'()\\[\\]]++",
"name": "invalid.illegal.unrecognized.yaml"
}
]
},
{ "include": "#presentation-detail" }
]
},
{
"comment": "https://yaml.org/spec/1.2.2/#rule-ns-reserved-directive",
"begin": "(?>^|\\G)(%)([\\x{85}[^ \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]++)",
"end": "$",
"beginCaptures": {
"1": { "name": "punctuation.definition.directive.begin.yaml" },
"2": { "name": "keyword.other.directive.other.yaml" }
},
"patterns": [
{
"match": "\\G([\t ]++)([\\x{85}[^ \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]++)",
"captures": {
"1": { "name": "punctuation.whitespace.separator.yaml" },
"2": { "name": "string.unquoted.directive-name.yaml" }
}
},
{
"match": "([\t ]++)([\\x{85}[^ \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]++)",
"captures": {
"1": { "name": "punctuation.whitespace.separator.yaml" },
"2": { "name": "string.unquoted.directive-parameter.yaml" }
}
},
{ "include": "#presentation-detail" }
]
}
]
},
"document": {
"comment": "https://yaml.org/spec/1.2.2/#91-documents",
"patterns": [
{
"match": "(?>^|\\G)---(?=[\r\n\t ])",
"name": "entity.other.document.begin.yaml"
},
{
"begin": "(?>^|\\G)\\.{3}(?=[\r\n\t ])",
"end": "$",
"name": "entity.other.document.end.yaml",
"patterns": [
{ "include": "#presentation-detail" },
{ "include": "source.yaml.1.2#unknown" }
]
}
]
},
"block-mapping": {
"//": "The check for plain keys is expensive",
"begin": "(?<=^|\\G|\t| )(?<![^\t ][\t ]*+:[\t ]*+|^---[\t ]*+)(?!:[\r\n\t ])(?=(?>(?#Double Quote)\"(?>[^\\\\\"]++|\\\\.)*+\"|(?#Single Quote)'(?>[^']++|'')*+'|(?#Flow-Map){(?>[^}]++|}[ \t]*+(?!:[\r\n\t ]))++}|(?#Flow-Seq)\\[(?>[^]]++|][ \t]*+(?!:[\r\n\t ]))++]|(?#Plain)(?>[\\x{85}[^-?:,\\[\\]{}#&*!|>'\"%@` \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]|[?:-](?![\r\n\t ]))(?>[^:#]++|:(?![\r\n\t ])|(?<! |\t)#++)*+)?+(?#Map Value)[\t ]*+:[\r\n\t ])",
"end": "(?=:[\r\n\t ])",
"endCaptures": { "0": { "name": "punctuation.separator.map.value.yaml" } },
"name": "meta.map.yaml",
"patterns": [
{ "include": "source.yaml.1.2#block-map-key-double" },
{ "include": "source.yaml#block-map-key-single" },
{ "include": "source.yaml.1.2#block-map-key-plain" },
{ "include": "source.yaml.1.2#flow-mapping" },
{ "include": "source.yaml.1.2#flow-sequence" }
]
},
"block-sequence": {
"comment": "https://yaml.org/spec/1.2.2/#rule-l+block-sequence",
"match": "(?<![^\t ][\t ]*+: *+|^--- *+)-(?=[\r\n\t ])",
"name": "punctuation.definition.block.sequence.item.yaml"
},
"block-map-key-explicit": {
"comment": "https://yaml.org/spec/1.2.2/#rule-c-l-block-map-explicit-key",
"begin": "\\?(?=[\r\n\t ])",
"end": "(?=(?>:|(?>^|\\G)(?>\\.{3}|---))[\r\n\t ])",
"beginCaptures": { "0": { "name": "punctuation.definition.map.key.yaml" } },
"endCaptures": { "0": { "name": "punctuation.separator.map.value.yaml" } },
"name": "meta.map.explicit.yaml",
"patterns": [
{ "include": "source.yaml.1.2#key-double" },
{ "include": "source.yaml#key-single" },
{ "include": "#flow-key-plain-out" },
{ "include": "#block-sequence" },
{ "include": "#block-mapping" },
{ "include": "#block-scalar" },
{ "include": "source.yaml.1.2#anchor-property" },
{ "include": "source.yaml.1.2#tag-property" },
{ "include": "#alias" },
{ "include": "source.yaml.1.2#flow-mapping" },
{ "include": "source.yaml.1.2#flow-sequence" },
{ "include": "#presentation-detail" }
]
},
"block-map-value": {
"comment": "https://yaml.org/spec/1.2.2/#rule-c-l-block-map-implicit-value",
"match": ":(?=[\r\n\t ])",
"name": "punctuation.separator.map.value.yaml"
},
"block-scalar": {
"patterns": [
{
"comment": "This doesn't work correctly when indented. Might have to dump it",
"begin": "(?>(\\|)|(>))(?<chomp>[+-])?+([1-9])(?(<chomp>)|\\g<chomp>)?+",
"while": "(?>^|\\G)(?> {\\4}| *+$)",
"beginCaptures": {
"1": { "name": "keyword.control.flow.block-scalar.literal.yaml" },
"2": { "name": "keyword.control.flow.block-scalar.folded.yaml" },
"3": { "name": "storage.modifier.chomping-indicator.yaml" },
"4": { "name": "constant.numeric.indentation-indicator.yaml" }
},
"whileCaptures": { "0": { "name": "punctuation.whitespace.indentation.yaml" } },
"name": "meta.scalar.yaml",
"patterns": [
{
"begin": "$",
"while": "\\G",
"contentName": "string.unquoted.block.yaml",
"patterns": [ { "include": "source.yaml#non-printable" } ]
},
{
"begin": "\\G",
"end": "$",
"patterns": [
{ "include": "#presentation-detail" },
{ "include": "source.yaml.1.2#unknown" }
]
}
]
},
{
"comment": "I'm not sure how I feel about this",
"begin": "(?>(\\|)|(>))([+-]?+)(.*+)",
"end": "(?! |$)",
"beginCaptures": {
"1": { "name": "keyword.control.flow.block-scalar.literal.yaml" },
"2": { "name": "keyword.control.flow.block-scalar.folded.yaml" },
"3": { "name": "storage.modifier.chomping-indicator.yaml" },
"4": {
"patterns": [
{ "include": "#presentation-detail" },
{ "include": "source.yaml.1.2#unknown" }
]
}
},
"name": "meta.scalar.yaml",
"patterns": [
{
"comment": "https://yaml.org/spec/1.2.2/#rule-l-nb-literal-text",
"//": "Find the highest indented line",
"begin": "(?>^|\\G)(?=( ++)$)",
"end": "(?>^|\\G)(?>(?=\\1(?!$))|(?!\\1| *+$) *+)",
"endCaptures": { "0": { "name": "punctuation.whitespace.separator.yaml" } },
"patterns": [ { "include": "#presentation-detail" } ]
},
{
"comment": "https://yaml.org/spec/1.2.2/#rule-l-nb-literal-text",
"begin": "(?>^|\\G)(?=( ++))",
"end": "(?>^|\\G)(?!\\1| *+$) *+",
"endCaptures": { "0": { "name": "punctuation.whitespace.separator.yaml" } },
"contentName": "string.unquoted.block.yaml",
"patterns": [
{
"comment": "This is not 100% correct",
"match": "(?>^|\\G) ++",
"name": "punctuation.whitespace.separator.yaml"
},
{ "include": "source.yaml#non-printable" }
]
}
]
}
]
},
"block-plain-out": {
"comment": "https://yaml.org/spec/1.2.2/#rule-ns-plain-multi-line (FLOW-OUT)",
"begin": "(?=[\\x{85}[^-?:,\\[\\]{}#&*!|>'\"%@` \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]|[?:-](?![\r\n\t ]))",
"end": "(?=[\t ]++#|[\t ]*+$)",
"name": "string.unquoted.plain.out.yaml",
"patterns": [
{ "include": "source.yaml.1.2#tag-implicit-plain-out" },
{
"match": ":(?=[\r\n\t ])",
"name": "invalid.illegal.multiline-key.yaml"
},
{
"match": "\\x{FEFF}",
"name": "invalid.illegal.bom.yaml"
},
{ "include": "source.yaml#non-printable" }
]
},
"flow-key-plain-out": {
"comment": "https://yaml.org/spec/1.2.2/#rule-ns-plain-one-line (FLOW-OUT)",
"begin": "(?=[\\x{85}[^-?:,\\[\\]{}#&*!|>'\"%@` \\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]|[?:-](?![\r\n\t ]))",
"end": "(?=[\t ]*+(?>$|:[\r\n\t ])|[\t ]++#)",
"name": "meta.map.key.yaml string.unquoted.plain.yaml entity.name.tag.yaml",
"patterns": [
{ "include": "source.yaml.1.2#tag-implicit-plain-out" },
{
"match": "\\x{FEFF}",
"name": "invalid.illegal.bom.yaml"
},
{ "include": "source.yaml#non-printable" }
]
},
"alias": {
"match": "(\\*)([\\x{85}[^ ,\\[\\]{}\\p{Cntrl}\\p{Surrogate}\\x{FEFF FFFE FFFF}]]++)|(\\*)",
"captures": {
"0": { "name": "keyword.control.flow.alias.yaml" },
"1": { "name": "punctuation.definition.alias.yaml" },
"2": { "name": "variable.other.alias.yaml" },
"3": { "name": "invalid.illegal.flow.alias.yaml" }
}
},
"presentation-detail": {
"patterns": [
{
"match": "[\t ]++",
"name": "punctuation.whitespace.separator.yaml"
},
{ "include": "source.yaml#non-printable" },
{ "include": "source.yaml.1.2#comment" }
]
}
}
}
28 changes: 8 additions & 20 deletions syntaxes/yaml.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"scopeName": "source.yaml",
"name": "YAML Ain't Markup Language",
"patterns": [
{
"comment": "Default to YAML version 1.2",
"begin": "\\A",
"while": "^",
"patterns": [ { "include": "source.yaml.1.2" } ]
},
{
"comment": "Support legacy FrontMatter integration",
"//": "https://github.com/microsoft/vscode-markdown-tm-grammar/pull/162",
Expand All @@ -11,26 +17,8 @@
"patterns": [ { "include": "source.yaml.1.2" } ]
},
{
"comment": "For when YAML is embedded inside HTML",
"//": "https://github.com/vuejs/language-tools/issues/4654",
"begin": "(?<=>)\\G(?!<)",
"end": "(?=<)",
"name": "meta.stream.yaml",
"patterns": [
{
"begin": "\\G(?![^<]*+<)",
"while": "^(?![^<]*<)",
"patterns": [ { "include": "source.yaml.1.2" } ]
},
{
"match": "[^<]++",
"captures": { "0": { "patterns": [ { "include": "source.yaml.1.2" } ] } }
}
]
},
{
"comment": "Default to YAML version 1.2",
"include": "source.yaml.1.2"
"comment": "Basic version for embedding",
"include": "source.yaml.embedded"
}
],
"repository": {
Expand Down

1 comment on commit c42cf86

@RedCMD
Copy link
Owner Author

@RedCMD RedCMD commented on c42cf86 Oct 21, 2024

Please sign in to comment.