Regular Expressions 101

Community Patterns

YAML Textmate Grammar - Name Property Hoister

0

Regular Expression
ECMAScript (JavaScript)

/
^([ ]{6})(- )((?!name)\w+[:](?:[ ]*(?=\n\1[ ]{4}\S)|[ ]*\S.+))((?:\n\1[ ]{2}.+)*?)(?:\n(\1[ ]{2})(name[ ]*[:])((?:[ ]*(?![>|])\S.+\b)|(?:(?:[ ]*[>|])?\n\5[ ]+.+)*))[ ]*$
/
gm

Description

YAML Textmate Grammar - Name property hoister

Moves a later name key value pair in multi-value block map definition to the top of its body (e.g. value with - prefix), easily changable to other keys and indent levels.

Details/Notes on Modification

  • Indent size is assumed to be 2.

  • Indent level of names being hoisted is controlled by capture group $1, which is later referenced by $5, the indent level of all other properties

  • Other properties can be hoisted by replacing the two instances of name in the pattern. A couple inputs for simple nested, folded, and literal values (immediately after these notes) seem to work.

  • Syntax level comments in captures will probably need to be rearranged after applying this, and worst case (especially comments lower indents) break matching

Submitted by disk0 - 3 years ago