forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlighting.ts
141 lines (129 loc) · 4.43 KB
/
highlighting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2021 Olivier Goffart <[email protected]>
Copyright (c) 2021 Simon Hausmann <[email protected]>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact [email protected] for more information.
LICENSE END */
import * as monaco from 'monaco-editor';
export const sixtyfps_language = <monaco.languages.IMonarchLanguage>{
defaultToken: 'invalid',
root_keywords: [
'import', 'from', 'export'
],
inner_keywords: [
'property', 'callback', 'animate', 'states', 'transitions', 'if', 'for'
],
lang_keywords: [
'root', 'parent', 'this', 'if'
],
type_keywords: ['int', 'string', 'float', 'length', 'physical_length', 'duration'],
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
symbols: /[\#\!\%\&\*\+\-\.\/\:\;\<\=\>\@\^\|_\?,()]+/,
tokenizer: {
root: [
[/[a-zA-Z_][a-zA-Z0-9_]*/, {
cases: {
'@root_keywords': { token: 'keyword' },
'@default': 'identifier'
}
}],
{ include: '@whitespace' },
{ include: '@numbers' },
[/"/, 'string', '@string'],
[/\{/, '', '@inner'],
[/@symbols/, ''],
],
inner: [
[/[a-zA-Z_][a-zA-Z0-9_\-]*\s*:=/, 'variable.parameter'],
[/[a-zA-Z_][a-zA-Z0-9_\-]*\s*:\s*\{/, 'variable.parameter', '@binding_1'],
[/[a-zA-Z_][a-zA-Z0-9_\-]*\s*:/, 'variable.parameter', '@binding_0'],
[/[a-zA-Z_][a-zA-Z0-9_\-]*/, {
cases: {
'@inner_keywords': { token: 'keyword' },
'@default': 'identifier'
}
}],
{ include: '@whitespace' },
{ include: '@numbers' },
[/"/, 'string', '@string'],
[/\{/, '', '@push'],
[/\}/, '', '@pop'],
[/:=/, ''],
[/<=>/, '', '@binding_0'],
[/=>\s*{/, '', '@binding_1'],
[/\</, '', '@type'],
[/\[/, '', 'binding_1'],
[/@symbols/, ''],
],
type: [
[/[a-zA-Z_][a-zA-Z0-9_]*/, {
cases: {
'@type_keywords': { token: 'keyword.type' },
'@default': 'identifier'
}
}],
{ include: '@whitespace' },
{ include: '@numbers' },
[/"/, 'string', '@string'],
[/\</, '', '@push'],
[/\>/, '', '@pop'],
[/@symbols/, ''],
],
binding_0: [
{ include: '@whitespace' },
[/\{/, '', '@binding_1'],
[/;/, '', '@pop'],
// that should not be needed, but ends recovering after a for
[/\}/, '', '@pop'],
[/[a-zA-Z_][a-zA-Z0-9_]*/, {
cases: {
'@lang_keywords': { token: 'keyword.type' },
'@default': 'identifier'
}
}],
{ include: '@numbers' },
[/"/, 'string', '@string'],
[/@symbols/, ''],
],
// inside a '{'
binding_1: [
[/[a-zA-Z_][a-zA-Z0-9_]*/, {
cases: {
'@lang_keywords': { token: 'keyword.type' },
'@default': 'identifier'
}
}],
{ include: '@whitespace' },
{ include: '@numbers' },
[/"/, 'string', '@string'],
[/\{/, '', '@push'],
[/\}/, '', '@pop'],
[/\[/, '', '@push'],
[/\]/, '', '@pop'],
[/@symbols/, ''],
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment'],
[/\/\/.*$/, 'comment']
],
string: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, 'string', '@pop']
],
comment: [
[/[^\/*]+/, 'comment'],
[/\/\*/, 'comment', '@push'],
['\\*/', 'comment', '@pop'],
[/[\/*]/, 'comment']
],
numbers: [
[/\d+(\.\d+)?\w*/, { token: 'number' }],
[/#[0-9a-fA-F]+/, { token: 'number' }],
]
},
}