44 changes: 22 additions & 22 deletions mode/ntriples/ntriples.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/**********************************************************
* This script provides syntax highlighting support for
* This script provides syntax highlighting support for
* the Ntriples format.
* Ntriples format specification:
* Ntriples format specification:
* http://www.w3.org/TR/rdf-testcases/#ntriples
***********************************************************/

/*
/*
The following expression defines the defined ASF grammar transitions.
pre_subject ->
{
( writing_subject_uri | writing_bnode_uri )
-> pre_predicate
-> writing_predicate_uri
-> pre_object
-> writing_object_uri | writing_object_bnode |
(
writing_object_literal
-> pre_predicate
-> writing_predicate_uri
-> pre_object
-> writing_object_uri | writing_object_bnode |
(
writing_object_literal
-> writing_literal_lang | writing_literal_type
)
-> post_object
Expand All @@ -25,7 +25,7 @@
-> ERROR
}
*/
CodeMirror.defineMode("ntriples", function() {
CodeMirror.defineMode("ntriples", function() {

var Location = {
PRE_SUBJECT : 0,
Expand All @@ -45,15 +45,15 @@ CodeMirror.defineMode("ntriples", function() {
function transitState(currState, c) {
var currLocation = currState.location;
var ret;

// Opening.
if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI;
else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI;
else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI;
else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI;
else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE;
else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL;

// Closing.
else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED;
else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED;
Expand All @@ -63,33 +63,33 @@ CodeMirror.defineMode("ntriples", function() {
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ;
else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ;
else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ;

// Closing typed and language literal.
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG;
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE;

// Spaces.
else if( c == ' ' &&
else if( c == ' ' &&
(
currLocation == Location.PRE_SUBJECT ||
currLocation == Location.PRE_PRED ||
currLocation == Location.PRE_OBJ ||
currLocation == Location.PRE_SUBJECT ||
currLocation == Location.PRE_PRED ||
currLocation == Location.PRE_OBJ ||
currLocation == Location.POST_OBJ
)
) ret = currLocation;

// Reset.
else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;
else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;

// Error
else ret = Location.ERROR;

currState.location=ret;
}

return {
startState: function() {
return {
return {
location : Location.PRE_SUBJECT,
uris : [],
anchors : [],
Expand Down
2 changes: 1 addition & 1 deletion mode/ocaml/ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ CodeMirror.defineMode('ocaml', function() {
}
};
});

CodeMirror.defineMIME('text/x-ocaml', 'ocaml');
1,582 changes: 791 additions & 791 deletions mode/perl/perl.js

Large diffs are not rendered by default.

326 changes: 163 additions & 163 deletions mode/pig/pig.js
Original file line number Diff line number Diff line change
@@ -1,171 +1,171 @@
/*
* Pig Latin Mode for CodeMirror 2
* @author Prasanth Jayachandran
* @link https://github.com/prasanthj/pig-codemirror-2
* Pig Latin Mode for CodeMirror 2
* @author Prasanth Jayachandran
* @link https://github.com/prasanthj/pig-codemirror-2
* This implementation is adapted from PL/SQL mode in CodeMirror 2.
*/
*/
CodeMirror.defineMode("pig", function(_config, parserConfig) {
var keywords = parserConfig.keywords,
builtins = parserConfig.builtins,
types = parserConfig.types,
multiLineStrings = parserConfig.multiLineStrings;
var isOperatorChar = /[*+\-%<>=&?:\/!|]/;
function chain(stream, state, f) {
state.tokenize = f;
return f(stream, state);
}
var type;
function ret(tp, style) {
type = tp;
return style;
}
function tokenComment(stream, state) {
var isEnd = false;
var ch;
while(ch = stream.next()) {
if(ch == "/" && isEnd) {
state.tokenize = tokenBase;
break;
}
isEnd = (ch == "*");
}
return ret("comment", "comment");
}
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 || multiLineStrings))
state.tokenize = tokenBase;
return ret("string", "error");
};
}
function tokenBase(stream, state) {
var ch = stream.next();
// is a start of string?
if (ch == '"' || ch == "'")
return chain(stream, state, tokenString(ch));
// is it one of the special chars
else if(/[\[\]{}\(\),;\.]/.test(ch))
return ret(ch);
// is it a number?
else if(/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return ret("number", "number");
}
// multi line comment or operator
else if (ch == "/") {
if (stream.eat("*")) {
return chain(stream, state, tokenComment);
}
else {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
}
// single line comment or operator
else if (ch=="-") {
if(stream.eat("-")){
stream.skipToEnd();
return ret("comment", "comment");
}
else {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
}
// is it an operator
else if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
else {
// get the while word
stream.eatWhile(/[\w\$_]/);
// is it one of the listed keywords?
if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) {
if (stream.eat(")") || stream.eat(".")) {
//keywords can be used as variables like flatten(group), group.$0 etc..
}
else {
return ("keyword", "keyword");
}
}
// is it one of the builtin functions?
if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase()))
{
return ("keyword", "variable-2");
}
// is it one of the listed types?
if (types && types.propertyIsEnumerable(stream.current().toUpperCase()))
return ("keyword", "variable-3");
// default is a 'variable'
return ret("variable", "pig-word");
}
}
// Interface
return {
startState: function() {
return {
tokenize: tokenBase,
startOfLine: true
};
},
token: function(stream, state) {
if(stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
return style;
}
};
var keywords = parserConfig.keywords,
builtins = parserConfig.builtins,
types = parserConfig.types,
multiLineStrings = parserConfig.multiLineStrings;

var isOperatorChar = /[*+\-%<>=&?:\/!|]/;

function chain(stream, state, f) {
state.tokenize = f;
return f(stream, state);
}

var type;
function ret(tp, style) {
type = tp;
return style;
}

function tokenComment(stream, state) {
var isEnd = false;
var ch;
while(ch = stream.next()) {
if(ch == "/" && isEnd) {
state.tokenize = tokenBase;
break;
}
isEnd = (ch == "*");
}
return ret("comment", "comment");
}

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 || multiLineStrings))
state.tokenize = tokenBase;
return ret("string", "error");
};
}

function tokenBase(stream, state) {
var ch = stream.next();

// is a start of string?
if (ch == '"' || ch == "'")
return chain(stream, state, tokenString(ch));
// is it one of the special chars
else if(/[\[\]{}\(\),;\.]/.test(ch))
return ret(ch);
// is it a number?
else if(/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return ret("number", "number");
}
// multi line comment or operator
else if (ch == "/") {
if (stream.eat("*")) {
return chain(stream, state, tokenComment);
}
else {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
}
// single line comment or operator
else if (ch=="-") {
if(stream.eat("-")){
stream.skipToEnd();
return ret("comment", "comment");
}
else {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
}
// is it an operator
else if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator");
}
else {
// get the while word
stream.eatWhile(/[\w\$_]/);
// is it one of the listed keywords?
if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) {
if (stream.eat(")") || stream.eat(".")) {
//keywords can be used as variables like flatten(group), group.$0 etc..
}
else {
return ("keyword", "keyword");
}
}
// is it one of the builtin functions?
if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase()))
{
return ("keyword", "variable-2");
}
// is it one of the listed types?
if (types && types.propertyIsEnumerable(stream.current().toUpperCase()))
return ("keyword", "variable-3");
// default is a 'variable'
return ret("variable", "pig-word");
}
}

// Interface
return {
startState: function() {
return {
tokenize: tokenBase,
startOfLine: true
};
},

token: function(stream, state) {
if(stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
return style;
}
};
});

(function() {
function keywords(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}
function keywords(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}

// builtin funcs taken from trunk revision 1303237
var pBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
+ "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
+ "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
+ "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
+ "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
+ "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
+ "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
+ "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
+ "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
+ "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER ";

// taken from QueryLexer.g
var pKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
+ "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
+ "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
+ "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
+ "NEQ MATCHES TRUE FALSE ";

// data types
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP ";

// builtin funcs taken from trunk revision 1303237
var pBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
+ "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
+ "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
+ "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
+ "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
+ "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
+ "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
+ "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
+ "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
+ "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER ";

// taken from QueryLexer.g
var pKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
+ "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
+ "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
+ "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
+ "NEQ MATCHES TRUE FALSE ";

// data types
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP ";

CodeMirror.defineMIME("text/x-pig", {
name: "pig",
builtins: keywords(pBuiltins),
keywords: keywords(pKeywords),
types: keywords(pTypes)
});
CodeMirror.defineMIME("text/x-pig", {
name: "pig",
builtins: keywords(pBuiltins),
keywords: keywords(pKeywords),
types: keywords(pTypes)
});
}());
48 changes: 24 additions & 24 deletions mode/python/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}

var singleOperators = parserConf.singleOperators || new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
var singleDelimiters = parserConf.singleDelimiters || new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = parserConf.doubleOperators || new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
Expand Down Expand Up @@ -72,15 +72,15 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (stream.eatSpace()) {
return null;
}

var ch = stream.peek();

// Handle Comments
if (ch === '#') {
stream.skipToEnd();
return 'comment';
}

// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var floatLiteral = false;
Expand Down Expand Up @@ -116,13 +116,13 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return 'number';
}
}

// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
return state.tokenize(stream, state);
}

// Handle operators and Delimiters
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
return null;
Expand All @@ -135,31 +135,31 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (stream.match(singleDelimiters)) {
return null;
}

if (stream.match(keywords)) {
return 'keyword';
}

if (stream.match(builtins)) {
return 'builtin';
}

if (stream.match(identifiers)) {
return 'variable';
}

// Handle non-detected items
stream.next();
return ERRORCLASS;
}

function tokenStringFactory(delimiter) {
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';

function tokenString(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/);
Expand Down Expand Up @@ -187,7 +187,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
tokenString.isString = true;
return tokenString;
}

function indent(stream, state, type) {
type = type || 'py';
var indentUnit = 0;
Expand All @@ -210,7 +210,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
type: type
});
}

function dedent(stream, state, type) {
type = type || 'py';
if (state.scopes.length == 1) return;
Expand Down Expand Up @@ -259,7 +259,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
}
return style;
}

// Handle decorators
if (current === '@') {
return stream.match(identifiers, false) ? 'meta' : ERRORCLASS;
Expand All @@ -269,7 +269,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
&& state.lastToken === 'meta') {
style = 'meta';
}

// Handle scope changes.
if (current === 'pass' || current === 'return') {
state.dedent += 1;
Expand Down Expand Up @@ -298,7 +298,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (state.scopes.length > 1) state.scopes.shift();
state.dedent -= 1;
}

return style;
}

Expand All @@ -312,27 +312,27 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
dedent: 0
};
},

token: function(stream, state) {
var style = tokenLexer(stream, state);

state.lastToken = style;

if (stream.eol() && stream.lambda) {
state.lambda = false;
}

return style;
},

indent: function(state) {
if (state.tokenize != tokenBase) {
return state.tokenize.isString ? CodeMirror.Pass : 0;
}

return state.scopes[0].offset;
}

};
return external;
});
Expand Down
2 changes: 1 addition & 1 deletion mode/q/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CodeMirror.defineMode("q",function(config){
return state.tokenize=tokenBase,"builtin";
}
if(/\s/.test(c))
return stream.peek()=="/"?(stream.skipToEnd(),"comment"):"whitespace";
return stream.peek()=="/"?(stream.skipToEnd(),"comment"):"whitespace";
if(c=='"')
return(state.tokenize=tokenString)(stream,state);
if(c=='`')
Expand Down
6 changes: 3 additions & 3 deletions mode/rst/rst.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ CodeMirror.defineMode('rst', function (config, options) {
rx_uri_protocol + rx_uri_domain + rx_uri_path
);

var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*/;
var rx_emphasis = /^\*[^\*\s](?:[^\*]*[^\*\s])?\*/;
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``/;
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*(\s+|$)/;
var rx_emphasis = /^[^\*]\*[^\*\s](?:[^\*]*[^\*\s])?\*(\s+|$)/;
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``(\s+|$)/;

var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
Expand Down
4 changes: 2 additions & 2 deletions mode/sass/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ CodeMirror.defineMode("sass", function(config) {
// If we haven't returned by now, we move 1 character
// and return an error
stream.next();
return 'error';
return null;
};

var tokenLexer = function(stream, state) {
Expand All @@ -302,7 +302,7 @@ CodeMirror.defineMode("sass", function(config) {
indent(state);
}

if (style !== "error"){
if (style !== null){
var startOfToken = stream.pos - current.length;
var withCurrentIndent = startOfToken + (config.indentUnit * state.indentCount);

Expand Down
4 changes: 2 additions & 2 deletions mode/shell/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CodeMirror.defineMode('shell', function() {
return 'number';
}
}
stream.eatWhile(/\w/);
stream.eatWhile(/[\w-]/);
var cur = stream.current();
if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
return words.hasOwnProperty(cur) ? words[cur] : null;
Expand Down Expand Up @@ -114,5 +114,5 @@ CodeMirror.defineMode('shell', function() {
}
};
});

CodeMirror.defineMIME('text/x-sh', 'shell');
20 changes: 10 additions & 10 deletions mode/sieve/sieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CodeMirror.defineMode("sieve", function(config) {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}

if (ch == "(") {
state._indent.push("(");
// add virtual angel wings so that editor behaves...
Expand All @@ -44,24 +44,24 @@ CodeMirror.defineMode("sieve", function(config) {
state._indent.push("{");
return null;
}

if (ch == ")") {
state._indent.pop();
state._indent.pop();
state._indent.pop();
}

if (ch === "}") {
state._indent.pop();
return null;
}

if (ch == ",")
return null;

if (ch == ";")
return null;


if (/[{}\(\),;]/.test(ch))
return null;

Expand Down Expand Up @@ -97,7 +97,7 @@ CodeMirror.defineMode("sieve", function(config) {

if (atoms.propertyIsEnumerable(cur))
return "atom";

return null;
}

Expand Down Expand Up @@ -169,10 +169,10 @@ CodeMirror.defineMode("sieve", function(config) {
var length = state._indent.length;
if (_textAfter && (_textAfter[0] == "}"))
length--;

if (length <0)
length = 0;

return length * indentUnit;
},

Expand Down
258 changes: 129 additions & 129 deletions mode/smalltalk/smalltalk.js
Original file line number Diff line number Diff line change
@@ -1,139 +1,139 @@
CodeMirror.defineMode('smalltalk', function(config) {

var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
var keywords = /true|false|nil|self|super|thisContext/;

var Context = function(tokenizer, parent) {
this.next = tokenizer;
this.parent = parent;
};

var Token = function(name, context, eos) {
this.name = name;
this.context = context;
this.eos = eos;
};

var State = function() {
this.context = new Context(next, null);
this.expectVariable = true;
this.indentation = 0;
this.userIndentationDelta = 0;
};

State.prototype.userIndent = function(indentation) {
this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
};

var next = function(stream, context, state) {
var token = new Token(null, context, false);
var aChar = stream.next();

if (aChar === '"') {
token = nextComment(stream, new Context(nextComment, context));

} else if (aChar === '\'') {
token = nextString(stream, new Context(nextString, context));

} else if (aChar === '#') {
stream.eatWhile(/[^ .]/);
token.name = 'string-2';

} else if (aChar === '$') {
stream.eatWhile(/[^ ]/);
token.name = 'string-2';

} else if (aChar === '|' && state.expectVariable) {
token.context = new Context(nextTemporaries, context);

} else if (/[\[\]{}()]/.test(aChar)) {
token.name = 'bracket';
token.eos = /[\[{(]/.test(aChar);

if (aChar === '[') {
state.indentation++;
} else if (aChar === ']') {
state.indentation = Math.max(0, state.indentation - 1);
}

} else if (specialChars.test(aChar)) {
stream.eatWhile(specialChars);
token.name = 'operator';
token.eos = aChar !== ';'; // ; cascaded message expression

} else if (/\d/.test(aChar)) {
stream.eatWhile(/[\w\d]/);
token.name = 'number';

} else if (/[\w_]/.test(aChar)) {
stream.eatWhile(/[\w\d_]/);
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;

} else {
token.eos = state.expectVariable;
}

return token;
};

var nextComment = function(stream, context) {
stream.eatWhile(/[^"]/);
return new Token('comment', stream.eat('"') ? context.parent : context, true);
};

var nextString = function(stream, context) {
stream.eatWhile(/[^']/);
return new Token('string', stream.eat('\'') ? context.parent : context, false);
};

var nextTemporaries = function(stream, context) {
var token = new Token(null, context, false);
var aChar = stream.next();

if (aChar === '|') {
token.context = context.parent;
token.eos = true;

} else {
stream.eatWhile(/[^|]/);
token.name = 'variable';
}

return token;
};

return {
startState: function() {
return new State;
},

token: function(stream, state) {
state.userIndent(stream.indentation());

if (stream.eatSpace()) {
return null;
}
var specialChars = /[+\-\/\\*~<>=@%|&?!.:;^]/;
var keywords = /true|false|nil|self|super|thisContext/;

var Context = function(tokenizer, parent) {
this.next = tokenizer;
this.parent = parent;
};

var Token = function(name, context, eos) {
this.name = name;
this.context = context;
this.eos = eos;
};

var State = function() {
this.context = new Context(next, null);
this.expectVariable = true;
this.indentation = 0;
this.userIndentationDelta = 0;
};

State.prototype.userIndent = function(indentation) {
this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
};

var next = function(stream, context, state) {
var token = new Token(null, context, false);
var aChar = stream.next();

if (aChar === '"') {
token = nextComment(stream, new Context(nextComment, context));

} else if (aChar === '\'') {
token = nextString(stream, new Context(nextString, context));

} else if (aChar === '#') {
stream.eatWhile(/[^ .]/);
token.name = 'string-2';

} else if (aChar === '$') {
stream.eatWhile(/[^ ]/);
token.name = 'string-2';

} else if (aChar === '|' && state.expectVariable) {
token.context = new Context(nextTemporaries, context);

} else if (/[\[\]{}()]/.test(aChar)) {
token.name = 'bracket';
token.eos = /[\[{(]/.test(aChar);

if (aChar === '[') {
state.indentation++;
} else if (aChar === ']') {
state.indentation = Math.max(0, state.indentation - 1);
}

} else if (specialChars.test(aChar)) {
stream.eatWhile(specialChars);
token.name = 'operator';
token.eos = aChar !== ';'; // ; cascaded message expression

} else if (/\d/.test(aChar)) {
stream.eatWhile(/[\w\d]/);
token.name = 'number';

} else if (/[\w_]/.test(aChar)) {
stream.eatWhile(/[\w\d_]/);
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;

} else {
token.eos = state.expectVariable;
}

return token;
};

var nextComment = function(stream, context) {
stream.eatWhile(/[^"]/);
return new Token('comment', stream.eat('"') ? context.parent : context, true);
};

var nextString = function(stream, context) {
stream.eatWhile(/[^']/);
return new Token('string', stream.eat('\'') ? context.parent : context, false);
};

var nextTemporaries = function(stream, context) {
var token = new Token(null, context, false);
var aChar = stream.next();

if (aChar === '|') {
token.context = context.parent;
token.eos = true;

} else {
stream.eatWhile(/[^|]/);
token.name = 'variable';
}

return token;
};

return {
startState: function() {
return new State;
},

token: function(stream, state) {
state.userIndent(stream.indentation());

if (stream.eatSpace()) {
return null;
}

var token = state.context.next(stream, state.context, state);
state.context = token.context;
state.expectVariable = token.eos;
var token = state.context.next(stream, state.context, state);
state.context = token.context;
state.expectVariable = token.eos;

state.lastToken = token;
return token.name;
},
state.lastToken = token;
return token.name;
},

blankLine: function(state) {
state.userIndent(0);
},
blankLine: function(state) {
state.userIndent(0);
},

indent: function(state, textAfter) {
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
return (state.indentation + i) * config.indentUnit;
},
indent: function(state, textAfter) {
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
return (state.indentation + i) * config.indentUnit;
},

electricChars: ']'
};
electricChars: ']'
};

});

CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
6 changes: 3 additions & 3 deletions mode/smarty/smarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CodeMirror.defineMode("smarty", function(config) {

var str = "";
if (ch != "/") {
str += ch;
str += ch;
}
var c = "";
while ((c = stream.eat(regs.validIdentifier))) {
Expand All @@ -101,7 +101,7 @@ CodeMirror.defineMode("smarty", function(config) {
}
}
if (/\s/.test(ch)) {
return null;
return null;
}
return ret("tag", "tag");
}
Expand Down Expand Up @@ -145,4 +145,4 @@ CodeMirror.defineMode("smarty", function(config) {
};
});

CodeMirror.defineMIME("text/x-smarty", "smarty");
CodeMirror.defineMIME("text/x-smarty", "smarty");
2 changes: 1 addition & 1 deletion mode/sparql/sparql.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CodeMirror.defineMode("sparql", function(config) {
state.context.col = stream.column();
}
}

return style;
},

Expand Down
44 changes: 22 additions & 22 deletions mode/sql/sql.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mode/tcl/tcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CodeMirror.defineMode("tcl", function() {
else if (ch == "$") {
stream.eatWhile(/[$_a-z0-9A-Z\.{:]/);
stream.eatWhile(/}/);
state.beforeParams = true;
state.beforeParams = true;
return "builtin";
}
else if (isOperatorChar.test(ch)) {
Expand Down
690 changes: 345 additions & 345 deletions mode/tiddlywiki/tiddlywiki.js

Large diffs are not rendered by default.

595 changes: 297 additions & 298 deletions mode/tiki/tiki.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions mode/turtle/turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ CodeMirror.defineMode("turtle", function(config) {
return null;
}
else if (ch == ":") {
return "operator";
} else {
return "operator";
} else {
stream.eatWhile(/[_\w\d]/);
if(stream.peek() == ":") {
return "variable-3";
} else {
var word = stream.current();
if(keywords.test(word)) {
return "meta";
}
if(ch >= "A" && ch <= "Z") {
return "comment";
} else {
return "keyword";
}
var word = stream.current();

if(keywords.test(word)) {
return "meta";
}

if(ch >= "A" && ch <= "Z") {
return "comment";
} else {
return "keyword";
}
}
var word = stream.current();
if (ops.test(word))
Expand Down Expand Up @@ -119,7 +119,7 @@ CodeMirror.defineMode("turtle", function(config) {
state.context.col = stream.column();
}
}

return style;
},

Expand Down
61 changes: 30 additions & 31 deletions mode/vb/vb.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CodeMirror.defineMode("vb", function(conf, parserConf) {
var ERRORCLASS = 'error';

function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
}

var singleOperators = new RegExp("^[\\+\\-\\*/%&\\\\|\\^~<>!]");
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(<>)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
Expand All @@ -15,9 +15,9 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try'];
var middleKeywords = ['else','elseif','case', 'catch'];
var endKeywords = ['next','loop'];

var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'in']);
var commonkeywords = ['as', 'dim', 'break', 'continue','optional', 'then', 'until',
var commonkeywords = ['as', 'dim', 'break', 'continue','optional', 'then', 'until',
'goto', 'byval','byref','new','handles','property', 'return',
'const','private', 'protected', 'friend', 'public', 'shared', 'static', 'true','false'];
var commontypes = ['integer','string','double','decimal','boolean','short','char', 'float','single'];
Expand All @@ -34,13 +34,13 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {

var indentInfo = null;




function indent(_stream, state) {
state.currentIndent++;
}

function dedent(_stream, state) {
state.currentIndent--;
}
Expand All @@ -49,24 +49,24 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
if (stream.eatSpace()) {
return null;
}

var ch = stream.peek();

// Handle Comments
if (ch === "'") {
stream.skipToEnd();
return 'comment';
}


// Handle Number Literals
if (stream.match(/^((&H)|(&O))?[0-9\.a-f]/i, false)) {
var floatLiteral = false;
// Floats
if (stream.match(/^\d*\.\d+F?/i)) { floatLiteral = true; }
else if (stream.match(/^\d+\.\d*F?/)) { floatLiteral = true; }
else if (stream.match(/^\.\d+F?/)) { floatLiteral = true; }

if (floatLiteral) {
// Float literals may be "imaginary"
stream.eat(/J/i);
Expand All @@ -93,13 +93,13 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
return 'number';
}
}

// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
return state.tokenize(stream, state);
}

// Handle operators and Delimiters
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
return null;
Expand Down Expand Up @@ -137,28 +137,28 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
dedent(stream,state);
return 'keyword';
}

if (stream.match(types)) {
return 'keyword';
}

if (stream.match(keywords)) {
return 'keyword';
}

if (stream.match(identifiers)) {
return 'variable';
}

// Handle non-detected items
stream.next();
return ERRORCLASS;
}

function tokenStringFactory(delimiter) {
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';

return function(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"]/);
Expand All @@ -179,7 +179,7 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
return OUTCLASS;
};
}


function tokenLexer(stream, state) {
var style = state.tokenize(stream, state);
Expand All @@ -195,8 +195,8 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
return ERRORCLASS;
}
}


var delimiter_index = '[({'.indexOf(current);
if (delimiter_index !== -1) {
indent(stream, state );
Expand All @@ -212,7 +212,7 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
return ERRORCLASS;
}
}

return style;
}

Expand All @@ -229,32 +229,31 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {

};
},

token: function(stream, state) {
if (stream.sol()) {
state.currentIndent += state.nextLineIndent;
state.nextLineIndent = 0;
state.doInCurrentLine = 0;
}
var style = tokenLexer(stream, state);

state.lastToken = {style:style, content: stream.current()};



return style;
},

indent: function(state, textAfter) {
var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;
if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);
if(state.currentIndent < 0) return 0;
return state.currentIndent * conf.indentUnit;
}

};
return external;
});

CodeMirror.defineMIME("text/x-vb", "vb");

8 changes: 4 additions & 4 deletions mode/vbscript/vbscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ CodeMirror.defineMode("vbscript", function() {
if (stream.eatSpace()) return null;
var ch = stream.next();
if (ch == "'") {
stream.skipToEnd();
return "comment";
stream.skipToEnd();
return "comment";
}
if (ch == '"') {
stream.skipTo('"');
return "string";
stream.skipTo('"');
return "string";
}

if (/\w/.test(ch)) {
Expand Down
2 changes: 1 addition & 1 deletion mode/xml/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var ok;
if (stream.eat("#")) {
if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
}
Expand Down
110 changes: 55 additions & 55 deletions mode/xquery/xquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ CodeMirror.defineMode("xquery", function() {
, atom = {type: "atom", style: "atom"}
, punctuation = {type: "punctuation", style: null}
, qualifier = {type: "axis_specifier", style: "qualifier"};

// kwObj is what is return from this function at the end
var kwObj = {
'if': A, 'switch': A, 'while': A, 'for': A,
'else': B, 'then': B, 'try': B, 'finally': B, 'catch': B,
'element': C, 'attribute': C, 'let': C, 'implements': C, 'import': C, 'module': C, 'namespace': C,
'return': C, 'super': C, 'this': C, 'throws': C, 'where': C, 'private': C,
'element': C, 'attribute': C, 'let': C, 'implements': C, 'import': C, 'module': C, 'namespace': C,
'return': C, 'super': C, 'this': C, 'throws': C, 'where': C, 'private': C,
',': punctuation,
'null': atom, 'fn:false()': atom, 'fn:true()': atom
};
// a list of 'basic' keywords. For each add a property to kwObj with the value of

// a list of 'basic' keywords. For each add a property to kwObj with the value of
// {type: basic[i], style: "keyword"} e.g. 'after' --> {type: "after", style: "keyword"}
var basic = ['after','ancestor','ancestor-or-self','and','as','ascending','assert','attribute','before',
'by','case','cast','child','comment','declare','default','define','descendant','descendant-or-self',
Expand All @@ -57,20 +57,20 @@ CodeMirror.defineMode("xquery", function() {
'self','some','sortby','stable','text','then','to','treat','typeswitch','union','variable','version','where',
'xquery', 'empty-sequence'];
for(var i=0, l=basic.length; i < l; i++) { kwObj[basic[i]] = kw(basic[i]);};
// a list of types. For each add a property to kwObj with the value of

// a list of types. For each add a property to kwObj with the value of
// {type: "atom", style: "atom"}
var types = ['xs:string', 'xs:float', 'xs:decimal', 'xs:double', 'xs:integer', 'xs:boolean', 'xs:date', 'xs:dateTime',
'xs:time', 'xs:duration', 'xs:dayTimeDuration', 'xs:time', 'xs:yearMonthDuration', 'numeric', 'xs:hexBinary',
var types = ['xs:string', 'xs:float', 'xs:decimal', 'xs:double', 'xs:integer', 'xs:boolean', 'xs:date', 'xs:dateTime',
'xs:time', 'xs:duration', 'xs:dayTimeDuration', 'xs:time', 'xs:yearMonthDuration', 'numeric', 'xs:hexBinary',
'xs:base64Binary', 'xs:anyURI', 'xs:QName', 'xs:byte','xs:boolean','xs:anyURI','xf:yearMonthDuration'];
for(var i=0, l=types.length; i < l; i++) { kwObj[types[i]] = atom;};

// each operator will add a property to kwObj with value of {type: "operator", style: "keyword"}
var operators = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', ':=', '=', '>', '>=', '<', '<=', '.', '|', '?', 'and', 'or', 'div', 'idiv', 'mod', '*', '/', '+', '-'];
for(var i=0, l=operators.length; i < l; i++) { kwObj[operators[i]] = operator;};

// each axis_specifiers will add a property to kwObj with value of {type: "axis_specifier", style: "qualifier"}
var axis_specifiers = ["self::", "attribute::", "child::", "descendant::", "descendant-or-self::", "parent::",
var axis_specifiers = ["self::", "attribute::", "child::", "descendant::", "descendant-or-self::", "parent::",
"ancestor::", "ancestor-or-self::", "following::", "preceding::", "following-sibling::", "preceding-sibling::"];
for(var i=0, l=axis_specifiers.length; i < l; i++) { kwObj[axis_specifiers[i]] = qualifier; };

Expand All @@ -80,42 +80,42 @@ CodeMirror.defineMode("xquery", function() {
// Used as scratch variables to communicate multiple values without
// consing up tons of objects.
var type, content;

function ret(tp, style, cont) {
type = tp; content = cont;
return style;
}

function chain(stream, state, f) {
state.tokenize = f;
return f(stream, state);
}

// the primary mode tokenizer
function tokenBase(stream, state) {
var ch = stream.next(),
var ch = stream.next(),
mightBeFunction = false,
isEQName = isEQNameAhead(stream);

// an XML tag (if not in some sub, chained tokenizer)
if (ch == "<") {
if(stream.match("!--", true))
return chain(stream, state, tokenXMLComment);

if(stream.match("![CDATA", false)) {
state.tokenize = tokenCDATA;
return ret("tag", "tag");
}

if(stream.match("?", false)) {
return chain(stream, state, tokenPreProcessing);
}

var isclose = stream.eat("/");
stream.eatSpace();
var tagName = "", c;
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;

return chain(stream, state, tokenTag(tagName, isclose));
}
// start code block
Expand All @@ -136,7 +136,7 @@ CodeMirror.defineMode("xquery", function() {
popStateStack(state);
return ret("tag", "tag");
}
else
else
return ret("word", "variable");
}
// if a number
Expand Down Expand Up @@ -186,13 +186,13 @@ CodeMirror.defineMode("xquery", function() {
// if there's a EQName ahead, consume the rest of the string portion, it's likely a function
if(isEQName && ch === '\"') while(stream.next() !== '"'){}
if(isEQName && ch === '\'') while(stream.next() !== '\''){}

// gobble up a word if the character is not known
if(!known) stream.eatWhile(/[\w\$_-]/);

// gobble a colon in the case that is a lib func type call fn:doc
var foundColon = stream.eat(":");

// if there's not a second colon, gobble another word. Otherwise, it's probably an axis specifier
// which should get matched as a keyword
if(!stream.eat(":") && foundColon) {
Expand All @@ -205,27 +205,27 @@ CodeMirror.defineMode("xquery", function() {
// is the word a keyword?
var word = stream.current();
known = keywords.propertyIsEnumerable(word) && keywords[word];
// if we think it's a function call but not yet known,

// if we think it's a function call but not yet known,
// set style to variable for now for lack of something better
if(mightBeFunction && !known) known = {type: "function_call", style: "variable def"};

// if the previous word was element, attribute, axis specifier, this word should be the name of that
if(isInXmlConstructor(state)) {
popStateStack(state);
return ret("word", "variable", word);
}
// as previously checked, if the word is element,attribute, axis specifier, call it an "xmlconstructor" and
// as previously checked, if the word is element,attribute, axis specifier, call it an "xmlconstructor" and
// push the stack so we know to look for it on the next word
if(word == "element" || word == "attribute" || known.type == "axis_specifier") pushStateStack(state, {type: "xmlconstructor"});

// if the word is known, return the details of that else just call this a generic 'word'
return known ? ret(known.type, known.style, word) :
ret("word", "variable", word);
}
}

// handle comments, including nested
// handle comments, including nested
function tokenComment(stream, state) {
var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;
while (ch = stream.next()) {
Expand All @@ -243,7 +243,7 @@ CodeMirror.defineMode("xquery", function() {
maybeEnd = (ch == ":");
maybeNested = (ch == "(");
}

return ret("comment", "comment");
}

Expand All @@ -264,10 +264,10 @@ CodeMirror.defineMode("xquery", function() {
// if we're in a string and in an XML block, allow an embedded code block
if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
state.tokenize = tokenBase;
return ret("string", "string");
return ret("string", "string");
}


while (ch = stream.next()) {
if (ch == quote) {
popStateStack(state);
Expand All @@ -278,16 +278,16 @@ CodeMirror.defineMode("xquery", function() {
// if we're in a string and in an XML block, allow an embedded code block in an attribute
if(stream.match("{", false) && isInXmlAttributeBlock(state)) {
state.tokenize = tokenBase;
return ret("string", "string");
return ret("string", "string");
}

}
}

return ret("string", "string");
};
}

// tokenizer for variables
function tokenVariable(stream, state) {
var isVariableChar = /[\w\$_-]/;
Expand All @@ -304,7 +304,7 @@ CodeMirror.defineMode("xquery", function() {
state.tokenize = tokenBase;
return ret("variable", "variable");
}

// tokenizer for XML tags
function tokenTag(name, isclose) {
return function(stream, state) {
Expand All @@ -322,7 +322,7 @@ CodeMirror.defineMode("xquery", function() {
return ret("tag", "tag");
}
else {
state.tokenize = tokenBase;
state.tokenize = tokenBase;
}
return ret("tag", "tag");
};
Expand All @@ -331,7 +331,7 @@ CodeMirror.defineMode("xquery", function() {
// tokenizer for XML attributes
function tokenAttribute(stream, state) {
var ch = stream.next();

if(ch == "/" && stream.eat(">")) {
if(isInXmlAttributeBlock(state)) popStateStack(state);
if(isInXmlBlock(state)) popStateStack(state);
Expand All @@ -347,7 +347,7 @@ CodeMirror.defineMode("xquery", function() {
if (ch == '"' || ch == "'")
return chain(stream, state, tokenString(ch, tokenAttribute));

if(!isInXmlAttributeBlock(state))
if(!isInXmlAttributeBlock(state))
pushStateStack(state, { type: "attribute", name: name, tokenize: tokenAttribute});

stream.eat(/[a-zA-Z_:]/);
Expand All @@ -357,18 +357,18 @@ CodeMirror.defineMode("xquery", function() {
// the case where the attribute has not value and the tag was closed
if(stream.match(">", false) || stream.match("/", false)) {
popStateStack(state);
state.tokenize = tokenBase;
state.tokenize = tokenBase;
}

return ret("attribute", "attribute");
}
// handle comments, including nested

// handle comments, including nested
function tokenXMLComment(stream, state) {
var ch;
while (ch = stream.next()) {
if (ch == "-" && stream.match("->", true)) {
state.tokenize = tokenBase;
state.tokenize = tokenBase;
return ret("comment", "comment");
}
}
Expand All @@ -380,7 +380,7 @@ CodeMirror.defineMode("xquery", function() {
var ch;
while (ch = stream.next()) {
if (ch == "]" && stream.match("]", true)) {
state.tokenize = tokenBase;
state.tokenize = tokenBase;
return ret("comment", "comment");
}
}
Expand All @@ -391,20 +391,20 @@ CodeMirror.defineMode("xquery", function() {
var ch;
while (ch = stream.next()) {
if (ch == "?" && stream.match(">", true)) {
state.tokenize = tokenBase;
state.tokenize = tokenBase;
return ret("comment", "comment meta");
}
}
}


// functions to test the current context of the state
function isInXmlBlock(state) { return isIn(state, "tag"); }
function isInXmlAttributeBlock(state) { return isIn(state, "attribute"); }
function isInXmlConstructor(state) { return isIn(state, "xmlconstructor"); }
function isInString(state) { return isIn(state, "string"); }

function isEQNameAhead(stream) {
function isEQNameAhead(stream) {
// assume we've already eaten a quote (")
if(stream.current() === '"')
return stream.match(/^[^\"]+\"\:/, false);
Expand All @@ -413,21 +413,21 @@ CodeMirror.defineMode("xquery", function() {
else
return false;
}

function isIn(state, type) {
return (state.stack.length && state.stack[state.stack.length - 1].type == type);
return (state.stack.length && state.stack[state.stack.length - 1].type == type);
}

function pushStateStack(state, newState) {
state.stack.push(newState);
}

function popStateStack(state) {
state.stack.pop();
var reinstateTokenize = state.stack.length && state.stack[state.stack.length-1].tokenize;
state.tokenize = reinstateTokenize || tokenBase;
}

// the interface for the mode API
return {
startState: function() {
Expand Down
180 changes: 90 additions & 90 deletions mode/yaml/yaml.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
CodeMirror.defineMode("yaml", function() {

var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');

return {
token: function(stream, state) {
var ch = stream.peek();
var esc = state.escaped;
state.escaped = false;
/* comments */
if (ch == "#") { stream.skipToEnd(); return "comment"; }
if (state.literal && stream.indentation() > state.keyCol) {
stream.skipToEnd(); return "string";
} else if (state.literal) { state.literal = false; }
if (stream.sol()) {
state.keyCol = 0;
state.pair = false;
state.pairStart = false;
/* document start */
if(stream.match(/---/)) { return "def"; }
/* document end */
if (stream.match(/\.\.\./)) { return "def"; }
/* array list item */
if (stream.match(/\s*-\s+/)) { return 'meta'; }
}
/* pairs (associative arrays) -> key */
if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
state.pair = true;
state.keyCol = stream.indentation();
return "atom";
}
if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }

/* inline pairs/lists */
if (stream.match(/^(\{|\}|\[|\])/)) {
if (ch == '{')
state.inlinePairs++;
else if (ch == '}')
state.inlinePairs--;
else if (ch == '[')
state.inlineList++;
else
state.inlineList--;
return 'meta';
}

/* list seperator */
if (state.inlineList > 0 && !esc && ch == ',') {
stream.next();
return 'meta';
}
/* pairs seperator */
if (state.inlinePairs > 0 && !esc && ch == ',') {
state.keyCol = 0;
state.pair = false;
state.pairStart = false;
stream.next();
return 'meta';
}

/* start of value of a pair */
if (state.pairStart) {
/* block literals */
if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
/* references */
if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
/* numbers */
if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
/* keywords */
if (stream.match(keywordRegex)) { return 'keyword'; }
}

/* nothing found, continue */
state.pairStart = false;
state.escaped = (ch == '\\');
stream.next();
return null;
},
startState: function() {
return {
pair: false,
pairStart: false,
keyCol: 0,
inlinePairs: 0,
inlineList: 0,
literal: false,
escaped: false
};
}
};
var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');

return {
token: function(stream, state) {
var ch = stream.peek();
var esc = state.escaped;
state.escaped = false;
/* comments */
if (ch == "#") { stream.skipToEnd(); return "comment"; }
if (state.literal && stream.indentation() > state.keyCol) {
stream.skipToEnd(); return "string";
} else if (state.literal) { state.literal = false; }
if (stream.sol()) {
state.keyCol = 0;
state.pair = false;
state.pairStart = false;
/* document start */
if(stream.match(/---/)) { return "def"; }
/* document end */
if (stream.match(/\.\.\./)) { return "def"; }
/* array list item */
if (stream.match(/\s*-\s+/)) { return 'meta'; }
}
/* pairs (associative arrays) -> key */
if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
state.pair = true;
state.keyCol = stream.indentation();
return "atom";
}
if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }

/* inline pairs/lists */
if (stream.match(/^(\{|\}|\[|\])/)) {
if (ch == '{')
state.inlinePairs++;
else if (ch == '}')
state.inlinePairs--;
else if (ch == '[')
state.inlineList++;
else
state.inlineList--;
return 'meta';
}

/* list seperator */
if (state.inlineList > 0 && !esc && ch == ',') {
stream.next();
return 'meta';
}
/* pairs seperator */
if (state.inlinePairs > 0 && !esc && ch == ',') {
state.keyCol = 0;
state.pair = false;
state.pairStart = false;
stream.next();
return 'meta';
}

/* start of value of a pair */
if (state.pairStart) {
/* block literals */
if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
/* references */
if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
/* numbers */
if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
/* keywords */
if (stream.match(keywordRegex)) { return 'keyword'; }
}

/* nothing found, continue */
state.pairStart = false;
state.escaped = (ch == '\\');
stream.next();
return null;
},
startState: function() {
return {
pair: false,
pairStart: false,
keyCol: 0,
inlinePairs: 0,
inlineList: 0,
literal: false,
escaped: false
};
}
};
});

CodeMirror.defineMIME("text/x-yaml", "yaml");
192 changes: 82 additions & 110 deletions mode/z80/z80.js
Original file line number Diff line number Diff line change
@@ -1,113 +1,85 @@
CodeMirror.defineMode('z80', function()
{
var keywords1 = /^(exx?|(ld|cp|in)([di]r?)?|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|rst|[de]i|halt|im|ot[di]r|out[di]?)\b/i;
var keywords2 = /^(call|j[pr]|ret[in]?)\b/i;
var keywords3 = /^b_?(call|jump)\b/i;
var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i;
var variables2 = /^(n?[zc]|p[oe]?|m)\b/i;
var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i;
var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+)\b/i;

return {startState: function()
{
return {context: 0};
}, token: function(stream, state)
{
if (!stream.column())
state.context = 0;

if (stream.eatSpace())
return null;

var w;

if (stream.eatWhile(/\w/))
{
w = stream.current();

if (stream.indentation())
{
if (state.context == 1 && variables1.test(w))
return 'variable-2';

if (state.context == 2 && variables2.test(w))
return 'variable-3';

if (keywords1.test(w))
{
state.context = 1;
return 'keyword';
}
else if (keywords2.test(w))
{
state.context = 2;
return 'keyword';
}
else if (keywords3.test(w))
{
state.context = 3;
return 'keyword';
}

if (errors.test(w))
return 'error';
}
else if (numbers.test(w))
{
return 'number';
}
else
{
return null;
}
}
else if (stream.eat(';'))
{
stream.skipToEnd();
return 'comment';
}
else if (stream.eat('"'))
{
while (w = stream.next())
{
if (w == '"')
break;

if (w == '\\')
stream.next();
}

return 'string';
}
else if (stream.eat('\''))
{
if (stream.match(/\\?.'/))
return 'number';
}
else if (stream.eat('.') || stream.sol() && stream.eat('#'))
{
state.context = 4;

if (stream.eatWhile(/\w/))
return 'def';
}
else if (stream.eat('$'))
{
if (stream.eatWhile(/[\da-f]/i))
return 'number';
}
else if (stream.eat('%'))
{
if (stream.eatWhile(/[01]/))
return 'number';
}
else
{
stream.next();
}

return null;
}};
CodeMirror.defineMode('z80', function() {
var keywords1 = /^(exx?|(ld|cp|in)([di]r?)?|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|rst|[de]i|halt|im|ot[di]r|out[di]?)\b/i;
var keywords2 = /^(call|j[pr]|ret[in]?)\b/i;
var keywords3 = /^b_?(call|jump)\b/i;
var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i;
var variables2 = /^(n?[zc]|p[oe]?|m)\b/i;
var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i;
var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+)\b/i;

return {
startState: function() {
return {context: 0};
},
token: function(stream, state) {
if (!stream.column())
state.context = 0;

if (stream.eatSpace())
return null;

var w;

if (stream.eatWhile(/\w/)) {
w = stream.current();

if (stream.indentation()) {
if (state.context == 1 && variables1.test(w))
return 'variable-2';

if (state.context == 2 && variables2.test(w))
return 'variable-3';

if (keywords1.test(w)) {
state.context = 1;
return 'keyword';
} else if (keywords2.test(w)) {
state.context = 2;
return 'keyword';
} else if (keywords3.test(w)) {
state.context = 3;
return 'keyword';
}

if (errors.test(w))
return 'error';
} else if (numbers.test(w)) {
return 'number';
} else {
return null;
}
} else if (stream.eat(';')) {
stream.skipToEnd();
return 'comment';
} else if (stream.eat('"')) {
while (w = stream.next()) {
if (w == '"')
break;

if (w == '\\')
stream.next();
}
return 'string';
} else if (stream.eat('\'')) {
if (stream.match(/\\?.'/))
return 'number';
} else if (stream.eat('.') || stream.sol() && stream.eat('#')) {
state.context = 4;

if (stream.eatWhile(/\w/))
return 'def';
} else if (stream.eat('$')) {
if (stream.eatWhile(/[\da-f]/i))
return 'number';
} else if (stream.eat('%')) {
if (stream.eatWhile(/[01]/))
return 'number';
} else {
stream.next();
}
return null;
}
};
});

CodeMirror.defineMIME("text/x-z80", "z80");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codemirror",
"version":"3.11.00",
"version":"3.12.00",
"main": "lib/codemirror.js",
"description": "In-browser code editing made bearable",
"licenses": [{"type": "MIT",
Expand Down
16 changes: 10 additions & 6 deletions test/lint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ var scopePasser = walk.make({
});

function checkFile(fileName) {
var file = fs.readFileSync(fileName, "utf8");
var badChar = file.match(/[\x00-\x08\x0b\x0c\x0e-\x19\uFEFF]/);
if (badChar)
fail("Undesirable character " + badChar[0].charCodeAt(0) + " at position " + badChar.index,
{source: fileName});
var file = fs.readFileSync(fileName, "utf8"), notAllowed;
if (notAllowed = file.match(/[\x00-\x08\x0b\x0c\x0e-\x19\uFEFF\t]|[ \t]\n/)) {
var msg;
if (notAllowed[0] == "\t") msg = "Found tab character";
else if (notAllowed[0].indexOf("\n") > -1) msg = "Trailing whitespace";
else msg = "Undesirable character " + notAllowed[0].charCodeAt(0);
var info = acorn.getLineInfo(file, notAllowed.index);
fail(msg + " at line " + info.line + ", column " + info.column, {source: fileName});
}

try {
var parsed = acorn.parse(file, {
Expand Down Expand Up @@ -91,7 +95,7 @@ function checkFile(fileName) {
var failed = false;
function fail(msg, pos) {
if (pos.start) msg += " (" + pos.start.line + ":" + pos.start.column + ")";
console.log(pos.source.match(/[^\/]+$/)[0] + ": " + msg);
console.log(pos.source + ": " + msg);
failed = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ testCM("verticalScroll", function(cm) {
cm.setLine(0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah");
is(sc.scrollWidth > baseWidth, "scrollbar present");
cm.setLine(0, "foo");
eq(sc.scrollWidth, baseWidth, "scrollbar gone");
if (!phantom) eq(sc.scrollWidth, baseWidth, "scrollbar gone");
cm.setLine(0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah");
cm.setLine(1, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbh");
is(sc.scrollWidth > baseWidth, "present again");
Expand Down
379 changes: 379 additions & 0 deletions test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ testVim('j_k_and_gj_gk', function(cm,vim,helpers){
helpers.doKeys('k');
helpers.assertCursorAt(0, 176);
},{ lineWrapping:true, value: 'This line is intentially long to test movement of gj and gk over wrapped lines. I will start on the end of this line, then make a step up and back to set the origin for j and k.\nThis line is supposed to be even longer than the previous. I will jump here and make another wiggle with gj and gk, before I jump back to the line above. Both wiggles should not change my cursor\'s target character but both j/k and gj/gk change each other\'s reference position.'});
testVim('gj_gk', function(cm, vim, helpers) {
if (phantom) return;
cm.setSize(120);
// Test top of document edge case.
cm.setCursor(0, 4);
helpers.doKeys('g', 'j');
helpers.doKeys('10', 'g', 'k');
helpers.assertCursorAt(0, 4);

// Test moving down preserves column position.
helpers.doKeys('g', 'j');
var pos1 = cm.getCursor();
var expectedPos2 = { line: 0, ch: (pos1.ch - 4) * 2 + 4};
helpers.doKeys('g', 'j');
helpers.assertCursorAt(expectedPos2);

// Move to the last character
cm.setCursor(0, 0);
// Move left to reset HSPos
helpers.doKeys('h');
// Test bottom of document edge case.
helpers.doKeys('100', 'g', 'j');
var endingPos = cm.getCursor();
is(endingPos != 0, 'gj should not be on wrapped line 0');
var topLeftCharCoords = cm.charCoords(makeCursor(0, 0));
var endingCharCoords = cm.charCoords(endingPos);
is(topLeftCharCoords.left == endingCharCoords.left, 'gj should end up on column 0');
},{ lineNumbers: false, lineWrapping:true, value: 'Thislineisintentiallylongtotestmovementofgjandgkoverwrappedlines.' });
testVim('}', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('}');
Expand Down Expand Up @@ -694,6 +722,35 @@ testVim('Y', function(cm, vim, helpers) {
}, { value: ' word1\nword2\n word3' });

// Action tests
testVim('ctrl-a', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('Ctrl-a');
eq('-9', cm.getValue());
helpers.assertCursorAt(0, 1);
helpers.doKeys('2','Ctrl-a');
eq('-7', cm.getValue());
}, {value: '-10'});
testVim('ctrl-x', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('Ctrl-x');
eq('-1', cm.getValue());
helpers.assertCursorAt(0, 1);
helpers.doKeys('2','Ctrl-x');
eq('-3', cm.getValue());
}, {value: '0'});
testVim('Ctrl-x/Ctrl-a search forward', function(cm, vim, helpers) {
['Ctrl-x', 'Ctrl-a'].forEach(function(key) {
cm.setCursor(0, 0);
helpers.doKeys(key);
helpers.assertCursorAt(0, 5);
helpers.doKeys('l');
helpers.doKeys(key);
helpers.assertCursorAt(0, 10);
cm.setCursor(0, 11);
helpers.doKeys(key);
helpers.assertCursorAt(0, 11);
});
}, {value: '__jmp1 jmp2 jmp'});
testVim('a', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('a');
Expand Down Expand Up @@ -1156,6 +1213,328 @@ testVim('._repeat', function(cm, vim, helpers) {
helpers.doKeys('3', '.');
eq('6', cm.getValue());
}, { value: '1 2 3 4 5 6'});
testVim('f;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('f', 'x');
helpers.doKeys(';');
helpers.doKeys('2', ';');
eq(9, cm.getCursor().ch);
}, { value: '01x3xx678x'});
testVim('F;', function(cm, vim, helpers) {
cm.setCursor(0, 8);
helpers.doKeys('F', 'x');
helpers.doKeys(';');
helpers.doKeys('2', ';');
eq(2, cm.getCursor().ch);
}, { value: '01x3xx6x8x'});
testVim('t;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('t', 'x');
helpers.doKeys(';');
helpers.doKeys('2', ';');
eq(8, cm.getCursor().ch);
}, { value: '01x3xx678x'});
testVim('T;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('T', 'x');
helpers.doKeys(';');
helpers.doKeys('2', ';');
eq(2, cm.getCursor().ch);
}, { value: '0xx3xx678x'});
testVim('f,', function(cm, vim, helpers) {
cm.setCursor(0, 6);
helpers.doKeys('f', 'x');
helpers.doKeys(',');
helpers.doKeys('2', ',');
eq(2, cm.getCursor().ch);
}, { value: '01x3xx678x'});
testVim('F,', function(cm, vim, helpers) {
cm.setCursor(0, 3);
helpers.doKeys('F', 'x');
helpers.doKeys(',');
helpers.doKeys('2', ',');
eq(9, cm.getCursor().ch);
}, { value: '01x3xx678x'});
testVim('t,', function(cm, vim, helpers) {
cm.setCursor(0, 6);
helpers.doKeys('t', 'x');
helpers.doKeys(',');
helpers.doKeys('2', ',');
eq(3, cm.getCursor().ch);
}, { value: '01x3xx678x'});
testVim('T,', function(cm, vim, helpers) {
cm.setCursor(0, 4);
helpers.doKeys('T', 'x');
helpers.doKeys(',');
helpers.doKeys('2', ',');
eq(8, cm.getCursor().ch);
}, { value: '01x3xx67xx'});
testVim('fd,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('f', '4');
cm.setCursor(0, 0);
helpers.doKeys('d', ';');
eq('56789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('d', ',');
eq('01239', cm.getValue());
}, { value: '0123456789'});
testVim('Fd,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('F', '4');
cm.setCursor(0, 9);
helpers.doKeys('d', ';');
eq('01239', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('d', ',');
eq('56789', cm.getValue());
}, { value: '0123456789'});
testVim('td,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('t', '4');
cm.setCursor(0, 0);
helpers.doKeys('d', ';');
eq('456789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('d', ',');
eq('012349', cm.getValue());
}, { value: '0123456789'});
testVim('Td,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('T', '4');
cm.setCursor(0, 9);
helpers.doKeys('d', ';');
eq('012349', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('d', ',');
eq('456789', cm.getValue());
}, { value: '0123456789'});
testVim('fc,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('f', '4');
cm.setCursor(0, 0);
helpers.doKeys('c', ';', 'Esc');
eq('56789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('c', ',');
eq('01239', cm.getValue());
}, { value: '0123456789'});
testVim('Fc,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('F', '4');
cm.setCursor(0, 9);
helpers.doKeys('c', ';', 'Esc');
eq('01239', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('c', ',');
eq('56789', cm.getValue());
}, { value: '0123456789'});
testVim('tc,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('t', '4');
cm.setCursor(0, 0);
helpers.doKeys('c', ';', 'Esc');
eq('456789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('c', ',');
eq('012349', cm.getValue());
}, { value: '0123456789'});
testVim('Tc,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('T', '4');
cm.setCursor(0, 9);
helpers.doKeys('c', ';', 'Esc');
eq('012349', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('c', ',');
eq('456789', cm.getValue());
}, { value: '0123456789'});
testVim('fy,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('f', '4');
cm.setCursor(0, 0);
helpers.doKeys('y', ';', 'P');
eq('012340123456789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('y', ',', 'P');
eq('012345678456789', cm.getValue());
}, { value: '0123456789'});
testVim('Fy,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('F', '4');
cm.setCursor(0, 9);
helpers.doKeys('y', ';', 'p');
eq('012345678945678', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('y', ',', 'P');
eq('012340123456789', cm.getValue());
}, { value: '0123456789'});
testVim('ty,;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('t', '4');
cm.setCursor(0, 0);
helpers.doKeys('y', ';', 'P');
eq('01230123456789', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 9);
helpers.doKeys('y', ',', 'p');
eq('01234567895678', cm.getValue());
}, { value: '0123456789'});
testVim('Ty,;', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('T', '4');
cm.setCursor(0, 9);
helpers.doKeys('y', ';', 'p');
eq('01234567895678', cm.getValue());
helpers.doKeys('u');
cm.setCursor(0, 0);
helpers.doKeys('y', ',', 'P');
eq('01230123456789', cm.getValue());
}, { value: '0123456789'});
testVim('HML', function(cm, vim, helpers) {
cm.setSize(600, 400);
cm.setCursor(120, 0);
helpers.doKeys('H');
helpers.assertCursorAt(90, 2);
helpers.doKeys('L');
helpers.assertCursorAt(119, 4);
helpers.doKeys('M');
helpers.assertCursorAt(104,4);
}, { value: (function(){
var upperLines = new Array(100);
var lowerLines = new Array(100);
var upper = ' xx\n';
var lower = ' xx\n';
upper = upperLines.join(upper);
lower = upperLines.join(lower);
return upper + lower;
})()});
var squareBracketMotionSandbox = ''+
'({\n'+//0
' ({\n'+//11
' /*comment {\n'+//2
' */(\n'+//3
'#else \n'+//4
' /* )\n'+//5
'#if }\n'+//6
' )}*/\n'+//7
')}\n'+//8
'{}\n'+//9
'#else {{\n'+//10
'{}\n'+//11
'}\n'+//12
'{\n'+//13
'#endif\n'+//14
'}\n'+//15
'}\n'+//16
'#else';//17
testVim('[[, ]]', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys(']', ']');
helpers.assertCursorAt(9,0);
helpers.doKeys('2', ']', ']');
helpers.assertCursorAt(13,0);
helpers.doKeys(']', ']');
helpers.assertCursorAt(17,0);
helpers.doKeys('[', '[');
helpers.assertCursorAt(13,0);
helpers.doKeys('2', '[', '[');
helpers.assertCursorAt(9,0);
helpers.doKeys('[', '[');
helpers.assertCursorAt(0,0);
}, { value: squareBracketMotionSandbox});
testVim('[], ][', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys(']', '[');
helpers.assertCursorAt(12,0);
helpers.doKeys('2', ']', '[');
helpers.assertCursorAt(16,0);
helpers.doKeys(']', '[');
helpers.assertCursorAt(17,0);
helpers.doKeys('[', ']');
helpers.assertCursorAt(16,0);
helpers.doKeys('2', '[', ']');
helpers.assertCursorAt(12,0);
helpers.doKeys('[', ']');
helpers.assertCursorAt(0,0);
}, { value: squareBracketMotionSandbox});
testVim('[{, ]}', function(cm, vim, helpers) {
cm.setCursor(4, 10);
helpers.doKeys('[', '{');
helpers.assertCursorAt(2,12);
helpers.doKeys('2', '[', '{');
helpers.assertCursorAt(0,1);
cm.setCursor(4, 10);
helpers.doKeys(']', '}');
helpers.assertCursorAt(6,11);
helpers.doKeys('2', ']', '}');
helpers.assertCursorAt(8,1);
cm.setCursor(0,1);
helpers.doKeys(']', '}');
helpers.assertCursorAt(8,1);
helpers.doKeys('[', '{');
helpers.assertCursorAt(0,1);
}, { value: squareBracketMotionSandbox});
testVim('[(, ])', function(cm, vim, helpers) {
cm.setCursor(4, 10);
helpers.doKeys('[', '(');
helpers.assertCursorAt(3,14);
helpers.doKeys('2', '[', '(');
helpers.assertCursorAt(0,0);
cm.setCursor(4, 10);
helpers.doKeys(']', ')');
helpers.assertCursorAt(5,11);
helpers.doKeys('2', ']', ')');
helpers.assertCursorAt(8,0);
helpers.doKeys('[', '(');
helpers.assertCursorAt(0,0);
helpers.doKeys(']', ')');
helpers.assertCursorAt(8,0);
}, { value: squareBracketMotionSandbox});
testVim('[*, ]*, [/, ]/', function(cm, vim, helpers) {
['*', '/'].forEach(function(key){
cm.setCursor(7, 0);
helpers.doKeys('2', '[', key);
helpers.assertCursorAt(2,2);
helpers.doKeys('2', ']', key);
helpers.assertCursorAt(7,5);
});
}, { value: squareBracketMotionSandbox});
testVim('[#, ]#', function(cm, vim, helpers) {
cm.setCursor(10, 3);
helpers.doKeys('2', '[', '#');
helpers.assertCursorAt(4,0);
helpers.doKeys('5', ']', '#');
helpers.assertCursorAt(17,0);
cm.setCursor(10, 3);
helpers.doKeys(']', '#');
helpers.assertCursorAt(14,0);
}, { value: squareBracketMotionSandbox});
testVim('[m, ]m, [M, ]M', function(cm, vim, helpers) {
cm.setCursor(11, 0);
helpers.doKeys('[', 'm');
helpers.assertCursorAt(10,7);
helpers.doKeys('4', '[', 'm');
helpers.assertCursorAt(1,3);
helpers.doKeys('5', ']', 'm');
helpers.assertCursorAt(11,0);
helpers.doKeys('[', 'M');
helpers.assertCursorAt(9,1);
helpers.doKeys('3', ']', 'M');
helpers.assertCursorAt(15,0);
helpers.doKeys('5', '[', 'M');
helpers.assertCursorAt(7,3);
}, { value: squareBracketMotionSandbox});

// Ex mode tests
testVim('ex_go_to_line', function(cm, vim, helpers) {
Expand Down
2 changes: 1 addition & 1 deletion theme/eclipse.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

.cm-s-eclipse .CodeMirror-matchingbracket {
outline:1px solid grey;
color:black !important;;
color:black !important;
}
52 changes: 52 additions & 0 deletions theme/midnight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Based on the theme at http://bonsaiden.github.com/JavaScript-Garden */

/*<!--breakpoint-->*/
.breakpoints {width: .8em;}
.breakpoint { color: #822; }

/*<!--match-->*/
span.CodeMirror-matchhighlight { background: #494949 }
.CodeMirror-focused span.CodeMirror-matchhighlight { background: #314D67; !important }

/*<!--activeline-->*/
.activeline {background: #253540 !important;}

.cm-s-midnight.CodeMirror {
background: #0F192A;
color: #D1EDFF;
}

.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}

.cm-s-midnight div.CodeMirror-selected {background: #314D67 !important;}
.cm-s-midnight .CodeMirror-gutters {background: #0F192A; border-right: 1px solid;}
.cm-s-midnight .CodeMirror-linenumber {color: #D0D0D0;}
.cm-s-midnight .CodeMirror-cursor {
border-left: 1px solid #F8F8F0 !important;
}

.cm-s-midnight span.cm-comment {color: #428BDD;}
.cm-s-midnight span.cm-atom {color: #AE81FF;}
.cm-s-midnight span.cm-number {color: #D1EDFF;}

.cm-s-midnight span.cm-property, .cm-s-tropicaleve span.cm-attribute {color: #A6E22E;}
.cm-s-midnight span.cm-keyword {color: #E83737;}
.cm-s-midnight span.cm-string {color: #1DC116;}

.cm-s-midnight span.cm-variable {color: #FFAA3E;}
.cm-s-midnight span.cm-variable-2 {color: #FFAA3E;}
.cm-s-midnight span.cm-def {color: #4DD;}
.cm-s-midnight span.cm-error {background: #F92672; color: #F8F8F0;}
.cm-s-midnight span.cm-bracket {color: #D1EDFF;}
.cm-s-midnight span.cm-tag {color: #008;}
.cm-s-midnight span.cm-link {color: #AE81FF;}

.cm-s-midnight .CodeMirror-matchingbracket {
text-decoration: underline;
color: white !important;
}

.typ { color: #FFAA3E; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }