-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from melnikga/feat/new-code-editor
feat: Implement Step-by-Step Cairo Code Highlighting - Issue #124
- Loading branch information
Showing
6 changed files
with
495 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import * as MonacoEditor from 'monaco-editor-core/esm/vs/editor/editor.api' | ||
export function registerCairoLanguageSupport(_monaco: typeof MonacoEditor) { | ||
const languageId = 'cairo' | ||
_monaco.languages.register({ id: languageId }) | ||
_monaco.languages.setLanguageConfiguration(languageId, { | ||
comments: { | ||
lineComment: '//', | ||
}, | ||
brackets: [ | ||
['{', '}'], | ||
['[', ']'], | ||
['(', ')'], | ||
['%{', '%}'], | ||
], | ||
autoClosingPairs: [ | ||
{ open: '{', close: '}' }, | ||
{ open: '[', close: ']' }, | ||
{ open: '(', close: ')' }, | ||
{ open: '%{', close: '%}' }, | ||
{ open: "'", close: "'", notIn: ['string', 'comment'] }, | ||
{ open: '<', close: '>' }, | ||
], | ||
surroundingPairs: [ | ||
{ open: '{', close: '}' }, | ||
{ open: '[', close: ']' }, | ||
{ open: '(', close: ')' }, | ||
{ open: '%{', close: '%}' }, | ||
{ open: "'", close: "'" }, | ||
{ open: '<', close: '>' }, | ||
], | ||
}) | ||
_monaco.languages.setMonarchTokensProvider(languageId, { | ||
defaultToken: '', | ||
tokenPostfix: '.cairo', | ||
|
||
brackets: [ | ||
{ token: 'delimiter.curly', open: '{', close: '}' }, | ||
{ token: 'delimiter.parenthesis', open: '(', close: ')' }, | ||
{ token: 'delimiter.square', open: '[', close: ']' }, | ||
{ token: 'delimiter.curly', open: '%{', close: '%}' }, | ||
{ token: 'delimiter.angle', open: '<', close: '>' }, | ||
], | ||
|
||
keywords: [ | ||
'as', | ||
'break', | ||
'const', | ||
'continue', | ||
'else', | ||
'enum', | ||
'extern', | ||
'false', | ||
'fn', | ||
'if', | ||
'impl', | ||
'implicits', | ||
'let', | ||
'loop', | ||
'match', | ||
'mod', | ||
'mut', | ||
'nopanic', | ||
'of', | ||
'ref', | ||
'return', | ||
'struct', | ||
'trait', | ||
'true', | ||
'type', | ||
'use', | ||
'Self', | ||
'assert', | ||
'do', | ||
'dyn', | ||
'for', | ||
'hint', | ||
'in', | ||
'macro', | ||
'move', | ||
'pub', | ||
'self', | ||
'static', | ||
'static_assert', | ||
'super', | ||
'try', | ||
'typeof', | ||
'unsafe', | ||
'where', | ||
'while', | ||
'with', | ||
'yield', | ||
'type', | ||
'cotype', | ||
], | ||
types: ['bool', 'u8', 'u16', 'u32', 'u64', 'u128', 'u256', 'usize'], | ||
literals: ['true', 'false'], | ||
operators: [ | ||
'!', | ||
'~', | ||
'!=', | ||
'%', | ||
'%=', | ||
'&', | ||
'&&', | ||
'*', | ||
'*=', | ||
'@', | ||
'*', | ||
'+', | ||
'+=', | ||
',', | ||
'-', | ||
'-', | ||
'-=', | ||
'->', | ||
'.', | ||
'/', | ||
'/=', | ||
':', | ||
':', | ||
';', | ||
'<', | ||
'<=', | ||
'=', | ||
'==', | ||
'=>', | ||
'>', | ||
'>=', | ||
'^', | ||
'|', | ||
'||', | ||
'?', | ||
], | ||
// we include these common regular expressions | ||
// eslint-disable-next-line no-useless-escape | ||
symbols: /[=><!~?:&|+\-*\/\^%]+/, | ||
numberDecimal: /[+-]?[0-9]+/, | ||
numberHex: /[+-]?0x[0-9a-fA-F]+/, | ||
|
||
// The main tokenizer for our languages | ||
tokenizer: { | ||
root: [ | ||
// identifiers and keywords | ||
[ | ||
/[a-z_$][\w$]*/, | ||
{ | ||
cases: { | ||
'@types': 'type.keyword', | ||
'@keywords': 'keyword', | ||
'@default': 'identifier', | ||
}, | ||
}, | ||
], | ||
|
||
// eslint-disable-next-line no-useless-escape | ||
[/[A-Z][\w\$]*/, 'type.identifier'], | ||
// whitespace | ||
{ include: '@whitespace' }, | ||
|
||
// directives | ||
[/^%[a-zA-Z]\w*/, 'tag'], | ||
|
||
// delimiters and operators | ||
// eslint-disable-next-line no-useless-escape | ||
[/[{}()\[\]]/, '@brackets'], | ||
[/[<>](?!@symbols)/, '@brackets'], | ||
[/\b(?:let|const)\s+([a-zA-Z_$][a-zA-Z\d_$]*)/, 'variableinit'], | ||
[ | ||
/@symbols/, | ||
{ | ||
cases: { | ||
'@operators': 'delimiter', | ||
'@default': '', | ||
}, | ||
}, | ||
], | ||
|
||
// numbers | ||
[/(@numberHex)/, 'number.hex'], | ||
[/(@numberDecimal)/, 'number'], | ||
|
||
// strings | ||
[/['"][^'"]*['"]/g, 'string'], | ||
], | ||
|
||
common: [], | ||
|
||
whitespace: [ | ||
[/\s+/, 'white'], | ||
[/\/\/.*/, 'comment'], | ||
], | ||
}, | ||
}) | ||
_monaco.editor.defineTheme('myTheme', { | ||
base: 'vs', | ||
inherit: true, | ||
rules: [ | ||
{ | ||
foreground: '#981B64', | ||
token: 'variableinit', | ||
}, | ||
], | ||
colors: { | ||
'editor.foreground': '#000000', | ||
'editorCursor.foreground': '#8B0000', | ||
'editor.lineHighlightBackground': '#0000FF20', | ||
'editor.selectionBackground': '#88000030', | ||
'editor.inactiveSelectionBackground': '#88000015', | ||
}, | ||
}) | ||
_monaco.editor.setTheme('myTheme') | ||
} |
Oops, something went wrong.