dart.js (3825B)
1 /* 2 Language: Dart 3 Requires: markdown.js 4 Author: Maxim Dikun <dikmax@gmail.com> 5 Description: Dart a modern, object-oriented language developed by Google. For more information see https://www.dartlang.org/ 6 Website: https://dart.dev 7 Category: scripting 8 */ 9 10 function dart(hljs) { 11 const SUBST = { 12 className: 'subst', 13 variants: [{ 14 begin: '\\$[A-Za-z0-9_]+' 15 }], 16 }; 17 18 const BRACED_SUBST = { 19 className: 'subst', 20 variants: [{ 21 begin: '\\${', 22 end: '}' 23 }], 24 keywords: 'true false null this is new super', 25 }; 26 27 const STRING = { 28 className: 'string', 29 variants: [{ 30 begin: 'r\'\'\'', 31 end: '\'\'\'' 32 }, 33 { 34 begin: 'r"""', 35 end: '"""' 36 }, 37 { 38 begin: 'r\'', 39 end: '\'', 40 illegal: '\\n' 41 }, 42 { 43 begin: 'r"', 44 end: '"', 45 illegal: '\\n' 46 }, 47 { 48 begin: '\'\'\'', 49 end: '\'\'\'', 50 contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST] 51 }, 52 { 53 begin: '"""', 54 end: '"""', 55 contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST] 56 }, 57 { 58 begin: '\'', 59 end: '\'', 60 illegal: '\\n', 61 contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST] 62 }, 63 { 64 begin: '"', 65 end: '"', 66 illegal: '\\n', 67 contains: [hljs.BACKSLASH_ESCAPE, SUBST, BRACED_SUBST] 68 } 69 ] 70 }; 71 BRACED_SUBST.contains = [ 72 hljs.C_NUMBER_MODE, STRING 73 ]; 74 75 const BUILT_IN_TYPES = [ 76 // dart:core 77 'Comparable', 78 'DateTime', 79 'Duration', 80 'Function', 81 'Iterable', 82 'Iterator', 83 'List', 84 'Map', 85 'Match', 86 'Object', 87 'Pattern', 88 'RegExp', 89 'Set', 90 'Stopwatch', 91 'String', 92 'StringBuffer', 93 'StringSink', 94 'Symbol', 95 'Type', 96 'Uri', 97 'bool', 98 'double', 99 'int', 100 'num', 101 // dart:html 102 'Element', 103 'ElementList', 104 ]; 105 const NULLABLE_BUILT_IN_TYPES = BUILT_IN_TYPES.map((e) => `${e}?`); 106 107 const KEYWORDS = { 108 keyword: 'abstract as assert async await break case catch class const continue covariant default deferred do ' + 109 'dynamic else enum export extends extension external factory false final finally for Function get hide if ' + 110 'implements import in inferface is late library mixin new null on operator part required rethrow return set ' + 111 'show static super switch sync this throw true try typedef var void while with yield', 112 built_in: 113 BUILT_IN_TYPES 114 .concat(NULLABLE_BUILT_IN_TYPES) 115 .concat([ 116 // dart:core 117 'Never', 118 'Null', 119 'dynamic', 120 'print', 121 // dart:html 122 'document', 123 'querySelector', 124 'querySelectorAll', 125 'window', 126 ]).join(' '), 127 $pattern: /[A-Za-z][A-Za-z0-9_]*\??/ 128 }; 129 130 return { 131 name: 'Dart', 132 keywords: KEYWORDS, 133 contains: [ 134 STRING, 135 hljs.COMMENT( 136 '/\\*\\*', 137 '\\*/', { 138 subLanguage: 'markdown', 139 relevance:0 140 } 141 ), 142 hljs.COMMENT( 143 '///+\\s*', 144 '$', { 145 contains: [{ 146 subLanguage: 'markdown', 147 begin: '.', 148 end: '$', 149 relevance:0 150 }] 151 } 152 ), 153 hljs.C_LINE_COMMENT_MODE, 154 hljs.C_BLOCK_COMMENT_MODE, 155 { 156 className: 'class', 157 beginKeywords: 'class interface', 158 end: '{', 159 excludeEnd: true, 160 contains: [{ 161 beginKeywords: 'extends implements' 162 }, 163 hljs.UNDERSCORE_TITLE_MODE 164 ] 165 }, 166 hljs.C_NUMBER_MODE, 167 { 168 className: 'meta', 169 begin: '@[A-Za-z]+' 170 }, 171 { 172 begin: '=>' // No markup, just a relevance booster 173 } 174 ] 175 }; 176 } 177 178 module.exports = dart;