forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_keywords.py
207 lines (202 loc) · 10.4 KB
/
list_keywords.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
from definition import SPACE, START_WORD, get_translated_keyword
# extra rules for ask
ask_after_is = {
"regex": START_WORD + get_translated_keyword("is") + SPACE + get_translated_keyword("ask"),
"token": ["text", "keyword", "text", "keyword"]
}
ask_after_equal = {
"regex": "(=)" + SPACE + get_translated_keyword("ask"),
"token": ["keyword", "text", "keyword"]
}
# This variable lists all the keywords in each level, i.e. everything that should be displayed in red (of type `keyword`)
#
# There are several categories of keywords:
# - space_before_and_after
# These are the keywords that must be "alone" so neither preceded nor followed directly by a word
#
# - no_space
# These are the keywords that are independent of the context (formerly the symbols).
# In particular, even if they are between 2 words, the syntax highlighting will select them
#
# - space_before
# This category of keywords allows you to have keywords that are not preceded
# by another word, but that can be followed immediately by another word. (see the PR #2413)
#
# - space_after
# This category of keywords allows you to have keywords that can be preceded immediately
# by another word, but that are not followed by another word.
#
# - constant
# list of level constants (direction and colors) not used yet (highlighted in white)
#
# - number & number_with_decimal
# 2 booleans to indicate if the level recognizes numbers, and if so, if it recognizes decimal numbers
#
# - extra_rules
# Some additional rules that will be added to reduce over highlighting
LEVELS = {
4: { # not used
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "color"],
"no_space": ["comma"],
"space_before": ["print", "sleep", "forward", "turn", "random"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"number": False,
"number_with_decimal": False,
"extra_rules": [ask_after_is]
},
5: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "color"],
"no_space": ["comma"],
"space_before": ["print", "sleep", "forward", "turn", "random"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": False,
"number_with_decimal": False,
"extra_rules": [ask_after_is]
},
6: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
7: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "repeat", "times", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
8: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
9: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
10: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "repeat", "for", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
11: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "for", "range", "to", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": False,
"extra_rules": [ask_after_is, ask_after_equal]
},
12: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "for", "range", "to", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
13: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "for", "range", "to", "and", "or", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
14: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "for", "range", "to", "and", "or", "else", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+", "<", ">", "!"],
"space_before": ["print", "sleep", "forward", "turn", "random", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
15: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "for", "range", "to", "and", "or", "while", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+", "<", ">", "!"],
"space_before": ["print", "sleep", "forward", "turn", "random", "else", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
16: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "for", "range", "to", "and", "or", "while", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+", "<", ">", "!", "\\[", "\\]"],
"space_before": ["print", "sleep", "forward", "turn", "random", "times"],
"space_after": [],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
17: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "for", "range", "to", "and", "or", "while", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+", "<", ">", "!", "\\[", "\\]", ":"],
"space_before": ["print", "sleep", "forward", "turn", "random", "times"],
"space_after": ["elif"],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
18: {
"space_before_and_after": ["is", "at", "add", "to_list", "remove", "from", "in", "not_in", "if", "else", "for", "range", "to", "and", "or", "while", "input", "repeat", "color"],
"no_space": ["comma", "-", "=", "/", "\\*", "\\+", "<", ">", "!", "\\[", "\\]", ":", "\\(", "\\)"],
"space_before": ["print", "sleep", "forward", "turn", "random", "times"],
"space_after": ["elif"],
"constant": ["black", "blue", "brown", "gray", "green", "orange", "pink", "purple", "red", "white", "yellow"],
"event": ["pressed"],
"number": True,
"number_with_decimal": True,
"extra_rules": [ask_after_is, ask_after_equal]
},
}