|
| 1 | +%YAML 1.2 |
| 2 | +--- |
| 3 | +# https://yaml.org/spec/1.2/spec.html |
| 4 | +# https://www.sublimetext.com/docs/syntax.html |
| 5 | +# https://www.sublimetext.com/docs/syntax.html#testing |
| 6 | +# https://www.sublimetext.com/docs/scope_naming.html |
| 7 | +name: JSON (Basic) |
| 8 | +scope: source.json.basic |
| 9 | +version: 2 |
| 10 | +hidden: true |
| 11 | + |
| 12 | + |
| 13 | +####[ Variables ]####################################################################################################### |
| 14 | + |
| 15 | + |
| 16 | +variables: |
| 17 | + boolean: |- |
| 18 | + (?x: # ignore whitespace |
| 19 | + false| |
| 20 | + true |
| 21 | + ) |
| 22 | + 'null': |- |
| 23 | + (?x: # ignore whitespace |
| 24 | + null |
| 25 | + ) |
| 26 | +
|
| 27 | +
|
| 28 | +####[ Contexts ]######################################################################################################## |
| 29 | + |
| 30 | + |
| 31 | +contexts: |
| 32 | + |
| 33 | + main: |
| 34 | + - include: any |
| 35 | + |
| 36 | + any: |
| 37 | + - include: 'null' |
| 38 | + - include: boolean |
| 39 | + - include: numbers |
| 40 | + - include: strings |
| 41 | + - include: sequence |
| 42 | + - include: mapping |
| 43 | + |
| 44 | +####[ Null ]############################################################################################################ |
| 45 | + |
| 46 | + 'null': |
| 47 | + - match: \b({{null}})\b |
| 48 | + captures: |
| 49 | + 1: constant.language.null.json |
| 50 | + |
| 51 | +####[ Boolean ]######################################################################################################### |
| 52 | + |
| 53 | + boolean: |
| 54 | + - match: \b({{boolean}})\b |
| 55 | + captures: |
| 56 | + 1: constant.language.boolean.json |
| 57 | + |
| 58 | +####[ Numbers ]######################################################################################################### |
| 59 | + |
| 60 | + numbers: |
| 61 | + - include: decimal-float |
| 62 | + - include: decimal-integer |
| 63 | + |
| 64 | + decimal-float: |
| 65 | + - match: |- |
| 66 | + (?x: # ignore whitespace |
| 67 | + ([-]?) # capture group 1: optional sign |
| 68 | + ( # capture group 2: numeric value |
| 69 | + (?:0|[1-9]\d*) # zero or any other (positive) decimal integer |
| 70 | + (?: |
| 71 | + (?:(\.)\d+)(?:[eE][-+]?\d+)?| # ... and either a period, one or more number characters, an optional exponent |
| 72 | + (?:[eE][-+]?\d+) # ... or an exponent |
| 73 | + ) |
| 74 | + ) |
| 75 | + ) |
| 76 | + scope: meta.number.float.decimal.json |
| 77 | + captures: |
| 78 | + 1: keyword.operator.arithmetic.json |
| 79 | + 2: constant.numeric.value.json |
| 80 | + 3: punctuation.separator.decimal.json |
| 81 | +
|
| 82 | + decimal-integer: |
| 83 | + - match: |- |
| 84 | + (?x: # ignore whitespace |
| 85 | + ([-]?) # capture group 1: optional sign |
| 86 | + (0|[1-9]\d*) # capture group 2: zero or any other (positive) decimal integer |
| 87 | + ) |
| 88 | + scope: meta.number.integer.decimal.json |
| 89 | + captures: |
| 90 | + 1: keyword.operator.arithmetic.json |
| 91 | + 2: constant.numeric.value.json |
| 92 | +
|
| 93 | +####[ Strings ]######################################################################################################### |
| 94 | + |
| 95 | + strings: |
| 96 | + - include: double-quoted-string |
| 97 | + |
| 98 | + double-quoted-string: |
| 99 | + - match: '"' |
| 100 | + scope: punctuation.definition.string.begin.json |
| 101 | + push: inside-double-quoted-string |
| 102 | + |
| 103 | + inside-double-quoted-string: |
| 104 | + - meta_scope: string.quoted.double.json |
| 105 | + - match: '"' |
| 106 | + scope: punctuation.definition.string.end.json |
| 107 | + pop: 1 |
| 108 | + - include: double-quoted-string-escape |
| 109 | + - match: |- |
| 110 | + (?x: # ignore whitespace |
| 111 | + $\n? # eol (end of line) optionally followed by newline |
| 112 | + ) |
| 113 | + scope: invalid.illegal.unclosed-string.json |
| 114 | + pop: 1 |
| 115 | +
|
| 116 | + double-quoted-string-escape: |
| 117 | + - match: |- |
| 118 | + (?x: # ignore whitespace |
| 119 | + (\\\")| |
| 120 | + (\\\\)| |
| 121 | + (\\\/)| |
| 122 | + (\\b)| |
| 123 | + (\\f)| |
| 124 | + (\\n)| |
| 125 | + (\\r)| |
| 126 | + (\\t)| |
| 127 | + (\\u[0-9a-fA-F]{4}) # backslash, lower u, exactly four hexadecimal characters |
| 128 | + ) |
| 129 | + captures: |
| 130 | + 1: constant.character.escape.double-quote.json |
| 131 | + 2: constant.character.escape.back-slash.json |
| 132 | + 3: constant.character.escape.forward-slash.json |
| 133 | + 4: constant.character.escape.backspace.json |
| 134 | + 5: constant.character.escape.form-feed.json |
| 135 | + 6: constant.character.escape.newline.json # linefeed |
| 136 | + 7: constant.character.escape.carriage-return.json |
| 137 | + 8: constant.character.escape.horizontal-tab.json |
| 138 | + 9: constant.character.escape.unicode-symbol.json |
| 139 | + - match: \\. |
| 140 | + scope: invalid.illegal.unrecognized-string-escape.json |
| 141 | + |
| 142 | +####[ Sequence ]######################################################################################################## |
| 143 | + |
| 144 | + sequence: |
| 145 | + - match: \[ |
| 146 | + scope: punctuation.section.sequence.begin.json |
| 147 | + push: inside-sequence |
| 148 | + |
| 149 | + inside-sequence: |
| 150 | + - meta_scope: meta.sequence.json |
| 151 | + - match: \] |
| 152 | + scope: punctuation.section.sequence.end.json |
| 153 | + pop: 1 |
| 154 | + - include: any |
| 155 | + - match: ',' |
| 156 | + scope: punctuation.separator.sequence.json |
| 157 | + - match: '[^\s\]]' |
| 158 | + scope: invalid.illegal.expected-sequence-separator.json |
| 159 | + |
| 160 | +####[ Mapping ]######################################################################################################### |
| 161 | + |
| 162 | + mapping: |
| 163 | + - match: \{ |
| 164 | + scope: punctuation.section.mapping.begin.json |
| 165 | + push: inside-mapping |
| 166 | + |
| 167 | + inside-mapping: |
| 168 | + - meta_scope: meta.mapping.json |
| 169 | + - match: \} |
| 170 | + scope: punctuation.section.mapping.end.json |
| 171 | + pop: 1 |
| 172 | + - match: '"' |
| 173 | + scope: punctuation.definition.string.begin.json |
| 174 | + push: inside-double-quoted-string-inside-mapping |
| 175 | + - include: latter-part-of-key-value-pair-inside-mapping |
| 176 | + - match: '[^\s\}]' |
| 177 | + scope: invalid.illegal.expected-mapping-key.json |
| 178 | + |
| 179 | + inside-double-quoted-string-inside-mapping: |
| 180 | + - clear_scopes: 1 |
| 181 | + - meta_scope: meta.mapping.key.json string.quoted.double.json |
| 182 | + - include: inside-double-quoted-string |
| 183 | + |
| 184 | + latter-part-of-key-value-pair-inside-mapping: |
| 185 | + - match: ':' |
| 186 | + scope: punctuation.separator.mapping.key-value.json |
| 187 | + push: |
| 188 | + - match: ',|\s?(?=\})' |
| 189 | + scope: invalid.illegal.expected-mapping-value.json |
| 190 | + pop: 1 |
| 191 | + - match: (?=\S) |
| 192 | + set: |
| 193 | + - clear_scopes: 1 |
| 194 | + - meta_scope: meta.mapping.value.json |
| 195 | + - include: any |
| 196 | + - match: '' |
| 197 | + set: |
| 198 | + - match: ',' |
| 199 | + scope: punctuation.separator.mapping.pair.json |
| 200 | + pop: 1 |
| 201 | + - match: \s*(?=\}) |
| 202 | + pop: 1 |
| 203 | + - match: \s(?!/[/*])(?=[^\s,])|[^\s,] |
| 204 | + scope: invalid.illegal.expected-mapping-separator.json |
| 205 | + pop: 1 |
0 commit comments