| 1 | /* Monarch grammar for TOML (ADR 0163 M9). */ |
| 2 | (function (global) { |
| 3 | 'use strict'; |
| 4 | |
| 5 | function registerTomlMonarch(monaco) { |
| 6 | if (!monaco || !monaco.languages) return; |
| 7 | monaco.languages.register({ id: 'toml' }); |
| 8 | monaco.languages.setMonarchTokensProvider('toml', { |
| 9 | defaultToken: '', |
| 10 | tokenPostfix: '.toml', |
| 11 | brackets: [ |
| 12 | { open: '{', close: '}', token: 'delimiter.bracket' }, |
| 13 | { open: '[', close: ']', token: 'delimiter.square' }, |
| 14 | ], |
| 15 | keywords: ['true', 'false'], |
| 16 | tokenizer: { |
| 17 | root: [ |
| 18 | { include: '@whitespace' }, |
| 19 | [/^\s*\[\[\s*[^\]]+\s*\]\]/, 'type.identifier'], |
| 20 | [/^\s*\[\s*[^\]]+\s*\]/, 'type.identifier'], |
| 21 | [/([A-Za-z0-9_-]+)(\s*)(=)/, ['key', 'white', 'delimiter']], |
| 22 | [/#.*$/, 'comment'], |
| 23 | [/"([^"\\]|\\.)*$/, 'string.invalid'], |
| 24 | [/"/, { token: 'string.quote', next: '@stringDouble' }], |
| 25 | [/'([^'\\]|\\.)*$/, 'string.invalid'], |
| 26 | [/'/, { token: 'string.quote', next: '@stringSingle' }], |
| 27 | [/\b(?:true|false)\b/, 'keyword'], |
| 28 | [/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/, 'number'], |
| 29 | [/[,]/, 'delimiter'], |
| 30 | ], |
| 31 | whitespace: [[/\s+/, 'white']], |
| 32 | stringDouble: [ |
| 33 | [/[^\\"]+/, 'string'], |
| 34 | [/\\./, 'string.escape'], |
| 35 | [/"/, { token: 'string.quote', next: '@pop' }], |
| 36 | ], |
| 37 | stringSingle: [ |
| 38 | [/[^\\']+/, 'string'], |
| 39 | [/\\./, 'string.escape'], |
| 40 | [/'/, { token: 'string.quote', next: '@pop' }], |
| 41 | ], |
| 42 | }, |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | global.cideRegisterMonarchGrammars = registerTomlMonarch; |
| 47 | })(typeof window !== 'undefined' ? window : globalThis); |
| 48 | |