Skip to content
Snippets Groups Projects
Commit e9c52f3d authored by Tugrul Elmas's avatar Tugrul Elmas Committed by Marijn Haverbeke
Browse files

[sql mode] Add text/x-mssql dialect and ssms theme

parent e8fa9720
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,9 @@ CodeMirror.defineMode("sql", function(config, parserConfig) { ...@@ -22,7 +22,9 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
support = parserConfig.support || {}, support = parserConfig.support || {},
hooks = parserConfig.hooks || {}, hooks = parserConfig.hooks || {},
dateSQL = parserConfig.dateSQL || {"date" : true, "time" : true, "timestamp" : true}, dateSQL = parserConfig.dateSQL || {"date" : true, "time" : true, "timestamp" : true},
backslashStringEscapes = parserConfig.backslashStringEscapes !== false backslashStringEscapes = parserConfig.backslashStringEscapes !== false,
brackets = parserConfig.brackets || /^[\{}\(\)\[\]]/,
punctuation = parserConfig.punctuation || /^[;.,:]/
function tokenBase(stream, state) { function tokenBase(stream, state) {
var ch = stream.next(); var ch = stream.next();
...@@ -65,9 +67,6 @@ CodeMirror.defineMode("sql", function(config, parserConfig) { ...@@ -65,9 +67,6 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
// charset casting: _utf8'str', N'str', n'str' // charset casting: _utf8'str', N'str', n'str'
// ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html // ref: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
return "keyword"; return "keyword";
} else if (/^[\(\),\;\[\]]/.test(ch)) {
// no highlighting
return null;
} else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) { } else if (support.commentSlashSlash && ch == "/" && stream.eat("/")) {
// 1-line comment // 1-line comment
stream.skipToEnd(); stream.skipToEnd();
...@@ -96,7 +95,15 @@ CodeMirror.defineMode("sql", function(config, parserConfig) { ...@@ -96,7 +95,15 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
} else if (operatorChars.test(ch)) { } else if (operatorChars.test(ch)) {
// operators // operators
stream.eatWhile(operatorChars); stream.eatWhile(operatorChars);
return null; return "operator";
} else if (brackets.test(ch)) {
// brackets
stream.eatWhile(brackets);
return "bracket";
} else if (punctuation.test(ch)) {
// punctuation
stream.eatWhile(punctuation);
return "punctuation";
} else if (ch == '{' && } else if (ch == '{' &&
(stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) { (stream.match(/^( )*(d|D|t|T|ts|TS)( )*'[^']*'( )*}/) || stream.match(/^( )*(d|D|t|T|ts|TS)( )*"[^"]*"( )*}/))) {
// dates (weird ODBC syntax) // dates (weird ODBC syntax)
...@@ -289,11 +296,13 @@ CodeMirror.defineMode("sql", function(config, parserConfig) { ...@@ -289,11 +296,13 @@ CodeMirror.defineMode("sql", function(config, parserConfig) {
CodeMirror.defineMIME("text/x-mssql", { CodeMirror.defineMIME("text/x-mssql", {
name: "sql", name: "sql",
client: set("charset clear connect edit ego exit go help nopager notee nowarning pager print prompt quit rehash source status system tee"), client: set("$partition binary_checksum checksum connectionproperty context_info current_request_id error_line error_message error_number error_procedure error_severity error_state formatmessage get_filestream_transaction_context getansinull host_id host_name isnull isnumeric min_active_rowversion newid newsequentialid rowcount_big xact_state object_id"),
keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered declare exec"), keywords: set(sqlKeywords + "begin trigger proc view index for add constraint key primary foreign collate clustered nonclustered declare exec go if use index holdlock nolock nowait paglock readcommitted readcommittedlock readpast readuncommitted repeatableread rowlock serializable snapshot tablock tablockx updlock with"),
builtin: set("bigint numeric bit smallint decimal smallmoney int tinyint money float real char varchar text nchar nvarchar ntext binary varbinary image cursor timestamp hierarchyid uniqueidentifier sql_variant xml table "), builtin: set("bigint numeric bit smallint decimal smallmoney int tinyint money float real char varchar text nchar nvarchar ntext binary varbinary image cursor timestamp hierarchyid uniqueidentifier sql_variant xml table "),
atoms: set("false true null unknown"), atoms: set("is not null like and or in left right between inner outer join all any some cross unpivot pivot exists"),
operatorChars: /^[*+\-%<>!=]/, operatorChars: /^[*+\-%<>!=^\&|\/]/,
brackets: /^[\{}\(\)]/,
punctuation: /^[;.,:/]/,
backslashStringEscapes: false, backslashStringEscapes: false,
dateSQL: set("date datetimeoffset datetime2 smalldatetime datetime time"), dateSQL: set("date datetimeoffset datetime2 smalldatetime datetime time"),
hooks: { hooks: {
......
.cm-s-ssms span.cm-keyword { color: blue; }
.cm-s-ssms span.cm-comment { color: darkgreen; }
.cm-s-ssms span.cm-string { color: red; }
.cm-s-ssms span.cm-def { color: black; }
.cm-s-ssms span.cm-variable { color: black; }
.cm-s-ssms span.cm-variable-2 { color: black; }
.cm-s-ssms span.cm-atom { color: darkgray; }
.cm-s-ssms .CodeMirror-linenumber { color: teal; }
.cm-s-ssms .CodeMirror-activeline-background { background: #ffffff; }
.cm-s-ssms span.cm-string-2 { color: #FF00FF; }
.cm-s-ssms span.cm-operator,
.cm-s-ssms span.cm-bracket,
.cm-s-ssms span.cm-punctuation { color: darkgray; }
.cm-s-ssms .CodeMirror-gutters { border-right: 3px solid #ffee62; background-color: #ffffff; }
.cm-s-ssms div.CodeMirror-selected { background: #ADD6FF; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment