Kirill Simonov avatar Kirill Simonov committed 9203fea

tweak.shell: support for locators in hightlighting and completion.

Comments (0)

Files changed (2)

src/htsql/tweak/shell/static/cm-htsql-mode.js

 
 CodeMirror.defineMode("htsql", function(conf) {
     return {
+        startState: function() {
+            return { locator: 0 };
+        },
         token: function(stream, state) {
             if (stream.eatSpace()) {
                 return null;
             }
+            if (state.locator) {
+                if (stream.match(/^(\[|\()/)) {
+                    state.locator += 1;
+                    return 'htsql-punctuation';
+                }
+                if (stream.match(/^(\]|\))/)) {
+                    state.locator -= 1;
+                    return 'htsql-punctuation';
+                }
+                if (stream.match(/^\./)) {
+                    return 'htsql-punctuation';
+                }
+                if (stream.match(/^\'([^\']|\'\')*\'/)) {
+                    return 'htsql-string';
+                }
+                if (stream.match(/^[0-9a-zA-Z_-]+/)) {
+                    return 'htsql-string';
+                }
+                stream.next();
+                return null;
+            }
             if (stream.match(/^:\s*[a-zA-Z_][0-9a-zA-Z_]*/)) {
                 return 'htsql-function';
             }
             if (stream.match(/^\'([^\']|\'\')*\'/)) {
                 return 'htsql-string';
             }
-            if (stream.match(/~|!~|<=|<|>=|>|==|=|!==|!=|!|&|\||->|\?|\^|\/|\*|\+|-/)) {
+            if (stream.match(/^(~|!~|<=|<|>=|>|==|=|!==|!=|!|&|\||->|\?|\^|\/|\*|\+|-)/)) {
                 return 'htsql-operator';
             }
-            if (stream.match(/\.|,|\(|\)|\{|\}|\[|\]|:=|:|\$|@/)) {
+            if (stream.match(/^(\.|,|\(|\)|\{|\}|:=|:|\$|@)/)) {
+                return 'htsql-punctuation';
+            }
+            if (stream.match(/^\[/)) {
+                state.locator += 1;
                 return 'htsql-punctuation';
             }
             stream.next();

src/htsql/tweak/shell/static/shell.js

         }
         var query = editor.getRange({line: 0, ch: 0}, {line: line, ch: start});
         var names = scanQuery(query);
+        if (!names) return;
         var completions = state.completions;
         for (var k = 0; k < names.length; k ++) {
             if (completions && completions.hasOwnProperty(names[k]))
     }
 
     function scanQuery(query) {
-        var regexp = /->|:=|[~<>=!&|.,?(){}:$@^/*+-]|'(?:[^']|'')*'|\d+[.eE]?|(?!\d)[_0-9a-zA-Z\u0080-\uFFFF]+/g;
+        var regexp = /->|:=|\[|\]|[~<>=!&|.,?(){}:$@^/*+-]|'(?:[^']|'')*'|\d+[.eE]?|(?!\d)[_0-9a-zA-Z\u0080-\uFFFF]+/g;
         var tokens = [];
         var match;
         while ((match = regexp.exec(query))) {
             var token = tokens[i];
             var prev_token = (i > 0) ? tokens[i-1] : '';
             var next_token = (i < tokens.length-1) ? tokens[i+1] : '';
+            if (state.indicator == '[') {
+                if (token == '[' || token == '(') {
+                    state.push('[', []);
+                }
+                else if (token == ']' || token == ')') {
+                    state.drop(/[[]/);
+                }
+                continue;
+            }
             if (/^(?![0-9])[_0-9a-zA-Z\u0080-\uFFFF]+$/.test(token)) {
                 if (!/[:$]/.test(prev_token) && !/[(]/.test(next_token)) {
                     state.push('_', state.identifiers.concat([token]));
             else if (token == '$') {
                 state.push('_', []);
             }
+            else if (token == '[') {
+                state.push('[', []);
+            }
             else {
                 state.drop_all(/[_]/);
             }
         }
+        if (state.indicator == '[') {
+            return null;
+        }
         return state.identifiers;
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.