khulnasoft commited on
Commit
e111422
1 Parent(s): 5958f7e

Upload 5 files

Browse files
jupyterlab-codeql-highlight/jupyterlab-codeql-highlight/__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Running `npm run build` will create static resources in the static
2
+ # directory of this Python package (and create that directory if necessary).
3
+
4
+
5
+ def _jupyter_labextension_paths():
6
+ return [{
7
+ 'name': 'jupyterlab-codeql-highlight',
8
+ 'src': 'static',
9
+ }]
jupyterlab-codeql-highlight/lib/codeql.js ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+ import * as CodeMirror from 'codemirror';
4
+ import 'codemirror/addon/mode/simple';
5
+
6
+ // "use strict";
7
+
8
+ // from where select predicate in as order by asc desc module result this super
9
+ // abstract cached external final library noopt private deprecated override query pragma language bindingset noinline nomagic monotonicAggregates transient
10
+ // not and or implies exists forall forex any none
11
+ // if then else
12
+ // int float string boolean date
13
+ // import
14
+ // class extends instanceof
15
+ // avg concat count max min rank strictconcat strictcount strictsum sum
16
+ // false true
17
+ var builtins_base = [
18
+ "from", "where", "select", "predicate", "in", "as", "order", "by", "asc", "desc", "module", "result", "this", "super",
19
+ "abstract", "cached", "external", "final", "library", "noopt", "private", "deprecated", "override", "query", "pragma", "language", "bindingset", "noinline", "nomagic", "monotonicAggregates", "transient",
20
+ "not", "and", "or", "implies", "exists", "forall", "forex", "any", "none",
21
+ "if", "then", "else",
22
+ "int", "float", "string", "boolean", "date",
23
+ "import",
24
+ "class", "extends", "instanceof",
25
+ "avg", "concat", "count", "max", "min", "rank", "strictconcat", "strictcount", "strictsum", "sum",
26
+ "false", "true"
27
+ ];
28
+ var builtins_str = '(' + builtins_base.join('|') + ')\\b';
29
+
30
+ var builtins_functions = [];
31
+ var builtins_fun_str = '(' + builtins_functions.join('|') + ')(?=\\()';
32
+
33
+ CodeMirror.defineSimpleMode("codeql", {
34
+ // The start state contains the rules that are intially used
35
+ start: [
36
+ // Comments
37
+ { regex: /\/\/\/?.*$/, token: 'comment', sol: true },
38
+ { regex: /(\s)\/\/\/?.*$/, token: 'comment' },
39
+ { regex: /\s*\*.*$/, token: 'comment', sol: true },
40
+ { regex: /\/\*/, token: 'comment', push: 'comments_block' },
41
+
42
+ // Strings
43
+ { regex: /"/, token: 'string', push: 'string_regular' },
44
+ { regex: /`"/, token: 'string', push: 'string_compound' },
45
+
46
+ // Macros
47
+ { regex: /`/, token: 'variable-2', push: 'macro_local' },
48
+ { regex: /\$/, token: 'variable-2', push: 'macro_global' },
49
+
50
+ // Decimal Numbers
51
+ {
52
+ regex: /\b[+-]?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+|\.)(?:[eE][+-]?[0-9]+)?[i]?\b/,
53
+ token: 'number'
54
+ },
55
+
56
+ // Keywords
57
+ // There are two separate dictionaries because the `\b` at the beginning of the regex seemed not to work. So instead, I either match the preceding space before the keyword or require the keyword to be at beginning of the string. I think this necessitates two different strings.
58
+ { regex: new RegExp('\\s' + builtins_str), token: 'keyword' },
59
+ { regex: new RegExp(builtins_str), token: 'keyword', sol: true },
60
+
61
+ { regex: new RegExp('\\s' + builtins_fun_str), token: 'def' },
62
+ { regex: /\s\w+(?=\()/, token: 'def' },
63
+
64
+ { regex: /[\{]/, indent: true },
65
+ { regex: /[\}]/, dedent: true },
66
+
67
+ { regex: /-|==|<=|>=|<|>|&|!=/, token: 'operator' },
68
+ { regex: /\*|\+|\^|\/|!|~|=|~=/, token: 'operator' },
69
+ ],
70
+ comments_block: [
71
+ { regex: /\/\*/, token: 'comment', push: 'comments_block' },
72
+ // this ends and restarts a comment block. but need to catch this so
73
+ // that it doesn\'t start _another_ level of comment blocks
74
+ { regex: /\*\/\*/, token: 'comment' },
75
+ { regex: /(\*\/\s+\*(?!\/)[^\n]*)|(\*\/)/, token: 'comment', pop: true },
76
+ // Match anything else as a character inside the comment
77
+ { regex: /./, token: 'comment' },
78
+ ],
79
+
80
+ string_compound: [
81
+ { regex: /`"/, token: 'string', push: 'string_compound' },
82
+ { regex: /"'/, token: 'string', pop: true },
83
+ { regex: /`/, token: 'variable-2', push: 'macro_local' },
84
+ { regex: /\$/, token: 'variable-2', push: 'macro_global' },
85
+ { regex: /./, token: 'string' }
86
+ ],
87
+ string_regular: [
88
+ { regex: /"/, token: 'string', pop: true },
89
+ { regex: /`/, token: 'variable-2', push: 'macro_local' },
90
+ { regex: /\$/, token: 'variable-2', push: 'macro_global' },
91
+ { regex: /./, token: 'string' }
92
+ ],
93
+ macro_local: [
94
+ { regex: /`/, token: 'variable-2', push: 'macro_local' },
95
+ { regex: /'/, token: 'variable-2', pop: true },
96
+ { regex: /./, token: 'variable-2' },
97
+ ],
98
+ macro_global: [
99
+ { regex: /\}/, token: 'variable-2', pop: true },
100
+ { regex: /.(?=[^\w\{\}])/, token: 'variable-2', pop: true },
101
+ { regex: /./, token: 'variable-2' },
102
+ ],
103
+ meta: {
104
+ closeBrackets: { pairs: "()[]{}`'\"\"" },
105
+ dontIndentStates: ['comment'],
106
+ electricInput: /^\s*\}$/,
107
+ blockCommentStart: '/*',
108
+ blockCommentEnd: '*/',
109
+ lineComment: '//',
110
+ fold: 'brace'
111
+ }
112
+ });
113
+
114
+ CodeMirror.defineMIME('text/x-codeql', 'codeql');
115
+ CodeMirror.defineMIME('text/codeql', 'codeql');
116
+
117
+ // When I paste this file in Jupyter, it won't work unless I include the
118
+ // following code, but when I leave this as a separate module, it won't work and
119
+ // raises an error.
120
+ CodeMirror.modeInfo.push({
121
+ ext: ['do', 'ado'],
122
+ mime: "text/x-codeql",
123
+ mode: 'codeql',
124
+ name: 'CodeQL'
125
+ });
jupyterlab-codeql-highlight/lib/plugin.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import './codeql'
2
+
3
+ export default [{
4
+ id: 'jupyterlab-codeql-highlight',
5
+ autoStart: true,
6
+ activate: function(app) {
7
+ console.log('JupyterLab `jupyterlab-codeql-highlight` extension is activated!');
8
+ console.log(app.commands);
9
+ registerStataFileType(app);
10
+ }
11
+ }];
12
+
13
+ function registerStataFileType(app) {
14
+ app.docRegistry.addFileType({
15
+ name: 'codeql',
16
+ displayName: 'CodeQL',
17
+ extensions: ['ql', 'qll'],
18
+ mimeTypes: ['text/x-codeql'],
19
+ });
20
+ }
jupyterlab-codeql-highlight/package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
jupyterlab-codeql-highlight/package.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "jupyterlab-codeql-highlight",
3
+ "version": "0.0.1",
4
+ "description": "Jupyterlab extension to highlight CodeQL syntax",
5
+ "author": "Alvaro Munoz",
6
+ "main": "lib/plugin.js",
7
+ "keywords": [
8
+ "jupyter",
9
+ "jupyterlab",
10
+ "jupyterlab-extension"
11
+ ],
12
+ "license": "MIT",
13
+ "repository": {
14
+ "url": "[email protected]:github/jupyterlab-codeql-highlight.git",
15
+ "type": "git"
16
+ },
17
+ "jupyterlab": {
18
+ "extension": true
19
+ },
20
+ "scripts": {},
21
+ "dependencies": {
22
+ "@jupyterlab/codemirror": "*"
23
+ },
24
+ "devDependencies": {}
25
+ }