7
if (typeof exports == "object" && typeof module == "object")
8
mod(require("../../lib/codemirror"));
9
else if (typeof define == "function" && define.amd)
10
define(["../../lib/codemirror"], mod);
13
})(function(CodeMirror) {
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;
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 " +
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) {
39
return f(stream, state);
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;
51
} else if (/\d/.test(ch)) {
52
stream.eatWhile(/[\w\.]/);
54
} else if (ch == "#") {
56
return chain(stream, state, tokenComment);
57
if (ch == "#" && stream.match(/ *\[ *\[/))
58
return chain(stream, state, tokenUnparsed);
61
} else if (ch == '"') {
64
} else if (ch == "$") {
65
stream.eatWhile(/[$_a-z0-9A-Z\.{:]/);
67
state.beforeParams = true;
69
} else if (isOperatorChar.test(ch)) {
70
stream.eatWhile(isOperatorChar);
73
stream.eatWhile(/[\w\$_{}\xa1-\uffff]/);
74
var word = stream.current().toLowerCase();
75
if (keywords && keywords.propertyIsEnumerable(word))
77
if (functions && functions.propertyIsEnumerable(word)) {
78
state.beforeParams = true;
84
function tokenString(quote) {
85
return function(stream, state) {
86
var escaped = false, next, end = false;
87
while ((next = stream.next()) != null) {
88
if (next == quote && !escaped) {
92
escaped = !escaped && next == "\\";
94
if (end) state.tokenize = tokenBase;
98
function tokenComment(stream, state) {
99
var maybeEnd = false, ch;
100
while (ch = stream.next()) {
101
if (ch == "#" && maybeEnd) {
102
state.tokenize = tokenBase;
105
maybeEnd = (ch == "*");
109
function tokenUnparsed(stream, state) {
110
var maybeEnd = 0, ch;
111
while (ch = stream.next()) {
112
if (ch == "#" && maybeEnd == 2) {
113
state.tokenize = tokenBase;
124
startState: function() {
131
token: function(stream, state) {
132
if (stream.eatSpace()) return null;
133
return state.tokenize(stream, state);
138
CodeMirror.defineMIME("text/x-tcl", "tcl");