1
CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
3
var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
4
var keywords = /true|false|nil|self|super|thisContext/;
6
var Context = function(tokenizer, parent) {
11
var Token = function(name, context, eos) {
13
this.context = context;
17
var State = function() {
18
this.context = new Context(next, null);
19
this.expectVariable = true;
21
this.userIndentationDelta = 0;
24
State.prototype.userIndent = function(indentation) {
25
this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
28
var next = function(stream, context, state) {
29
var token = new Token(null, context, false);
30
var aChar = stream.next();
33
token = nextComment(stream, new Context(nextComment, context));
35
} else if (aChar === '\'') {
36
token = nextString(stream, new Context(nextString, context));
38
} else if (aChar === '#') {
39
stream.eatWhile(/[^ .]/);
40
token.name = 'string-2';
42
} else if (aChar === '$') {
43
stream.eatWhile(/[^ ]/);
44
token.name = 'string-2';
46
} else if (aChar === '|' && state.expectVariable) {
47
token.context = new Context(nextTemporaries, context);
49
} else if (/[\[\]{}()]/.test(aChar)) {
50
token.name = 'bracket';
51
token.eos = /[\[{(]/.test(aChar);
55
} else if (aChar === ']') {
56
state.indentation = Math.max(0, state.indentation - 1);
59
} else if (specialChars.test(aChar)) {
60
stream.eatWhile(specialChars);
61
token.name = 'operator';
62
token.eos = aChar !== ';'; // ; cascaded message expression
64
} else if (/\d/.test(aChar)) {
65
stream.eatWhile(/[\w\d]/);
68
} else if (/[\w_]/.test(aChar)) {
69
stream.eatWhile(/[\w\d_]/);
70
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
73
token.eos = state.expectVariable;
79
var nextComment = function(stream, context) {
80
stream.eatWhile(/[^"]/);
81
return new Token('comment', stream.eat('"') ? context.parent : context, true);
84
var nextString = function(stream, context) {
85
stream.eatWhile(/[^']/);
86
return new Token('string', stream.eat('\'') ? context.parent : context, false);
89
var nextTemporaries = function(stream, context, state) {
90
var token = new Token(null, context, false);
91
var aChar = stream.next();
94
token.context = context.parent;
98
stream.eatWhile(/[^|]/);
99
token.name = 'variable';
106
startState: function() {
110
token: function(stream, state) {
111
state.userIndent(stream.indentation());
113
if (stream.eatSpace()) {
117
var token = state.context.next(stream, state.context, state);
118
state.context = token.context;
119
state.expectVariable = token.eos;
121
state.lastToken = token;
125
blankLine: function(state) {
129
indent: function(state, textAfter) {
130
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
131
return (state.indentation + i) * config.indentUnit;
139
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
b'\\ No newline at end of file'