|
| 1 | +%YAML 1.2 |
| 2 | +--- |
| 3 | +name: JSON |
| 4 | +scope: source.json.vendored-for-liquid |
| 5 | +version: 2 |
| 6 | +hidden: true |
| 7 | + |
| 8 | +contexts: |
| 9 | + |
| 10 | + prototype: |
| 11 | + - include: comments |
| 12 | + |
| 13 | + main: |
| 14 | + - include: values |
| 15 | + |
| 16 | + values: |
| 17 | + - include: constants |
| 18 | + - include: floats |
| 19 | + - include: integers |
| 20 | + - include: strings |
| 21 | + - include: arrays |
| 22 | + - include: objects |
| 23 | + |
| 24 | +###[ COMMENTS ]################################################################ |
| 25 | + |
| 26 | + comments: |
| 27 | + - include: block-comments |
| 28 | + - include: line-comments |
| 29 | + |
| 30 | + block-comments: |
| 31 | + # empty block comments |
| 32 | + - match: /\*\*+/ |
| 33 | + scope: comment.block.empty.json punctuation.definition.comment.json |
| 34 | + # documentation block comments |
| 35 | + - match: /\*\*+ |
| 36 | + scope: punctuation.definition.comment.begin.json |
| 37 | + push: block-comment-documentation-body |
| 38 | + # normal block comments |
| 39 | + - match: /\* |
| 40 | + scope: punctuation.definition.comment.begin.json |
| 41 | + push: block-comment-body |
| 42 | + |
| 43 | + block-comment-documentation-body: |
| 44 | + - meta_include_prototype: false |
| 45 | + - meta_scope: comment.block.documentation.json |
| 46 | + - match: \*+/ |
| 47 | + scope: punctuation.definition.comment.end.json |
| 48 | + pop: 1 |
| 49 | + - match: ^\s*(\*)(?![*/]) |
| 50 | + captures: |
| 51 | + 1: punctuation.definition.comment.json |
| 52 | + |
| 53 | + block-comment-body: |
| 54 | + - meta_include_prototype: false |
| 55 | + - meta_scope: comment.block.json |
| 56 | + - match: \*/ |
| 57 | + scope: punctuation.definition.comment.end.json |
| 58 | + pop: 1 |
| 59 | + - match: ^\s*(\*)(?![*/]) |
| 60 | + captures: |
| 61 | + 1: punctuation.definition.comment.json |
| 62 | + |
| 63 | + line-comments: |
| 64 | + - match: // |
| 65 | + scope: punctuation.definition.comment.json |
| 66 | + push: line-comment-body |
| 67 | + |
| 68 | + line-comment-body: |
| 69 | + - meta_include_prototype: false |
| 70 | + - meta_scope: comment.line.double-slash.json |
| 71 | + - match: $\n? |
| 72 | + pop: 1 |
| 73 | + |
| 74 | +###[ ARRAYS ]################################################################## |
| 75 | + |
| 76 | + arrays: |
| 77 | + - match: \[ |
| 78 | + scope: punctuation.section.sequence.begin.json |
| 79 | + push: array-body |
| 80 | + |
| 81 | + array-body: |
| 82 | + - meta_scope: meta.sequence.json |
| 83 | + - match: \] |
| 84 | + scope: punctuation.section.sequence.end.json |
| 85 | + pop: 1 |
| 86 | + - match: ',' |
| 87 | + scope: punctuation.separator.sequence.json |
| 88 | + - include: values |
| 89 | + - match: \S |
| 90 | + scope: invalid.illegal.expected-sequence-separator.json |
| 91 | + |
| 92 | +###[ OBJECTS ]################################################################# |
| 93 | + |
| 94 | + objects: |
| 95 | + - match: \{ |
| 96 | + scope: punctuation.section.mapping.begin.json |
| 97 | + push: object-body |
| 98 | + |
| 99 | + object-body: |
| 100 | + - meta_scope: meta.mapping.json |
| 101 | + - match: \} |
| 102 | + scope: punctuation.section.mapping.end.json |
| 103 | + pop: 1 |
| 104 | + - match: \" |
| 105 | + scope: punctuation.definition.string.begin.json |
| 106 | + push: object-key-body |
| 107 | + - match: ':' |
| 108 | + scope: punctuation.separator.key-value.json |
| 109 | + push: expect-object-value |
| 110 | + - match: \S |
| 111 | + scope: invalid.illegal.expected-mapping-key.json |
| 112 | + |
| 113 | + object-key-body: |
| 114 | + - clear_scopes: 1 |
| 115 | + - meta_include_prototype: false |
| 116 | + - meta_scope: meta.mapping.key.json string.quoted.double.json |
| 117 | + - include: double-quoted-string-body |
| 118 | + |
| 119 | + expect-object-value: |
| 120 | + - meta_include_prototype: false |
| 121 | + - include: comments |
| 122 | + - match: ',|\s?(?=\})' |
| 123 | + scope: invalid.illegal.expected-mapping-value.json |
| 124 | + pop: 1 |
| 125 | + - match: (?=\S) |
| 126 | + set: object-value-body |
| 127 | + |
| 128 | + object-value-body: |
| 129 | + - clear_scopes: 1 |
| 130 | + - meta_scope: meta.mapping.value.json |
| 131 | + - include: values |
| 132 | + - match: '' |
| 133 | + set: object-value-end |
| 134 | + |
| 135 | + object-value-end: |
| 136 | + - meta_include_prototype: false |
| 137 | + - include: comments |
| 138 | + - match: (?=\s*\}) |
| 139 | + pop: 1 |
| 140 | + - match: ',' |
| 141 | + scope: punctuation.separator.sequence.json |
| 142 | + pop: 1 |
| 143 | + - match: \s(?!/[/*])(?=[^\s,])|[^\s,] |
| 144 | + scope: invalid.illegal.expected-mapping-separator.json |
| 145 | + pop: 1 |
| 146 | + |
| 147 | +###[ LITERALS ]################################################################ |
| 148 | + |
| 149 | + constants: |
| 150 | + - match: \b(?:false|true)\b |
| 151 | + scope: constant.language.boolean.json |
| 152 | + - match: \bnull\b |
| 153 | + scope: constant.language.null.json |
| 154 | + |
| 155 | + floats: |
| 156 | + - match: (-?)((?:0|[1-9]\d*)(?:(?:(\.)\d+)(?:[eE][-+]?\d+)?|(?:[eE][-+]?\d+))) |
| 157 | + scope: meta.number.float.decimal.json |
| 158 | + captures: |
| 159 | + 1: keyword.operator.arithmetic.json |
| 160 | + 2: constant.numeric.value.json |
| 161 | + 3: punctuation.separator.decimal.json |
| 162 | + |
| 163 | + integers: |
| 164 | + - match: (-?)(0|[1-9]\d*) |
| 165 | + scope: meta.number.integer.decimal.json |
| 166 | + captures: |
| 167 | + 1: keyword.operator.arithmetic.json |
| 168 | + 2: constant.numeric.value.json |
| 169 | + |
| 170 | + strings: |
| 171 | + - match: \" |
| 172 | + scope: punctuation.definition.string.begin.json |
| 173 | + push: double-quoted-string-body |
| 174 | + |
| 175 | + double-quoted-string-body: |
| 176 | + - meta_include_prototype: false |
| 177 | + - meta_scope: meta.string.json string.quoted.double.json |
| 178 | + - match: \" |
| 179 | + scope: punctuation.definition.string.end.json |
| 180 | + pop: 1 |
| 181 | + - match: \n |
| 182 | + scope: invalid.illegal.unclosed-string.json |
| 183 | + pop: 1 |
| 184 | + - include: string-prototype |
| 185 | + - include: string-escapes |
| 186 | + |
| 187 | + # for use by inheriting syntaxes to easily inject string interpolation |
| 188 | + # in any kind of quoted or unquoted string |
| 189 | + string-prototype: [] |
| 190 | + |
| 191 | + string-escapes: |
| 192 | + - match: |- |
| 193 | + (?x: # turn on extended mode |
| 194 | + \\ # a literal backslash |
| 195 | + (?: # ...followed by... |
| 196 | + ["\\/bfnrt] # one of these characters |
| 197 | + | # ...or... |
| 198 | + u # a u |
| 199 | + [0-9a-fA-F]{4} # and four hex digits |
| 200 | + ) |
| 201 | + ) |
| 202 | + scope: constant.character.escape.json |
| 203 | + - match: \\. |
| 204 | + scope: invalid.illegal.unrecognized-string-escape.json |
0 commit comments