main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | /*
|
---|
| 2 | Language: JSON
|
---|
| 3 | Description: JSON (JavaScript Object Notation) is a lightweight data-interchange format.
|
---|
| 4 | Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
|
---|
| 5 | Website: http://www.json.org
|
---|
| 6 | Category: common, protocols
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | function json(hljs) {
|
---|
| 10 | const LITERALS = {
|
---|
| 11 | literal: 'true false null'
|
---|
| 12 | };
|
---|
| 13 | const ALLOWED_COMMENTS = [
|
---|
| 14 | hljs.C_LINE_COMMENT_MODE,
|
---|
| 15 | hljs.C_BLOCK_COMMENT_MODE
|
---|
| 16 | ];
|
---|
| 17 | const TYPES = [
|
---|
| 18 | hljs.QUOTE_STRING_MODE,
|
---|
| 19 | hljs.C_NUMBER_MODE
|
---|
| 20 | ];
|
---|
| 21 | const VALUE_CONTAINER = {
|
---|
| 22 | end: ',',
|
---|
| 23 | endsWithParent: true,
|
---|
| 24 | excludeEnd: true,
|
---|
| 25 | contains: TYPES,
|
---|
| 26 | keywords: LITERALS
|
---|
| 27 | };
|
---|
| 28 | const OBJECT = {
|
---|
| 29 | begin: /\{/,
|
---|
| 30 | end: /\}/,
|
---|
| 31 | contains: [
|
---|
| 32 | {
|
---|
| 33 | className: 'attr',
|
---|
| 34 | begin: /"/,
|
---|
| 35 | end: /"/,
|
---|
| 36 | contains: [hljs.BACKSLASH_ESCAPE],
|
---|
| 37 | illegal: '\\n'
|
---|
| 38 | },
|
---|
| 39 | hljs.inherit(VALUE_CONTAINER, {
|
---|
| 40 | begin: /:/
|
---|
| 41 | })
|
---|
| 42 | ].concat(ALLOWED_COMMENTS),
|
---|
| 43 | illegal: '\\S'
|
---|
| 44 | };
|
---|
| 45 | const ARRAY = {
|
---|
| 46 | begin: '\\[',
|
---|
| 47 | end: '\\]',
|
---|
| 48 | contains: [hljs.inherit(VALUE_CONTAINER)], // inherit is a workaround for a bug that makes shared modes with endsWithParent compile only the ending of one of the parents
|
---|
| 49 | illegal: '\\S'
|
---|
| 50 | };
|
---|
| 51 | TYPES.push(OBJECT, ARRAY);
|
---|
| 52 | ALLOWED_COMMENTS.forEach(function(rule) {
|
---|
| 53 | TYPES.push(rule);
|
---|
| 54 | });
|
---|
| 55 | return {
|
---|
| 56 | name: 'JSON',
|
---|
| 57 | contains: TYPES,
|
---|
| 58 | keywords: LITERALS,
|
---|
| 59 | illegal: '\\S'
|
---|
| 60 | };
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | module.exports = json;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.