elm.js
1 /*! `elm` grammar compiled for Highlight.js 11.10.0 */ 2 (function(){ 3 var hljsGrammar = (function () { 4 'use strict'; 5 6 /* 7 Language: Elm 8 Author: Janis Voigtlaender <janis.voigtlaender@gmail.com> 9 Website: https://elm-lang.org 10 Category: functional 11 */ 12 13 /** @type LanguageFn */ 14 function elm(hljs) { 15 const COMMENT = { variants: [ 16 hljs.COMMENT('--', '$'), 17 hljs.COMMENT( 18 /\{-/, 19 /-\}/, 20 { contains: [ 'self' ] } 21 ) 22 ] }; 23 24 const CONSTRUCTOR = { 25 className: 'type', 26 begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (built-in, infix). 27 relevance: 0 28 }; 29 30 const LIST = { 31 begin: '\\(', 32 end: '\\)', 33 illegal: '"', 34 contains: [ 35 { 36 className: 'type', 37 begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?' 38 }, 39 COMMENT 40 ] 41 }; 42 43 const RECORD = { 44 begin: /\{/, 45 end: /\}/, 46 contains: LIST.contains 47 }; 48 49 const CHARACTER = { 50 className: 'string', 51 begin: '\'\\\\?.', 52 end: '\'', 53 illegal: '.' 54 }; 55 56 const KEYWORDS = [ 57 "let", 58 "in", 59 "if", 60 "then", 61 "else", 62 "case", 63 "of", 64 "where", 65 "module", 66 "import", 67 "exposing", 68 "type", 69 "alias", 70 "as", 71 "infix", 72 "infixl", 73 "infixr", 74 "port", 75 "effect", 76 "command", 77 "subscription" 78 ]; 79 80 return { 81 name: 'Elm', 82 keywords: KEYWORDS, 83 contains: [ 84 85 // Top-level constructions. 86 87 { 88 beginKeywords: 'port effect module', 89 end: 'exposing', 90 keywords: 'port effect module where command subscription exposing', 91 contains: [ 92 LIST, 93 COMMENT 94 ], 95 illegal: '\\W\\.|;' 96 }, 97 { 98 begin: 'import', 99 end: '$', 100 keywords: 'import as exposing', 101 contains: [ 102 LIST, 103 COMMENT 104 ], 105 illegal: '\\W\\.|;' 106 }, 107 { 108 begin: 'type', 109 end: '$', 110 keywords: 'type alias', 111 contains: [ 112 CONSTRUCTOR, 113 LIST, 114 RECORD, 115 COMMENT 116 ] 117 }, 118 { 119 beginKeywords: 'infix infixl infixr', 120 end: '$', 121 contains: [ 122 hljs.C_NUMBER_MODE, 123 COMMENT 124 ] 125 }, 126 { 127 begin: 'port', 128 end: '$', 129 keywords: 'port', 130 contains: [ COMMENT ] 131 }, 132 133 // Literals and names. 134 CHARACTER, 135 hljs.QUOTE_STRING_MODE, 136 hljs.C_NUMBER_MODE, 137 CONSTRUCTOR, 138 hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }), 139 COMMENT, 140 141 { // No markup, relevance booster 142 begin: '->|<-' } 143 ], 144 illegal: /;/ 145 }; 146 } 147 148 return elm; 149 150 })(); 151 152 hljs.registerLanguage('elm', hljsGrammar); 153 })();