github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/app/public/codemirror/mode/tcl/tcl.js (about) 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 //tcl mode by Ford_Lawnmower :: Based on Velocity mode by Steve O'Hara 5 6 (function(mod) { 7 if (typeof exports == "object" && typeof module == "object") // CommonJS 8 mod(require("../../lib/codemirror")); 9 else if (typeof define == "function" && define.amd) // AMD 10 define(["../../lib/codemirror"], mod); 11 else // Plain browser env 12 mod(CodeMirror); 13 })(function(CodeMirror) { 14 "use strict"; 15 16 CodeMirror.defineMode("tcl", function() { 17 function parseWords(str) { 18 var obj = {}, words = str.split(" "); 19 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 20 return obj; 21 } 22 var keywords = parseWords("Tcl safe after append array auto_execok auto_import auto_load " + 23 "auto_mkindex auto_mkindex_old auto_qualify auto_reset bgerror " + 24 "binary break catch cd close concat continue dde eof encoding error " + 25 "eval exec exit expr fblocked fconfigure fcopy file fileevent filename " + 26 "filename flush for foreach format gets glob global history http if " + 27 "incr info interp join lappend lindex linsert list llength load lrange " + 28 "lreplace lsearch lset lsort memory msgcat namespace open package parray " + 29 "pid pkg::create pkg_mkIndex proc puts pwd re_syntax read regex regexp " + 30 "registry regsub rename resource return scan seek set socket source split " + 31 "string subst switch tcl_endOfWord tcl_findLibrary tcl_startOfNextWord " + 32 "tcl_wordBreakAfter tcl_startOfPreviousWord tcl_wordBreakBefore tcltest " + 33 "tclvars tell time trace unknown unset update uplevel upvar variable " + 34 "vwait"); 35 var functions = parseWords("if elseif else and not or eq ne in ni for foreach while switch"); 36 var isOperatorChar = /[+\-*&%=<>!?^\/\|]/; 37 function chain(stream, state, f) { 38 state.tokenize = f; 39 return f(stream, state); 40 } 41 function tokenBase(stream, state) { 42 var beforeParams = state.beforeParams; 43 state.beforeParams = false; 44 var ch = stream.next(); 45 if ((ch == '"' || ch == "'") && state.inParams) 46 return chain(stream, state, tokenString(ch)); 47 else if (/[\[\]{}\(\),;\.]/.test(ch)) { 48 if (ch == "(" && beforeParams) state.inParams = true; 49 else if (ch == ")") state.inParams = false; 50 return null; 51 } 52 else if (/\d/.test(ch)) { 53 stream.eatWhile(/[\w\.]/); 54 return "number"; 55 } 56 else if (ch == "#" && stream.eat("*")) { 57 return chain(stream, state, tokenComment); 58 } 59 else if (ch == "#" && stream.match(/ *\[ *\[/)) { 60 return chain(stream, state, tokenUnparsed); 61 } 62 else if (ch == "#" && stream.eat("#")) { 63 stream.skipToEnd(); 64 return "comment"; 65 } 66 else if (ch == '"') { 67 stream.skipTo(/"/); 68 return "comment"; 69 } 70 else if (ch == "$") { 71 stream.eatWhile(/[$_a-z0-9A-Z\.{:]/); 72 stream.eatWhile(/}/); 73 state.beforeParams = true; 74 return "builtin"; 75 } 76 else if (isOperatorChar.test(ch)) { 77 stream.eatWhile(isOperatorChar); 78 return "comment"; 79 } 80 else { 81 stream.eatWhile(/[\w\$_{}\xa1-\uffff]/); 82 var word = stream.current().toLowerCase(); 83 if (keywords && keywords.propertyIsEnumerable(word)) 84 return "keyword"; 85 if (functions && functions.propertyIsEnumerable(word)) { 86 state.beforeParams = true; 87 return "keyword"; 88 } 89 return null; 90 } 91 } 92 function tokenString(quote) { 93 return function(stream, state) { 94 var escaped = false, next, end = false; 95 while ((next = stream.next()) != null) { 96 if (next == quote && !escaped) { 97 end = true; 98 break; 99 } 100 escaped = !escaped && next == "\\"; 101 } 102 if (end) state.tokenize = tokenBase; 103 return "string"; 104 }; 105 } 106 function tokenComment(stream, state) { 107 var maybeEnd = false, ch; 108 while (ch = stream.next()) { 109 if (ch == "#" && maybeEnd) { 110 state.tokenize = tokenBase; 111 break; 112 } 113 maybeEnd = (ch == "*"); 114 } 115 return "comment"; 116 } 117 function tokenUnparsed(stream, state) { 118 var maybeEnd = 0, ch; 119 while (ch = stream.next()) { 120 if (ch == "#" && maybeEnd == 2) { 121 state.tokenize = tokenBase; 122 break; 123 } 124 if (ch == "]") 125 maybeEnd++; 126 else if (ch != " ") 127 maybeEnd = 0; 128 } 129 return "meta"; 130 } 131 return { 132 startState: function() { 133 return { 134 tokenize: tokenBase, 135 beforeParams: false, 136 inParams: false 137 }; 138 }, 139 token: function(stream, state) { 140 if (stream.eatSpace()) return null; 141 return state.tokenize(stream, state); 142 } 143 }; 144 }); 145 CodeMirror.defineMIME("text/x-tcl", "tcl"); 146 147 });