70 changes: 30 additions & 40 deletions mode/xquery/xquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ CodeMirror.defineMode("xquery", function() {
return kwObj;
}();

// 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);
Expand All @@ -95,7 +86,7 @@ CodeMirror.defineMode("xquery", function() {

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

if(stream.match("?", false)) {
Expand All @@ -112,28 +103,28 @@ CodeMirror.defineMode("xquery", function() {
// start code block
else if(ch == "{") {
pushStateStack(state,{ type: "codeblock"});
return ret("", null);
return null;
}
// end code block
else if(ch == "}") {
popStateStack(state);
return ret("", null);
return null;
}
// if we're in an XML block
else if(isInXmlBlock(state)) {
if(ch == ">")
return ret("tag", "tag");
return "tag";
else if(ch == "/" && stream.eat(">")) {
popStateStack(state);
return ret("tag", "tag");
return "tag";
}
else
return ret("word", "variable");
return "variable";
}
// if a number
else if (/\d/.test(ch)) {
stream.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/);
return ret("number", "atom");
return "atom";
}
// comment start
else if (ch === "(" && stream.eat(":")) {
Expand All @@ -149,27 +140,27 @@ CodeMirror.defineMode("xquery", function() {
}
// assignment
else if(ch ===":" && stream.eat("=")) {
return ret("operator", "keyword");
return "keyword";
}
// open paren
else if(ch === "(") {
pushStateStack(state, { type: "paren"});
return ret("", null);
return null;
}
// close paren
else if(ch === ")") {
popStateStack(state);
return ret("", null);
return null;
}
// open paren
else if(ch === "[") {
pushStateStack(state, { type: "bracket"});
return ret("", null);
return null;
}
// close paren
else if(ch === "]") {
popStateStack(state);
return ret("", null);
return null;
}
else {
var known = keywords.propertyIsEnumerable(ch) && keywords[ch];
Expand Down Expand Up @@ -204,15 +195,14 @@ CodeMirror.defineMode("xquery", function() {
// 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);
return "variable";
}
// 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);
return known ? known.style : "variable";
}
}

Expand All @@ -235,7 +225,7 @@ CodeMirror.defineMode("xquery", function() {
maybeNested = (ch == "(");
}

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

// tokenizer for string literals
Expand All @@ -247,15 +237,15 @@ CodeMirror.defineMode("xquery", function() {
if(isInString(state) && stream.current() == quote) {
popStateStack(state);
if(f) state.tokenize = f;
return ret("string", "string");
return "string";
}

pushStateStack(state, { type: "string", name: quote, tokenize: tokenString(quote, f) });

// 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 "string";
}


Expand All @@ -269,13 +259,13 @@ 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 "string";
}

}
}

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

Expand All @@ -293,7 +283,7 @@ CodeMirror.defineMode("xquery", function() {
}
stream.eatWhile(isVariableChar);
state.tokenize = tokenBase;
return ret("variable", "variable");
return "variable";
}

// tokenizer for XML tags
Expand All @@ -303,19 +293,19 @@ CodeMirror.defineMode("xquery", function() {
if(isclose && stream.eat(">")) {
popStateStack(state);
state.tokenize = tokenBase;
return ret("tag", "tag");
return "tag";
}
// self closing tag without attributes?
if(!stream.eat("/"))
pushStateStack(state, { type: "tag", name: name, tokenize: tokenBase});
if(!stream.eat(">")) {
state.tokenize = tokenAttribute;
return ret("tag", "tag");
return "tag";
}
else {
state.tokenize = tokenBase;
}
return ret("tag", "tag");
return "tag";
};
}

Expand All @@ -326,14 +316,14 @@ CodeMirror.defineMode("xquery", function() {
if(ch == "/" && stream.eat(">")) {
if(isInXmlAttributeBlock(state)) popStateStack(state);
if(isInXmlBlock(state)) popStateStack(state);
return ret("tag", "tag");
return "tag";
}
if(ch == ">") {
if(isInXmlAttributeBlock(state)) popStateStack(state);
return ret("tag", "tag");
return "tag";
}
if(ch == "=")
return ret("", null);
return null;
// quoted string
if (ch == '"' || ch == "'")
return chain(stream, state, tokenString(ch, tokenAttribute));
Expand All @@ -351,7 +341,7 @@ CodeMirror.defineMode("xquery", function() {
state.tokenize = tokenBase;
}

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

// handle comments, including nested
Expand All @@ -360,7 +350,7 @@ CodeMirror.defineMode("xquery", function() {
while (ch = stream.next()) {
if (ch == "-" && stream.match("->", true)) {
state.tokenize = tokenBase;
return ret("comment", "comment");
return "comment";
}
}
}
Expand All @@ -372,7 +362,7 @@ CodeMirror.defineMode("xquery", function() {
while (ch = stream.next()) {
if (ch == "]" && stream.match("]", true)) {
state.tokenize = tokenBase;
return ret("comment", "comment");
return "comment";
}
}
}
Expand All @@ -383,7 +373,7 @@ CodeMirror.defineMode("xquery", function() {
while (ch = stream.next()) {
if (ch == "?" && stream.match(">", true)) {
state.tokenize = tokenBase;
return ret("comment", "comment meta");
return "comment meta";
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "codemirror",
"version":"5.2.0",
"version":"5.3.0",
"main": "lib/codemirror.js",
"description": "In-browser code editing made bearable",
"licenses": [{"type": "MIT",
"url": "http://codemirror.net/LICENSE"}],
"license": "MIT",
"directories": {"lib": "./lib"},
"scripts": {"test": "node ./test/run.js"},
"devDependencies": {"node-static": "0.6.0",
Expand Down
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h2>Test Suite</h2>
<script src="search_test.js"></script>
<script src="mode_test.js"></script>

<script src="../mode/clike/test.js"></script>
<script src="../mode/css/test.js"></script>
<script src="../mode/css/scss_test.js"></script>
<script src="../mode/css/less_test.js"></script>
Expand Down
9 changes: 9 additions & 0 deletions test/sql-hint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@
to: Pos(0, 15)
});

test("alias_complete", {
value: "SELECT t. FROM users t",
cursor: Pos(0, 9),
tables: simpleTables,
list: ["t.name", "t.score", "t.birthDate"],
from: Pos(0, 7),
to: Pos(0, 9)
});

function deepCompare(a, b) {
if (!a || typeof a != "object")
return a === b;
Expand Down
13 changes: 13 additions & 0 deletions test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ function testVim(name, run, opts, expectedFail) {
CodeMirror.Vim.resetVimGlobalState_();
var successful = false;
var savedOpenNotification = cm.openNotification;
var savedOpenDialog = cm.openDialog;
try {
run(cm, vim, helpers);
successful = true;
} finally {
cm.openNotification = savedOpenNotification;
cm.openDialog = savedOpenDialog;
if (!successful || verbose) {
place.style.visibility = "visible";
} else {
Expand Down Expand Up @@ -2460,6 +2462,13 @@ testVim('macro_multislash_search', function(cm, vim, helpers) {
helpers.doKeys('@', 'd');
helpers.assertCursorAt(0, 15);
}, { value: 'one line of text to rule them all.'});
testVim('macro_last_ex_command_register', function (cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doEx('s/a/b');
helpers.doKeys('2', '@', ':');
eq('bbbaa', cm.getValue());
helpers.assertCursorAt(0, 2);
}, { value: 'aaaaa'});
testVim('macro_parens', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'z', 'i');
Expand Down Expand Up @@ -3549,6 +3558,10 @@ testSubstitute('ex_substitute_multibackslash_replacement', {
value: 'one,two \n three,four',
expectedValue: 'one\\\\\\\\two \n three\\\\\\\\four', // 2*8 backslashes.
expr: '%s/,/\\\\\\\\\\\\\\\\/g'}); // 16 backslashes.
testSubstitute('ex_substitute_newline_replacement', {
value: 'one,two \n three,four',
expectedValue: 'one\ntwo \n three\nfour',
expr: '%s/,/\\n/g'});
testSubstitute('ex_substitute_braces_word', {
value: 'ababab abb ab{2}',
expectedValue: 'ab abb ab{2}',
Expand Down
1 change: 1 addition & 0 deletions theme/monokai.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

.cm-s-monokai span.cm-variable {color: #f8f8f2;}
.cm-s-monokai span.cm-variable-2 {color: #9effff;}
.cm-s-monokai span.cm-variable-3 {color: #66d9ef;}
.cm-s-monokai span.cm-def {color: #fd971f;}
.cm-s-monokai span.cm-bracket {color: #f8f8f2;}
.cm-s-monokai span.cm-tag {color: #f92672;}
Expand Down
66 changes: 66 additions & 0 deletions theme/ttcn.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* DEFAULT THEME */
.cm-atom {color: #219;}
.cm-attribute {color: #00c;}
.cm-bracket {color: #997;}
.cm-comment {color: #333333;}
.cm-def {color: #00f;}
.cm-em {font-style: italic;}
.cm-error {color: #f00;}
.cm-header {color: #00f; font-weight: bold;}
.cm-hr {color: #999;}
.cm-invalidchar {color: #f00;}
.cm-keyword {font-weight:bold}
.cm-link {color: #00c; text-decoration: underline;}
.cm-meta {color: #555;}
.cm-negative {color: #d44;}
.cm-positive {color: #292;}
.cm-qualifier {color: #555;}
.cm-quote {color: #090;}
.cm-strikethrough {text-decoration: line-through;}
.cm-string {color: #006400;}
.cm-string-2 {color: #f50;}
.cm-strong {font-weight: bold;}
.cm-tag {color: #170;}
.cm-variable {color: #8B2252;}
.cm-variable-2 {color: #05a;}
.cm-variable-3 {color: #085;}

.cm-negative {color: #d44;}
.cm-positive {color: #292;}
.cm-header, .cm-strong {font-weight: bold;}
.cm-em {font-style: italic;}
.cm-link {text-decoration: underline;}
.cm-strikethrough {text-decoration: line-through;}

.cm-s-default .cm-error {color: #f00;}
.cm-invalidchar {color: #f00;}

/* ASN */
.cm-s-ttcn .cm-accessTypes,
.cm-s-ttcn .cm-compareTypes {color: #27408B}
.cm-s-ttcn .cm-cmipVerbs {color: #8B2252}
.cm-s-ttcn .cm-modifier {color:#D2691E}
.cm-s-ttcn .cm-status {color:#8B4545}
.cm-s-ttcn .cm-storage {color:#A020F0}
.cm-s-ttcn .cm-tags {color:#006400}

/* CFG */
.cm-s-ttcn .cm-externalCommands {color: #8B4545; font-weight:bold}
.cm-s-ttcn .cm-fileNCtrlMaskOptions,
.cm-s-ttcn .cm-sectionTitle {color: #2E8B57; font-weight:bold}

/* TTCN */
.cm-s-ttcn .cm-booleanConsts,
.cm-s-ttcn .cm-otherConsts,
.cm-s-ttcn .cm-verdictConsts {color: #006400}
.cm-s-ttcn .cm-configOps,
.cm-s-ttcn .cm-functionOps,
.cm-s-ttcn .cm-portOps,
.cm-s-ttcn .cm-sutOps,
.cm-s-ttcn .cm-timerOps,
.cm-s-ttcn .cm-verdictOps {color: #0000FF}
.cm-s-ttcn .cm-preprocessor,
.cm-s-ttcn .cm-templateMatch,
.cm-s-ttcn .cm-ttcn3Macros {color: #27408B}
.cm-s-ttcn .cm-types {color: #A52A2A; font-weight:bold}
.cm-s-ttcn .cm-visibilityModifiers {font-weight:bold}