From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/codemirror/mode/smalltalk/index.html | 56 ++++++++++++++ js/codemirror/mode/smalltalk/smalltalk.js | 122 ++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 js/codemirror/mode/smalltalk/index.html create mode 100644 js/codemirror/mode/smalltalk/smalltalk.js (limited to 'js/codemirror/mode/smalltalk') diff --git a/js/codemirror/mode/smalltalk/index.html b/js/codemirror/mode/smalltalk/index.html new file mode 100644 index 00000000..67cb22b4 --- /dev/null +++ b/js/codemirror/mode/smalltalk/index.html @@ -0,0 +1,56 @@ + + + + CodeMirror 2: Smalltalk mode + + + + + + + + +

CodeMirror 2: Smalltalk mode

+ +
+ + + +

Simple Smalltalk mode.

+ +

MIME types defined: text/x-stsrc.

+ + diff --git a/js/codemirror/mode/smalltalk/smalltalk.js b/js/codemirror/mode/smalltalk/smalltalk.js new file mode 100644 index 00000000..a5b14e14 --- /dev/null +++ b/js/codemirror/mode/smalltalk/smalltalk.js @@ -0,0 +1,122 @@ +CodeMirror.defineMode("smalltalk", function(config, parserConfig) { + var keywords = {"true": 1, "false": 1, nil: 1, self: 1, "super": 1, thisContext: 1}; + var indentUnit = config.indentUnit; + + function chain(stream, state, f) { + state.tokenize = f; + return f(stream, state); + } + + var type; + function ret(tp, style) { + type = tp; + return style; + } + + function tokenBase(stream, state) { + var ch = stream.next(); + if (ch == '"') + return chain(stream, state, tokenComment(ch)); + else if (ch == "'") + return chain(stream, state, tokenString(ch)); + else if (ch == "#") { + stream.eatWhile(/[\w\$_]/); + return ret("string", "string"); + } + else if (/\d/.test(ch)) { + stream.eatWhile(/[\w\.]/) + return ret("number", "number"); + } + else if (/[\[\]()]/.test(ch)) { + return ret(ch, null); + } + else { + stream.eatWhile(/[\w\$_]/); + if (keywords && keywords.propertyIsEnumerable(stream.current())) return ret("keyword", "keyword"); + return ret("word", "variable"); + } + } + + function tokenString(quote) { + return function(stream, state) { + var escaped = false, next, end = false; + while ((next = stream.next()) != null) { + if (next == quote && !escaped) {end = true; break;} + escaped = !escaped && next == "\\"; + } + if (end || !(escaped)) + state.tokenize = tokenBase; + return ret("string", "string"); + }; + } + + function tokenComment(quote) { + return function(stream, state) { + var next, end = false; + while ((next = stream.next()) != null) { + if (next == quote) {end = true; break;} + } + if (end) + state.tokenize = tokenBase; + return ret("comment", "comment"); + }; + } + + function Context(indented, column, type, align, prev) { + this.indented = indented; + this.column = column; + this.type = type; + this.align = align; + this.prev = prev; + } + + function pushContext(state, col, type) { + return state.context = new Context(state.indented, col, type, null, state.context); + } + function popContext(state) { + return state.context = state.context.prev; + } + + // Interface + + return { + startState: function(basecolumn) { + return { + tokenize: tokenBase, + context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), + indented: 0, + startOfLine: true + }; + }, + + token: function(stream, state) { + var ctx = state.context; + if (stream.sol()) { + if (ctx.align == null) ctx.align = false; + state.indented = stream.indentation(); + state.startOfLine = true; + } + if (stream.eatSpace()) return null; + var style = state.tokenize(stream, state); + if (type == "comment") return style; + if (ctx.align == null) ctx.align = true; + + if (type == "[") pushContext(state, stream.column(), "]"); + else if (type == "(") pushContext(state, stream.column(), ")"); + else if (type == ctx.type) popContext(state); + state.startOfLine = false; + return style; + }, + + indent: function(state, textAfter) { + if (state.tokenize != tokenBase) return 0; + var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type; + if (ctx.align) return ctx.column + (closing ? 0 : 1); + else return ctx.indented + (closing ? 0 : indentUnit); + }, + + electricChars: "]" + }; +}); + +CodeMirror.defineMIME("text/x-stsrc", {name: "smalltalk"}); -- cgit v1.2.3