Skip to content

Commit b04745e

Browse files
authored
Merge pull request ethereum#4744 from kairoski03/master
add toml syntax highlighting for monaco
2 parents 2b01ad7 + dfeb1e0 commit b04745e

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

apps/remix-ide/src/app/editor/editor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class Editor extends Plugin {
5353
ts: 'typescript',
5454
move: 'move',
5555
circom: 'circom',
56-
nr: 'rust'
56+
nr: 'rust',
57+
toml: 'toml'
5758
}
5859

5960
this.activated = false

libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { solidityTokensProvider, solidityLanguageConfig } from './syntaxes/solid
99
import { cairoTokensProvider, cairoLanguageConfig } from './syntaxes/cairo'
1010
import { zokratesTokensProvider, zokratesLanguageConfig } from './syntaxes/zokrates'
1111
import { moveTokenProvider, moveLanguageConfig } from './syntaxes/move'
12+
import { tomlLanguageConfig, tomlTokenProvider } from './syntaxes/toml'
1213
import { monacoTypes } from '@remix-ui/editor'
1314
import { loadTypes } from './web-types'
1415
import { retrieveNodesAtPosition } from './helpers/retrieveNodesAtPosition'
@@ -344,6 +345,8 @@ export const EditorUI = (props: EditorUIProps) => {
344345
monacoRef.current.editor.setModelLanguage(file.model, 'remix-move')
345346
} else if (file.language === 'circom') {
346347
monacoRef.current.editor.setModelLanguage(file.model, 'remix-circom')
348+
} else if (file.language === 'toml') {
349+
monacoRef.current.editor.setModelLanguage(file.model, 'remix-toml')
347350
}
348351
}, [props.currentFile])
349352

@@ -888,6 +891,7 @@ export const EditorUI = (props: EditorUIProps) => {
888891
monacoRef.current.languages.register({ id: 'remix-zokrates' })
889892
monacoRef.current.languages.register({ id: 'remix-move' })
890893
monacoRef.current.languages.register({ id: 'remix-circom' })
894+
monacoRef.current.languages.register({ id: 'remix-toml' })
891895

892896
// Allow JSON schema requests
893897
monacoRef.current.languages.json.jsonDefaults.setDiagnosticsOptions({ enableSchemaRequest: true })
@@ -908,6 +912,9 @@ export const EditorUI = (props: EditorUIProps) => {
908912
monacoRef.current.languages.setMonarchTokensProvider('remix-circom', circomTokensProvider as any)
909913
monacoRef.current.languages.setLanguageConfiguration('remix-circom', circomLanguageConfig(monacoRef.current) as any)
910914

915+
monacoRef.current.languages.setMonarchTokensProvider('remix-toml', tomlTokenProvider as any)
916+
monacoRef.current.languages.setLanguageConfiguration('remix-toml', tomlLanguageConfig as any)
917+
911918
monacoRef.current.languages.registerDefinitionProvider('remix-solidity', new RemixDefinitionProvider(props, monaco))
912919
monacoRef.current.languages.registerDocumentHighlightProvider('remix-solidity', new RemixHighLightProvider(props, monaco))
913920
monacoRef.current.languages.registerReferenceProvider('remix-solidity', new RemixReferenceProvider(props, monaco))
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-disable no-useless-escape */
2+
export const tomlLanguageConfig = {
3+
comments: {
4+
lineComment: "#",
5+
},
6+
brackets: [
7+
["{", "}"],
8+
["[", "]"],
9+
["(", ")"],
10+
],
11+
autoClosingPairs: [
12+
{ open: "{", close: "}" },
13+
{ open: "[", close: "]" },
14+
{ open: "(", close: ")" },
15+
{ open: '"', close: '"' },
16+
{ open: "'", close: "'" },
17+
],
18+
surroundingPairs: [
19+
{ open: "{", close: "}" },
20+
{ open: "[", close: "]" },
21+
{ open: "(", close: ")" },
22+
{ open: '"', close: '"' },
23+
{ open: "'", close: "'" },
24+
],
25+
}
26+
27+
export const tomlTokenProvider = {
28+
defaultToken: "",
29+
tokenPostfix: ".toml",
30+
31+
escapes:
32+
/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
33+
34+
tokenizer: {
35+
root: [
36+
[/([a-zA-Z0-9_-]+)(\s*)(=)/, ["variable.name", "operators", ""]],
37+
[/\[[a-zA-Z0-9_.-]+\]/, "type.identifier"],
38+
[/\s*((#).*)$/, "comment"],
39+
40+
[/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
41+
[/0[xX][0-9a-fA-F]+/, "number.hex"],
42+
[/\d+/, "number"],
43+
44+
[/"([^"\\]|\\.)*$/, "string.invalid"],
45+
[/'([^'\\]|\\.)*$/, "string.invalid"],
46+
[/"/, "string", "@string_double"],
47+
[/'/, "string", "@string_single"],
48+
],
49+
string_double: [
50+
[/[^\\"]+/, "string"],
51+
[/@escapes/, "string.escape"],
52+
[/\\./, "string.escape.invalid"],
53+
[/"/, "string", "@pop"],
54+
],
55+
string_single: [
56+
[/[^\\']+/, "string"],
57+
[/@escapes/, "string.escape"],
58+
[/\\./, "string.escape.invalid"],
59+
[/'/, "string", "@pop"],
60+
],
61+
},
62+
}

0 commit comments

Comments
 (0)