| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | // CodeMirror, copyright (c) by Marijn Haverbeke and others
 | 
					
						
							| 
									
										
										
										
											2022-10-15 12:22:09 +02:00
										 |  |  | // Distributed under an MIT license: http://codemirror.net/5/LICENSE
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(mod) { | 
					
						
							|  |  |  |   if (typeof exports == "object" && typeof module == "object") // CommonJS
 | 
					
						
							|  |  |  |     mod(require("../../lib/codemirror")); | 
					
						
							|  |  |  |   else if (typeof define == "function" && define.amd) // AMD
 | 
					
						
							|  |  |  |     define(["../../lib/codemirror"], mod); | 
					
						
							|  |  |  |   else // Plain browser env
 | 
					
						
							|  |  |  |     mod(CodeMirror); | 
					
						
							|  |  |  | })(function(CodeMirror) { | 
					
						
							|  |  |  |   "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CodeMirror.defineMode("elm", function() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function switchState(source, setState, f) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       setState(f); | 
					
						
							|  |  |  |       return f(source, setState); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     var lowerRE = /[a-z]/; | 
					
						
							|  |  |  |     var upperRE = /[A-Z]/; | 
					
						
							|  |  |  |     var innerRE = /[a-zA-Z0-9_]/; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |     var digitRE = /[0-9]/; | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     var hexRE = /[0-9A-Fa-f]/; | 
					
						
							|  |  |  |     var symbolRE = /[-&*+.\\/<>=?^|:]/; | 
					
						
							|  |  |  |     var specialRE = /[(),[\]{}]/; | 
					
						
							|  |  |  |     var spacesRE = /[ \v\f]/; // newlines are handled in tokenizer
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function normal() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       return function(source, setState) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         if (source.eatWhile(spacesRE)) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |           return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         var char = source.next(); | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (specialRE.test(char)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           return (char === '{' && source.eat('-')) | 
					
						
							|  |  |  |             ? switchState(source, setState, chompMultiComment(1)) | 
					
						
							|  |  |  |             : (char === '[' && source.match('glsl|')) | 
					
						
							|  |  |  |                 ? switchState(source, setState, chompGlsl) | 
					
						
							|  |  |  |                 : 'builtin'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (char === '\'') | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           return switchState(source, setState, chompChar); | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (char === '"') | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           return source.eat('"') | 
					
						
							|  |  |  |             ? source.eat('"') | 
					
						
							|  |  |  |                 ? switchState(source, setState, chompMultiString) | 
					
						
							|  |  |  |                 : 'string' | 
					
						
							|  |  |  |             : switchState(source, setState, chompSingleString); | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (upperRE.test(char)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           source.eatWhile(innerRE); | 
					
						
							|  |  |  |           return 'variable-2'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (lowerRE.test(char)) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |           var isDef = source.pos === 1; | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           source.eatWhile(innerRE); | 
					
						
							|  |  |  |           return isDef ? "def" : "variable"; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (digitRE.test(char)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           if (char === '0') | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             if (source.eat(/[xX]/)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               source.eatWhile(hexRE); // should require at least 1
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |               return "number"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           else | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             source.eatWhile(digitRE); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           if (source.eat('.')) | 
					
						
							|  |  |  |           { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |             source.eatWhile(digitRE); // should require at least 1
 | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           if (source.eat(/[eE]/)) | 
					
						
							|  |  |  |           { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |             source.eat(/[-+]/); | 
					
						
							|  |  |  |             source.eatWhile(digitRE); // should require at least 1
 | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           return "number"; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         if (symbolRE.test(char)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           if (char === '-' && source.eat('-')) | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             source.skipToEnd(); | 
					
						
							|  |  |  |             return "comment"; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |           } | 
					
						
							|  |  |  |           source.eatWhile(symbolRE); | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           return "keyword"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (char === '_') | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           return "keyword"; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return "error"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function chompMultiComment(nest) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (nest == 0) | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         return normal(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |       return function(source, setState) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         while (!source.eol()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           var char = source.next(); | 
					
						
							|  |  |  |           if (char == '{' && source.eat('-')) | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             ++nest; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           else if (char == '-' && source.eat('}')) | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             --nest; | 
					
						
							|  |  |  |             if (nest === 0) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |               setState(normal()); | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |               return 'comment'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         setState(chompMultiComment(nest)); | 
					
						
							|  |  |  |         return 'comment'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function chompMultiString(source, setState) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       while (!source.eol()) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         var char = source.next(); | 
					
						
							|  |  |  |         if (char === '"' && source.eat('"') && source.eat('"')) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |           setState(normal()); | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |           return 'string'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |       return 'string'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function chompSingleString(source, setState) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       while (source.skipTo('\\"')) { source.next(); source.next(); } | 
					
						
							|  |  |  |       if (source.skipTo('"')) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         source.next(); | 
					
						
							|  |  |  |         setState(normal()); | 
					
						
							|  |  |  |         return 'string'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |       source.skipToEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       setState(normal()); | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |       return 'error'; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function chompChar(source, setState) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       while (source.skipTo("\\'")) { source.next(); source.next(); } | 
					
						
							|  |  |  |       if (source.skipTo("'")) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         source.next(); | 
					
						
							|  |  |  |         setState(normal()); | 
					
						
							|  |  |  |         return 'string'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       source.skipToEnd(); | 
					
						
							|  |  |  |       setState(normal()); | 
					
						
							|  |  |  |       return 'error'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     function chompGlsl(source, setState) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       while (!source.eol()) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         var char = source.next(); | 
					
						
							|  |  |  |         if (char === '|' && source.eat(']')) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           setState(normal()); | 
					
						
							|  |  |  |           return 'string'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return 'string'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |     var wellKnownWords = { | 
					
						
							|  |  |  |       case: 1, | 
					
						
							|  |  |  |       of: 1, | 
					
						
							|  |  |  |       as: 1, | 
					
						
							|  |  |  |       if: 1, | 
					
						
							|  |  |  |       then: 1, | 
					
						
							|  |  |  |       else: 1, | 
					
						
							|  |  |  |       let: 1, | 
					
						
							|  |  |  |       in: 1, | 
					
						
							|  |  |  |       type: 1, | 
					
						
							|  |  |  |       alias: 1, | 
					
						
							|  |  |  |       module: 1, | 
					
						
							|  |  |  |       where: 1, | 
					
						
							|  |  |  |       import: 1, | 
					
						
							|  |  |  |       exposing: 1, | 
					
						
							|  |  |  |       port: 1 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       startState: function ()  { return { f: normal() }; }, | 
					
						
							|  |  |  |       copyState:  function (s) { return { f: s.f }; }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 12:22:09 +02:00
										 |  |  |       lineComment: '--', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       token: function(stream, state) { | 
					
						
							| 
									
										
										
										
											2020-09-20 21:41:40 +02:00
										 |  |  |         var type = state.f(stream, function(s) { state.f = s; }); | 
					
						
							|  |  |  |         var word = stream.current(); | 
					
						
							|  |  |  |         return (wellKnownWords.hasOwnProperty(word)) ? 'keyword' : type; | 
					
						
							| 
									
										
										
										
											2018-01-21 10:33:32 -05:00
										 |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CodeMirror.defineMIME("text/x-elm", "elm"); | 
					
						
							|  |  |  | }); |