progress but not working yet

This commit is contained in:
Morgan Yarbrough 2015-04-17 11:17:31 -04:00
commit 7ae5c862c2

View file

@ -3,7 +3,7 @@
* *
* Copyright (c) 2010, Ajax.org B.V. * Copyright (c) 2010, Ajax.org B.V.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -36,9 +36,9 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var SqlServerHighlightRules = function() { var SqlServerHighlightRules = function() {
/** /**
* each section has a link and some javacript code. * each section has a link and some javacript code.
* go to the link, open dev tools, run code to get the string. * go to the link, open dev tools, run code to get the string.
* *
* Right now this code is optimized to make it easy for a developer to modify. * Right now this code is optimized to make it easy for a developer to modify.
* Once I'm certain that this is not missing anything it can be 'compiled' into a cleaner/faster format that is not executing stuff on the fly for no reason. * Once I'm certain that this is not missing anything it can be 'compiled' into a cleaner/faster format that is not executing stuff on the fly for no reason.
*/ */
@ -81,7 +81,7 @@ var SqlServerHighlightRules = function() {
/* https://msdn.microsoft.com/en-us/library/ms177520.aspx */ /* https://msdn.microsoft.com/en-us/library/ms177520.aspx */
"@@CONNECTIONS|@@CPU_BUSY|@@IDLE|@@IO_BUSY|@@PACKET_ERRORS|@@PACK_RECEIVED|@@PACK_SENT|@@TIMETICKS|@@TOTAL_ERRORS|@@TOTAL_READ|@@TOTAL_WRITE|FN_VIRTUALFILESTATS|" + "@@CONNECTIONS|@@CPU_BUSY|@@IDLE|@@IO_BUSY|@@PACKET_ERRORS|@@PACK_RECEIVED|@@PACK_SENT|@@TIMETICKS|@@TOTAL_ERRORS|@@TOTAL_READ|@@TOTAL_WRITE|FN_VIRTUALFILESTATS|" +
/* https://msdn.microsoft.com/en-us/library/ms188353.aspx */ /* https://msdn.microsoft.com/en-us/library/ms188353.aspx */
"PATINDEX|TEXTPTR|TEXTVALID|" "PATINDEX|TEXTPTR|TEXTVALID"
); );
@ -106,12 +106,12 @@ var SqlServerHighlightRules = function() {
//add each part of set statement to keywords for highlighting, yet keep set statements as is for code completion //add each part of set statement to keywords for highlighting, yet keep set statements as is for code completion
//NOTE: there is likely a better way to do this but I don't fully understand the syntax highlighting part yet //NOTE: there is likely a better way to do this but I don't fully understand the syntax highlighting part yet
var eachSet = setStatements.split('|'); /*var eachSet = setStatements.split('|');
eachSet.forEach(function(v) { eachSet.forEach(function(v) {
v.split(' ').forEach(function(v) { v.split(' ').forEach(function(v) {
keywords += '|' + v; keywords += '|' + v;
}); });
}); });*/
//remove any other built in things from key word list //remove any other built in things from key word list
@ -124,17 +124,35 @@ var SqlServerHighlightRules = function() {
var keywordMapper = this.createKeywordMapper({ var keywordMapper = this.createKeywordMapper({
"support.function": builtinFunctions, "support.function": builtinFunctions,
"keyword": keywords, "keyword": keywords,
"keyword.set": setStatements,
"constant.language": logicalOperators, "constant.language": logicalOperators,
"storage.type": dataTypes "storage.type": dataTypes
}, "identifier", true); }, "identifier", true);
//store keywordList created by createKeywordMapper so we can merge it with second call
var keywordList = this.$keywordList;
var statementMapper = this.createKeywordMapper({
"keyword.set": setStatements,
}, "identifier", true);
//merge first keyword list back in
for (var i = 0; i < keywordList.length; i++) {
this.$keywordList.push(keywordList[i]);
}
// createKeywordMapper ignores case which we want because SqlServer keywords are not case sensitive which // createKeywordMapper ignores case which we want because SqlServer keywords are not case sensitive which
// causes our keywords to get changed to lowercase. // causes our keywords to get changed to lowercase.
// However, the preferred standard for keywords is uppercase, so this transforms them back to uppercase for code completion // However, the preferred standard for keywords is uppercase, so this transforms them back to uppercase for code completion
for (var i = 0; i < this.$keywordList.length; i++) { for (var i = 0; i < this.$keywordList.length; i++) {
this.$keywordList[i] = this.$keywordList[i].toUpperCase(); this.$keywordList[i] = this.$keywordList[i].toUpperCase();
} }
var originalStatementMapper = statementMapper;
statementMapper= function(value){
var r = originalStatementMapper(value);
console.log('value: ' + value + '\tresult: ' + r);
return r;
};
this.$rules = { this.$rules = {
"start": [{ "start": [{
@ -153,10 +171,13 @@ var SqlServerHighlightRules = function() {
}, { }, {
token: "constant.numeric", // float token: "constant.numeric", // float
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token: statementMapper,
regex: "SET [a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, { }, {
token: keywordMapper, token: keywordMapper,
regex: "@{0,2}[a-zA-Z_$][a-zA-Z0-9_$]*\\b" //up to 2 @symbols for some build in functions regex: "@{0,2}[a-zA-Z_$][a-zA-Z0-9_$]*\\b" //up to 2 @symbols for some build in functions
}, { },{
token: "constant.class", token: "constant.class",
regex: "@@?[a-zA-Z_$][a-zA-Z0-9_$]*\\b" regex: "@@?[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, { }, {