Skip to content

Commit

Permalink
CE: Support python highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
jxarco committed Dec 14, 2023
1 parent 74fd8e3 commit cd8935a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
17 changes: 11 additions & 6 deletions build/components/codeeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class CodeEditor {
this._lastTime = null;

this.languages = [
'Plain Text', 'JavaScript', 'CSS', 'GLSL', 'WGSL', 'JSON', 'XML'
'Plain Text', 'JavaScript', 'CSS', 'GLSL', 'WGSL', 'JSON', 'XML', 'Python'
];
this.specialKeys = [
'Backspace', 'Enter', 'ArrowUp', 'ArrowDown',
Expand All @@ -213,15 +213,18 @@ class CodeEditor {
'WGSL': ['var', 'let', 'true', 'false', 'fn', 'bool', 'u32', 'i32', 'f16', 'f32', 'vec2f', 'vec3f', 'vec4f', 'mat2x2f', 'mat3x3f', 'mat4x4f', 'array', 'atomic', 'struct',
'sampler', 'sampler_comparison', 'texture_depth_2d', 'texture_depth_2d_array', 'texture_depth_cube', 'texture_depth_cube_array', 'texture_depth_multisampled_2d',
'texture_external', 'texture_1d', 'texture_2d', 'texture_2d_array', 'texture_3d', 'texture_cube', 'texture_cube_array', 'texture_storage_1d', 'texture_storage_2d',
'texture_storage_2d_array', 'texture_storage_3d']
'texture_storage_2d_array', 'texture_storage_3d'],
'Python': ['False', 'def', 'None', 'True', 'in', 'is', 'and', 'lambda', 'nonlocal', 'not', 'or']
};
this.utils = { // These ones don't have hightlight, used as suggestions to autocomplete only...
'JavaScript': ['querySelector', 'body', 'addEventListener', 'removeEventListener', 'remove', 'sort', 'keys', 'filter', 'isNaN', 'parseFloat', 'parseInt', 'EPSILON', 'isFinite',
'bind', 'prototype', 'length', 'assign', 'entries', 'values', 'concat', 'substring', 'substr', 'splice', 'slice', 'buffer', 'appendChild', 'createElement'],
'WGSL': ['textureSample']
'WGSL': ['textureSample'],
'Python': ['print', 'open']
};
this.types = {
'JavaScript': ['Object', 'String', 'Function', 'Boolean', 'Symbol', 'Error', 'Number']
'JavaScript': ['Object', 'String', 'Function', 'Boolean', 'Symbol', 'Error', 'Number'],
'Python': ['int', 'type', 'TypeError', 'float', 'ZeroDivisionError', 'map', 'list']
};
this.builtin = {
'JavaScript': ['document', 'console', 'window', 'navigator'],
Expand All @@ -231,14 +234,16 @@ class CodeEditor {
'JavaScript': ['for', 'if', 'else', 'case', 'switch', 'return', 'while', 'continue', 'break', 'do', 'import',
'from', 'throw', 'async', 'try', 'catch'],
'GLSL': ['for', 'if', 'else', 'return', 'continue', 'break'],
'WGSL': ['const','for', 'if', 'else', 'return', 'continue', 'break', 'storage', 'read', 'uniform']
'WGSL': ['const','for', 'if', 'else', 'return', 'continue', 'break', 'storage', 'read', 'uniform'],
'Python': ['if', 'raise', 'del', 'import', 'return', 'elif', 'try', 'else', 'while', 'as', 'except', 'with', 'assert', 'finally', 'yield', 'break', 'for', 'class', 'continue', 'global', 'pass']
};
this.symbols = {
'JavaScript': ['<', '>', '[', ']', '{', '}', '(', ')', ';', '=', '|', '||', '&', '&&', '?', '??'],
'JSON': ['[', ']', '{', '}', '(', ')'],
'GLSL': ['[', ']', '{', '}', '(', ')'],
'WGSL': ['[', ']', '{', '}', '(', ')', '->'],
'CSS': ['{', '}', '(', ')', '*']
'CSS': ['{', '}', '(', ')', '*'],
'Python': ['<', '>', '[', ']', '(', ')', '=']
};

// Action keys
Expand Down
28 changes: 19 additions & 9 deletions build/lexgui.css
Original file line number Diff line number Diff line change
Expand Up @@ -2931,15 +2931,15 @@ ul.lexassetscontent {
color: #95a0e1;
}

.cm-str { color: #d0774e; } /* string */
.cm-kwd { color: #218cce; } /* keyword */
.cm-com { color: #5cab5a; } /* comment */
.cm-typ { color: #36c0b0; } /* type */
.cm-std { color: #cf6dcf; } /* statements & declarations */
.cm-bln { color: inherit; } /* builtin */
.cm-dec { color: #b1ce9b; } /* decimal */
.cm-sym { color: #e7ded2; } /* symbol */
.cm-mtd { color: #e0cc68 } /* method */
.cm-str.javascript { color: #d0774e; } /* string */
.cm-kwd.javascript { color: #218cce; } /* keyword */
.cm-com.javascript { color: #5cab5a; } /* comment */
.cm-typ.javascript { color: #36c0b0; } /* type */
.cm-std.javascript { color: #cf6dcf; } /* statements & declarations */
.cm-bln.javascript { color: inherit; } /* builtin */
.cm-dec.javascript { color: #b1ce9b; } /* decimal */
.cm-sym.javascript { color: #e7ded2; } /* symbol */
.cm-mtd.javascript { color: #e0cc68 } /* method */

.cm-str.css { color: #d0774e; } /* string */
.cm-kwd.css { color: #e8be53; } /* keyword */
Expand Down Expand Up @@ -2981,6 +2981,16 @@ ul.lexassetscontent {
.cm-sym.wgsl { color: #f9cb20; } /* symbol */
.cm-mtd.wgsl { color: #e0cc68; } /* method */

.cm-str.python { color: #d0774e; } /* string */
.cm-kwd.python { color: #218cce; } /* keyword */
.cm-com.python { color: #5cab5a; } /* comment */
.cm-typ.python { color: #36c0b0; } /* type */
.cm-std.python { color: #cf6dcf; } /* statements & declarations */
.cm-bln.python { color: inherit; } /* builtin */
.cm-dec.python { color: #b1ce9b; } /* decimal */
.cm-sym.python { color: #e7ded2; } /* symbol */
.cm-mtd.python { color: #e0cc68 } /* method */

/* plain color */
.cm-str.plaintext, .cm-kwd.plaintext, .cm-com.plaintext, .cm-typ.plaintext, .cm-std.plaintext,
.cm-bln.plaintext, .cm-dec.plaintext, .cm-sym.plaintext, .cm-mtd.plaintext { color: inherit; }
Expand Down

0 comments on commit cd8935a

Please sign in to comment.