@exercism/codemirror-lang-red 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +203 -2
- package/dist/index.cjs +1662 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +1654 -0
- package/package.json +56 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1662 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var language = require('@codemirror/language');
|
|
4
|
+
var highlight = require('@lezer/highlight');
|
|
5
|
+
var lr = require('@lezer/lr');
|
|
6
|
+
var autocomplete = require('@codemirror/autocomplete');
|
|
7
|
+
|
|
8
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
9
|
+
const Binary = 1,
|
|
10
|
+
Char = 2,
|
|
11
|
+
Comment = 3,
|
|
12
|
+
Constant = 4,
|
|
13
|
+
ConstructStart = 5,
|
|
14
|
+
ControlWord = 6,
|
|
15
|
+
Datatype = 7,
|
|
16
|
+
Date = 8,
|
|
17
|
+
Decimal = 9,
|
|
18
|
+
DeclWord = 10,
|
|
19
|
+
Directive = 11,
|
|
20
|
+
Email = 12,
|
|
21
|
+
File = 13,
|
|
22
|
+
FuncWord = 14,
|
|
23
|
+
GetPath = 15,
|
|
24
|
+
GetWord = 16,
|
|
25
|
+
Integer = 17,
|
|
26
|
+
Issue = 18,
|
|
27
|
+
LitPath = 19,
|
|
28
|
+
LitWord = 20,
|
|
29
|
+
LoopWord = 21,
|
|
30
|
+
MapStart = 22,
|
|
31
|
+
Money = 23,
|
|
32
|
+
Operator = 24,
|
|
33
|
+
Pair = 25,
|
|
34
|
+
Path = 26,
|
|
35
|
+
QueryWord = 27,
|
|
36
|
+
Ref = 28,
|
|
37
|
+
Refinement = 29,
|
|
38
|
+
SetPath = 30,
|
|
39
|
+
SetWord = 31,
|
|
40
|
+
StandardWord = 32,
|
|
41
|
+
String$1 = 33,
|
|
42
|
+
Tag = 34,
|
|
43
|
+
Time = 35,
|
|
44
|
+
Tuple = 36,
|
|
45
|
+
Url = 37,
|
|
46
|
+
Word = 38,
|
|
47
|
+
Dialect_red = 0;
|
|
48
|
+
|
|
49
|
+
// Generated by scripts/red-words.mjs from Red's source. Do not edit.
|
|
50
|
+
const redFunctions = [
|
|
51
|
+
{ name: "??", kind: "function", args: ["'value"], refinements: [] },
|
|
52
|
+
{ name: "about", kind: "function", args: [], refinements: [{ name: "debug", args: [] }, { name: "cc", args: [] }] },
|
|
53
|
+
{ name: "absolute", kind: "action", args: ["value"], refinements: [] },
|
|
54
|
+
{ name: "acos", kind: "function", args: ["cosine"], refinements: [] },
|
|
55
|
+
{ name: "action?", kind: "function", args: ["value"], refinements: [] },
|
|
56
|
+
{ name: "add", kind: "action", args: ["value1", "value2"], refinements: [] },
|
|
57
|
+
{ name: "all", kind: "native", args: ["conds"], refinements: [] },
|
|
58
|
+
{ name: "all-word?", kind: "function", args: ["value"], refinements: [] },
|
|
59
|
+
{ name: "also", kind: "function", args: ["value1", "value2"], refinements: [] },
|
|
60
|
+
{ name: "alter", kind: "function", args: ["series", "value"], refinements: [] },
|
|
61
|
+
{ name: "and", kind: "op", args: [], refinements: [] },
|
|
62
|
+
{ name: "any", kind: "native", args: ["conds"], refinements: [] },
|
|
63
|
+
{ name: "any-block?", kind: "function", args: ["value"], refinements: [] },
|
|
64
|
+
{ name: "any-function?", kind: "function", args: ["value"], refinements: [] },
|
|
65
|
+
{ name: "any-list?", kind: "function", args: ["value"], refinements: [] },
|
|
66
|
+
{ name: "any-object?", kind: "function", args: ["value"], refinements: [] },
|
|
67
|
+
{ name: "any-path?", kind: "function", args: ["value"], refinements: [] },
|
|
68
|
+
{ name: "any-point?", kind: "function", args: ["value"], refinements: [] },
|
|
69
|
+
{ name: "any-string?", kind: "function", args: ["value"], refinements: [] },
|
|
70
|
+
{ name: "any-word?", kind: "function", args: ["value"], refinements: [] },
|
|
71
|
+
{ name: "append", kind: "action", args: ["series", "value"], refinements: [{ name: "part", args: ["length"] }, { name: "only", args: [] }, { name: "dup", args: ["count"] }] },
|
|
72
|
+
{ name: "apply", kind: "native", args: [], refinements: [] },
|
|
73
|
+
{ name: "arccosine", kind: "native", args: ["cosine"], refinements: [{ name: "radians", args: [] }] },
|
|
74
|
+
{ name: "arcsine", kind: "native", args: ["sine"], refinements: [{ name: "radians", args: [] }] },
|
|
75
|
+
{ name: "arctangent", kind: "native", args: ["tangent"], refinements: [{ name: "radians", args: [] }] },
|
|
76
|
+
{ name: "arctangent2", kind: "native", args: ["y", "x"], refinements: [{ name: "radians", args: [] }] },
|
|
77
|
+
{ name: "as", kind: "native", args: ["type", "spec"], refinements: [] },
|
|
78
|
+
{ name: "as-money", kind: "native", args: ["currency", "amount"], refinements: [] },
|
|
79
|
+
{ name: "as-pair", kind: "native", args: ["x", "y"], refinements: [] },
|
|
80
|
+
{ name: "as-point2D", kind: "native", args: ["x", "y"], refinements: [] },
|
|
81
|
+
{ name: "as-point3D", kind: "native", args: ["x", "y", "z"], refinements: [] },
|
|
82
|
+
{ name: "asin", kind: "function", args: ["sine"], refinements: [] },
|
|
83
|
+
{ name: "ask", kind: "function", args: ["question"], refinements: [{ name: "hide", args: [] }, { name: "history", args: ["blk"] }] },
|
|
84
|
+
{ name: "at", kind: "action", args: ["series", "index"], refinements: [] },
|
|
85
|
+
{ name: "atan", kind: "function", args: ["tangent"], refinements: [] },
|
|
86
|
+
{ name: "atan2", kind: "function", args: ["y", "x"], refinements: [] },
|
|
87
|
+
{ name: "attempt", kind: "function", args: ["code"], refinements: [{ name: "safer", args: [] }] },
|
|
88
|
+
{ name: "average", kind: "function", args: ["block"], refinements: [] },
|
|
89
|
+
{ name: "back", kind: "action", args: ["series"], refinements: [] },
|
|
90
|
+
{ name: "binary?", kind: "function", args: ["value"], refinements: [] },
|
|
91
|
+
{ name: "bind", kind: "native", args: ["word", "context"], refinements: [{ name: "copy", args: [] }] },
|
|
92
|
+
{ name: "bitset?", kind: "function", args: ["value"], refinements: [] },
|
|
93
|
+
{ name: "block?", kind: "function", args: ["value"], refinements: [] },
|
|
94
|
+
{ name: "body-of", kind: "function", args: ["value"], refinements: [] },
|
|
95
|
+
{ name: "break", kind: "native", args: [], refinements: [{ name: "return", args: ["value"] }] },
|
|
96
|
+
{ name: "browse", kind: "native", args: ["url"], refinements: [] },
|
|
97
|
+
{ name: "call", kind: "native", args: ["cmd"], refinements: [{ name: "wait", args: [] }, { name: "show", args: [] }, { name: "console", args: [] }, { name: "shell", args: [] }, { name: "input", args: ["in"] }, { name: "output", args: ["out"] }, { name: "error", args: ["err"] }] },
|
|
98
|
+
{ name: "case", kind: "native", args: ["cases"], refinements: [{ name: "all", args: [] }] },
|
|
99
|
+
{ name: "catch", kind: "native", args: ["block"], refinements: [{ name: "name", args: ["word"] }] },
|
|
100
|
+
{ name: "cause-error", kind: "function", args: ["err-type", "err-id", "args"], refinements: [] },
|
|
101
|
+
{ name: "change", kind: "action", args: ["series", "value"], refinements: [{ name: "part", args: ["range"] }, { name: "only", args: [] }, { name: "dup", args: ["count"] }] },
|
|
102
|
+
{ name: "change-dir", kind: "function", args: ["dir"], refinements: [] },
|
|
103
|
+
{ name: "char?", kind: "function", args: ["value"], refinements: [] },
|
|
104
|
+
{ name: "charset", kind: "function", args: ["spec"], refinements: [] },
|
|
105
|
+
{ name: "checksum", kind: "native", args: ["data", "method"], refinements: [{ name: "with", args: ["spec"] }] },
|
|
106
|
+
{ name: "class-of", kind: "function", args: ["value"], refinements: [] },
|
|
107
|
+
{ name: "clean-path", kind: "function", args: ["file"], refinements: [{ name: "only", args: [] }, { name: "dir", args: [] }] },
|
|
108
|
+
{ name: "clear", kind: "action", args: ["series"], refinements: [] },
|
|
109
|
+
{ name: "clear-reactions", kind: "function", args: [], refinements: [] },
|
|
110
|
+
{ name: "clock", kind: "function", args: ["code"], refinements: [{ name: "times", args: ["n"] }] },
|
|
111
|
+
{ name: "close", kind: "action", args: ["port"], refinements: [] },
|
|
112
|
+
{ name: "collect", kind: "function", args: ["body"], refinements: [{ name: "into", args: ["collected"] }] },
|
|
113
|
+
{ name: "comment", kind: "function", args: ["'value"], refinements: [] },
|
|
114
|
+
{ name: "complement", kind: "action", args: ["value"], refinements: [] },
|
|
115
|
+
{ name: "complement?", kind: "native", args: ["bits"], refinements: [] },
|
|
116
|
+
{ name: "compose", kind: "native", args: ["value"], refinements: [{ name: "deep", args: [] }, { name: "only", args: [] }, { name: "into", args: ["out"] }] },
|
|
117
|
+
{ name: "compress", kind: "native", args: ["data", "method"], refinements: [{ name: "level", args: ["lvl"] }] },
|
|
118
|
+
{ name: "construct", kind: "native", args: ["block"], refinements: [{ name: "with", args: ["object"] }, { name: "only", args: [] }] },
|
|
119
|
+
{ name: "context", kind: "function", args: ["spec"], refinements: [] },
|
|
120
|
+
{ name: "context?", kind: "native", args: ["word"], refinements: [] },
|
|
121
|
+
{ name: "continue", kind: "native", args: [], refinements: [] },
|
|
122
|
+
{ name: "copy", kind: "action", args: ["value"], refinements: [{ name: "part", args: ["length"] }, { name: "deep", args: [] }, { name: "types", args: ["kind"] }] },
|
|
123
|
+
{ name: "cos", kind: "function", args: ["angle"], refinements: [] },
|
|
124
|
+
{ name: "cosine", kind: "native", args: ["angle"], refinements: [{ name: "radians", args: [] }] },
|
|
125
|
+
{ name: "create", kind: "action", args: ["port"], refinements: [] },
|
|
126
|
+
{ name: "datatype?", kind: "function", args: ["value"], refinements: [] },
|
|
127
|
+
{ name: "date?", kind: "function", args: ["value"], refinements: [] },
|
|
128
|
+
{ name: "debase", kind: "native", args: ["value"], refinements: [{ name: "base", args: ["base-value"] }] },
|
|
129
|
+
{ name: "debug", kind: "function", args: ["code"], refinements: [{ name: "later", args: [] }] },
|
|
130
|
+
{ name: "decode-url", kind: "function", args: ["url"], refinements: [] },
|
|
131
|
+
{ name: "decompress", kind: "native", args: ["data", "method"], refinements: [{ name: "size", args: ["sz"] }] },
|
|
132
|
+
{ name: "deep-reactor", kind: "function", args: ["spec"], refinements: [] },
|
|
133
|
+
{ name: "dehex", kind: "native", args: ["value"], refinements: [] },
|
|
134
|
+
{ name: "delete", kind: "action", args: ["file"], refinements: [] },
|
|
135
|
+
{ name: "difference", kind: "native", args: ["set1", "set2"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }] },
|
|
136
|
+
{ name: "dir?", kind: "function", args: ["file"], refinements: [] },
|
|
137
|
+
{ name: "dirize", kind: "function", args: ["path"], refinements: [] },
|
|
138
|
+
{ name: "divide", kind: "action", args: ["value1", "value2"], refinements: [] },
|
|
139
|
+
{ name: "do", kind: "native", args: ["value"], refinements: [{ name: "expand", args: [] }, { name: "args", args: ["arg"] }, { name: "next", args: ["position"] }, { name: "trace", args: ["callback"] }] },
|
|
140
|
+
{ name: "do-file", kind: "function", args: ["file", "callback", "do-args"], refinements: [] },
|
|
141
|
+
{ name: "do-thru", kind: "function", args: ["url"], refinements: [{ name: "update", args: [] }] },
|
|
142
|
+
{ name: "does", kind: "native", args: ["body"], refinements: [] },
|
|
143
|
+
{ name: "dt", kind: "function", args: ["body"], refinements: [] },
|
|
144
|
+
{ name: "dump-reactions", kind: "function", args: [], refinements: [] },
|
|
145
|
+
{ name: "either", kind: "native", args: ["cond", "true-blk", "false-blk"], refinements: [] },
|
|
146
|
+
{ name: "ellipsize-at", kind: "function", args: ["str", "len"], refinements: [] },
|
|
147
|
+
{ name: "email?", kind: "function", args: ["value"], refinements: [] },
|
|
148
|
+
{ name: "empty?", kind: "function", args: ["data"], refinements: [] },
|
|
149
|
+
{ name: "enbase", kind: "native", args: ["value"], refinements: [{ name: "base", args: ["base-value"] }] },
|
|
150
|
+
{ name: "encode-url", kind: "function", args: ["url-obj"], refinements: [] },
|
|
151
|
+
{ name: "enhex", kind: "native", args: ["value"], refinements: [] },
|
|
152
|
+
{ name: "equal?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
153
|
+
{ name: "error?", kind: "function", args: ["value"], refinements: [] },
|
|
154
|
+
{ name: "even?", kind: "action", args: ["number"], refinements: [] },
|
|
155
|
+
{ name: "exclude", kind: "native", args: ["set1", "set2"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }] },
|
|
156
|
+
{ name: "exists-thru?", kind: "function", args: ["url"], refinements: [] },
|
|
157
|
+
{ name: "exit", kind: "native", args: [], refinements: [] },
|
|
158
|
+
{ name: "exp", kind: "native", args: ["value"], refinements: [] },
|
|
159
|
+
{ name: "extend", kind: "native", args: ["obj", "spec"], refinements: [{ name: "case", args: [] }] },
|
|
160
|
+
{ name: "extract", kind: "function", args: ["series", "width"], refinements: [{ name: "index", args: ["pos"] }, { name: "into", args: ["output"] }] },
|
|
161
|
+
{ name: "fifth", kind: "function", args: ["s"], refinements: [] },
|
|
162
|
+
{ name: "file?", kind: "function", args: ["value"], refinements: [] },
|
|
163
|
+
{ name: "find", kind: "action", args: ["series", "value"], refinements: [{ name: "part", args: ["length"] }, { name: "only", args: [] }, { name: "case", args: [] }, { name: "same", args: [] }, { name: "any", args: [] }, { name: "with", args: ["wild"] }, { name: "skip", args: ["size"] }, { name: "last", args: [] }, { name: "reverse", args: [] }, { name: "tail", args: [] }, { name: "match", args: [] }] },
|
|
164
|
+
{ name: "first", kind: "function", args: ["s"], refinements: [] },
|
|
165
|
+
{ name: "float?", kind: "function", args: ["value"], refinements: [] },
|
|
166
|
+
{ name: "forall", kind: "native", args: ["'word", "body"], refinements: [] },
|
|
167
|
+
{ name: "foreach", kind: "native", args: ["'word", "series", "body"], refinements: [] },
|
|
168
|
+
{ name: "forever", kind: "native", args: ["body"], refinements: [] },
|
|
169
|
+
{ name: "form", kind: "action", args: ["value"], refinements: [{ name: "part", args: ["limit"] }] },
|
|
170
|
+
{ name: "fourth", kind: "function", args: ["s"], refinements: [] },
|
|
171
|
+
{ name: "func", kind: "native", args: ["spec", "body"], refinements: [] },
|
|
172
|
+
{ name: "function", kind: "native", args: ["spec", "body"], refinements: [{ name: "extern", args: [] }] },
|
|
173
|
+
{ name: "function?", kind: "function", args: ["value"], refinements: [] },
|
|
174
|
+
{ name: "get", kind: "native", args: ["word"], refinements: [{ name: "any", args: [] }, { name: "case", args: [] }] },
|
|
175
|
+
{ name: "get-env", kind: "native", args: ["var"], refinements: [] },
|
|
176
|
+
{ name: "get-path?", kind: "function", args: ["value"], refinements: [] },
|
|
177
|
+
{ name: "get-word?", kind: "function", args: ["value"], refinements: [] },
|
|
178
|
+
{ name: "greater-or-equal?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
179
|
+
{ name: "greater?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
180
|
+
{ name: "handle?", kind: "function", args: ["value"], refinements: [] },
|
|
181
|
+
{ name: "has", kind: "native", args: ["vars", "body"], refinements: [] },
|
|
182
|
+
{ name: "hash?", kind: "function", args: ["value"], refinements: [] },
|
|
183
|
+
{ name: "head", kind: "action", args: ["series"], refinements: [] },
|
|
184
|
+
{ name: "head?", kind: "action", args: ["series"], refinements: [] },
|
|
185
|
+
{ name: "help", kind: "function", args: ["'word"], refinements: [] },
|
|
186
|
+
{ name: "if", kind: "native", args: ["cond", "then-blk"], refinements: [] },
|
|
187
|
+
{ name: "image?", kind: "function", args: ["value"], refinements: [] },
|
|
188
|
+
{ name: "immediate?", kind: "function", args: ["value"], refinements: [] },
|
|
189
|
+
{ name: "in", kind: "native", args: ["object", "word"], refinements: [] },
|
|
190
|
+
{ name: "index?", kind: "action", args: ["series"], refinements: [] },
|
|
191
|
+
{ name: "input", kind: "function", args: [], refinements: [] },
|
|
192
|
+
{ name: "insert", kind: "action", args: ["series", "value"], refinements: [{ name: "part", args: ["length"] }, { name: "only", args: [] }, { name: "dup", args: ["count"] }] },
|
|
193
|
+
{ name: "integer?", kind: "function", args: ["value"], refinements: [] },
|
|
194
|
+
{ name: "intersect", kind: "native", args: ["set1", "set2"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }] },
|
|
195
|
+
{ name: "issue?", kind: "function", args: ["value"], refinements: [] },
|
|
196
|
+
{ name: "last", kind: "function", args: ["s"], refinements: [] },
|
|
197
|
+
{ name: "last?", kind: "function", args: ["series"], refinements: [] },
|
|
198
|
+
{ name: "length?", kind: "action", args: ["series"], refinements: [] },
|
|
199
|
+
{ name: "lesser-or-equal?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
200
|
+
{ name: "lesser?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
201
|
+
{ name: "list-env", kind: "native", args: [], refinements: [] },
|
|
202
|
+
{ name: "lit-path?", kind: "function", args: ["value"], refinements: [] },
|
|
203
|
+
{ name: "lit-word?", kind: "function", args: ["value"], refinements: [] },
|
|
204
|
+
{ name: "load", kind: "function", args: ["source"], refinements: [{ name: "header", args: [] }, { name: "all", args: [] }, { name: "trap", args: [] }, { name: "next", args: ["position"] }, { name: "part", args: ["length"] }, { name: "into", args: ["out"] }, { name: "as", args: ["type"] }] },
|
|
205
|
+
{ name: "load-thru", kind: "function", args: ["url"], refinements: [{ name: "update", args: [] }, { name: "as", args: ["type"] }] },
|
|
206
|
+
{ name: "log-10", kind: "native", args: ["value"], refinements: [] },
|
|
207
|
+
{ name: "log-2", kind: "native", args: ["value"], refinements: [] },
|
|
208
|
+
{ name: "log-e", kind: "native", args: ["value"], refinements: [] },
|
|
209
|
+
{ name: "logic?", kind: "function", args: ["value"], refinements: [] },
|
|
210
|
+
{ name: "loop", kind: "native", args: ["count", "body"], refinements: [] },
|
|
211
|
+
{ name: "lowercase", kind: "native", args: ["string"], refinements: [{ name: "part", args: ["limit"] }] },
|
|
212
|
+
{ name: "make", kind: "action", args: ["type", "spec"], refinements: [] },
|
|
213
|
+
{ name: "make-dir", kind: "function", args: ["path"], refinements: [{ name: "deep", args: [] }] },
|
|
214
|
+
{ name: "map?", kind: "function", args: ["value"], refinements: [] },
|
|
215
|
+
{ name: "math", kind: "function", args: ["datum"], refinements: [{ name: "safe", args: [] }] },
|
|
216
|
+
{ name: "max", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
217
|
+
{ name: "min", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
218
|
+
{ name: "mod", kind: "function", args: ["a", "b"], refinements: [] },
|
|
219
|
+
{ name: "modify", kind: "action", args: ["target", "field", "value"], refinements: [{ name: "case", args: [] }] },
|
|
220
|
+
{ name: "modulo", kind: "function", args: ["a", "b"], refinements: [] },
|
|
221
|
+
{ name: "mold", kind: "action", args: ["value"], refinements: [{ name: "only", args: [] }, { name: "all", args: [] }, { name: "flat", args: [] }, { name: "part", args: ["limit"] }] },
|
|
222
|
+
{ name: "money?", kind: "function", args: ["value"], refinements: [] },
|
|
223
|
+
{ name: "move", kind: "action", args: ["origin", "target"], refinements: [{ name: "part", args: ["length"] }] },
|
|
224
|
+
{ name: "multiply", kind: "action", args: ["value1", "value2"], refinements: [] },
|
|
225
|
+
{ name: "NaN?", kind: "native", args: ["value"], refinements: [] },
|
|
226
|
+
{ name: "native?", kind: "function", args: ["value"], refinements: [] },
|
|
227
|
+
{ name: "negate", kind: "action", args: ["number"], refinements: [] },
|
|
228
|
+
{ name: "negative?", kind: "native", args: ["number"], refinements: [] },
|
|
229
|
+
{ name: "new-line", kind: "native", args: ["position", "value"], refinements: [{ name: "all", args: [] }, { name: "skip", args: ["size"] }] },
|
|
230
|
+
{ name: "new-line?", kind: "native", args: ["position"], refinements: [] },
|
|
231
|
+
{ name: "next", kind: "action", args: ["series"], refinements: [] },
|
|
232
|
+
{ name: "no-react", kind: "function", args: ["body"], refinements: [] },
|
|
233
|
+
{ name: "none?", kind: "function", args: ["value"], refinements: [] },
|
|
234
|
+
{ name: "normalize-dir", kind: "function", args: ["dir"], refinements: [] },
|
|
235
|
+
{ name: "not", kind: "native", args: ["value"], refinements: [] },
|
|
236
|
+
{ name: "not-equal?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
237
|
+
{ name: "now", kind: "native", args: [], refinements: [{ name: "year", args: [] }, { name: "month", args: [] }, { name: "day", args: [] }, { name: "time", args: [] }, { name: "zone", args: [] }, { name: "date", args: [] }, { name: "weekday", args: [] }, { name: "yearday", args: [] }, { name: "precise", args: [] }, { name: "utc", args: [] }] },
|
|
238
|
+
{ name: "number?", kind: "function", args: ["value"], refinements: [] },
|
|
239
|
+
{ name: "object?", kind: "function", args: ["value"], refinements: [] },
|
|
240
|
+
{ name: "odd?", kind: "action", args: ["number"], refinements: [] },
|
|
241
|
+
{ name: "offset?", kind: "function", args: ["series1", "series2"], refinements: [] },
|
|
242
|
+
{ name: "op?", kind: "function", args: ["value"], refinements: [] },
|
|
243
|
+
{ name: "open", kind: "action", args: ["port"], refinements: [{ name: "new", args: [] }, { name: "read", args: [] }, { name: "write", args: [] }, { name: "seek", args: [] }, { name: "allow", args: ["access"] }] },
|
|
244
|
+
{ name: "open?", kind: "action", args: ["port"], refinements: [] },
|
|
245
|
+
{ name: "or", kind: "op", args: [], refinements: [] },
|
|
246
|
+
{ name: "pad", kind: "function", args: ["str", "n"], refinements: [{ name: "left", args: [] }, { name: "with", args: ["c"] }] },
|
|
247
|
+
{ name: "pair?", kind: "function", args: ["value"], refinements: [] },
|
|
248
|
+
{ name: "paren?", kind: "function", args: ["value"], refinements: [] },
|
|
249
|
+
{ name: "parse", kind: "native", args: ["input", "rules"], refinements: [{ name: "case", args: [] }, { name: "part", args: ["length"] }, { name: "trace", args: ["callback"] }] },
|
|
250
|
+
{ name: "parse-trace", kind: "function", args: ["input", "rules"], refinements: [{ name: "case", args: [] }, { name: "part", args: ["limit"] }] },
|
|
251
|
+
{ name: "path-thru", kind: "function", args: ["url"], refinements: [] },
|
|
252
|
+
{ name: "path?", kind: "function", args: ["value"], refinements: [] },
|
|
253
|
+
{ name: "percent?", kind: "function", args: ["value"], refinements: [] },
|
|
254
|
+
{ name: "pick", kind: "action", args: ["series", "index"], refinements: [] },
|
|
255
|
+
{ name: "planar?", kind: "function", args: ["value"], refinements: [] },
|
|
256
|
+
{ name: "point2D?", kind: "function", args: ["value"], refinements: [] },
|
|
257
|
+
{ name: "point3D?", kind: "function", args: ["value"], refinements: [] },
|
|
258
|
+
{ name: "poke", kind: "action", args: ["series", "index", "value"], refinements: [] },
|
|
259
|
+
{ name: "positive?", kind: "native", args: ["number"], refinements: [] },
|
|
260
|
+
{ name: "power", kind: "action", args: ["number", "exponent"], refinements: [] },
|
|
261
|
+
{ name: "prin", kind: "native", args: ["value"], refinements: [] },
|
|
262
|
+
{ name: "print", kind: "native", args: ["value"], refinements: [] },
|
|
263
|
+
{ name: "probe", kind: "function", args: ["value"], refinements: [] },
|
|
264
|
+
{ name: "profile", kind: "function", args: ["code"], refinements: [{ name: "by", args: ["cat"] }] },
|
|
265
|
+
{ name: "put", kind: "action", args: ["series", "key", "value"], refinements: [{ name: "case", args: [] }] },
|
|
266
|
+
{ name: "query", kind: "action", args: ["target"], refinements: [] },
|
|
267
|
+
{ name: "quit", kind: "function", args: [], refinements: [{ name: "return", args: ["status"] }] },
|
|
268
|
+
{ name: "quote", kind: "function", args: [":value"], refinements: [] },
|
|
269
|
+
{ name: "random", kind: "action", args: ["value"], refinements: [{ name: "seed", args: [] }, { name: "secure", args: [] }, { name: "only", args: [] }] },
|
|
270
|
+
{ name: "react", kind: "function", args: ["reaction"], refinements: [{ name: "link", args: ["objects"] }, { name: "unlink", args: ["src"] }, { name: "later", args: [] }, { name: "with", args: ["ctx"] }] },
|
|
271
|
+
{ name: "react?", kind: "function", args: ["reactor", "field"], refinements: [{ name: "target", args: [] }] },
|
|
272
|
+
{ name: "reactor", kind: "function", args: ["spec"], refinements: [] },
|
|
273
|
+
{ name: "read", kind: "action", args: ["source"], refinements: [{ name: "part", args: ["length"] }, { name: "seek", args: ["index"] }, { name: "binary", args: [] }, { name: "lines", args: [] }, { name: "info", args: [] }, { name: "as", args: ["encoding"] }] },
|
|
274
|
+
{ name: "read-thru", kind: "function", args: ["url"], refinements: [{ name: "update", args: [] }, { name: "binary", args: [] }] },
|
|
275
|
+
{ name: "recycle", kind: "native", args: [], refinements: [{ name: "on", args: [] }, { name: "off", args: [] }] },
|
|
276
|
+
{ name: "reduce", kind: "native", args: ["value"], refinements: [{ name: "into", args: ["out"] }] },
|
|
277
|
+
{ name: "ref?", kind: "function", args: ["value"], refinements: [] },
|
|
278
|
+
{ name: "refinement?", kind: "function", args: ["value"], refinements: [] },
|
|
279
|
+
{ name: "reflect", kind: "action", args: ["value", "field"], refinements: [] },
|
|
280
|
+
{ name: "register-scheme", kind: "function", args: ["spec"], refinements: [{ name: "native", args: ["dispatch"] }] },
|
|
281
|
+
{ name: "rejoin", kind: "function", args: ["block"], refinements: [] },
|
|
282
|
+
{ name: "relate", kind: "function", args: ["'field", "reaction"], refinements: [] },
|
|
283
|
+
{ name: "remainder", kind: "action", args: ["value1", "value2"], refinements: [] },
|
|
284
|
+
{ name: "remove", kind: "action", args: ["series"], refinements: [{ name: "part", args: ["length"] }, { name: "key", args: ["key-arg"] }] },
|
|
285
|
+
{ name: "remove-each", kind: "native", args: ["'word", "data", "body"], refinements: [] },
|
|
286
|
+
{ name: "rename", kind: "action", args: ["from", "to"], refinements: [] },
|
|
287
|
+
{ name: "repeat", kind: "native", args: ["'word", "value", "body"], refinements: [] },
|
|
288
|
+
{ name: "repend", kind: "function", args: ["series", "value"], refinements: [{ name: "only", args: [] }] },
|
|
289
|
+
{ name: "replace", kind: "function", args: ["series", "pattern", "value"], refinements: [{ name: "all", args: [] }, { name: "deep", args: [] }, { name: "case", args: [] }] },
|
|
290
|
+
{ name: "return", kind: "native", args: ["value"], refinements: [] },
|
|
291
|
+
{ name: "reverse", kind: "action", args: ["series"], refinements: [{ name: "part", args: ["length"] }, { name: "skip", args: ["size"] }] },
|
|
292
|
+
{ name: "round", kind: "action", args: ["n"], refinements: [{ name: "to", args: ["scale"] }, { name: "even", args: [] }, { name: "down", args: [] }, { name: "half-down", args: [] }, { name: "floor", args: [] }, { name: "ceiling", args: [] }, { name: "half-ceiling", args: [] }] },
|
|
293
|
+
{ name: "routine", kind: "function", args: ["spec", "body"], refinements: [] },
|
|
294
|
+
{ name: "routine?", kind: "function", args: ["value"], refinements: [] },
|
|
295
|
+
{ name: "same?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
296
|
+
{ name: "save", kind: "function", args: ["where", "value"], refinements: [{ name: "header", args: ["header-data"] }, { name: "all", args: [] }, { name: "length", args: [] }, { name: "as", args: ["format"] }] },
|
|
297
|
+
{ name: "scalar?", kind: "function", args: ["value"], refinements: [] },
|
|
298
|
+
{ name: "scan", kind: "function", args: ["buffer"], refinements: [{ name: "next", args: [] }, { name: "fast", args: [] }] },
|
|
299
|
+
{ name: "second", kind: "function", args: ["s"], refinements: [] },
|
|
300
|
+
{ name: "select", kind: "action", args: ["series", "value"], refinements: [{ name: "part", args: ["length"] }, { name: "only", args: [] }, { name: "case", args: [] }, { name: "same", args: [] }, { name: "any", args: [] }, { name: "with", args: ["wild"] }, { name: "skip", args: ["size"] }, { name: "last", args: [] }, { name: "reverse", args: [] }] },
|
|
301
|
+
{ name: "send", kind: "function", args: ["target", "msg"], refinements: [{ name: "no-wait", args: [] }] },
|
|
302
|
+
{ name: "series?", kind: "function", args: ["value"], refinements: [] },
|
|
303
|
+
{ name: "set", kind: "native", args: ["word", "value"], refinements: [{ name: "any", args: [] }, { name: "case", args: [] }, { name: "only", args: [] }, { name: "some", args: [] }] },
|
|
304
|
+
{ name: "set-env", kind: "native", args: ["var", "value"], refinements: [] },
|
|
305
|
+
{ name: "set-path?", kind: "function", args: ["value"], refinements: [] },
|
|
306
|
+
{ name: "set-word?", kind: "function", args: ["value"], refinements: [] },
|
|
307
|
+
{ name: "shift", kind: "native", args: ["data", "bits"], refinements: [{ name: "left", args: [] }, { name: "logical", args: [] }] },
|
|
308
|
+
{ name: "sign?", kind: "native", args: ["number"], refinements: [] },
|
|
309
|
+
{ name: "sin", kind: "function", args: ["angle"], refinements: [] },
|
|
310
|
+
{ name: "sine", kind: "native", args: ["angle"], refinements: [{ name: "radians", args: [] }] },
|
|
311
|
+
{ name: "size?", kind: "native", args: ["file"], refinements: [] },
|
|
312
|
+
{ name: "skip", kind: "action", args: ["series", "offset"], refinements: [] },
|
|
313
|
+
{ name: "sort", kind: "action", args: ["series"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }, { name: "compare", args: ["comparator"] }, { name: "part", args: ["length"] }, { name: "all", args: [] }, { name: "reverse", args: [] }, { name: "stable", args: [] }] },
|
|
314
|
+
{ name: "source", kind: "function", args: ["'word"], refinements: [] },
|
|
315
|
+
{ name: "spec-of", kind: "function", args: ["value"], refinements: [] },
|
|
316
|
+
{ name: "split", kind: "function", args: ["series", "dlm"], refinements: [] },
|
|
317
|
+
{ name: "split-path", kind: "function", args: ["target"], refinements: [] },
|
|
318
|
+
{ name: "sqrt", kind: "function", args: ["number"], refinements: [] },
|
|
319
|
+
{ name: "square-root", kind: "native", args: ["value"], refinements: [] },
|
|
320
|
+
{ name: "stats", kind: "native", args: [], refinements: [{ name: "show", args: [] }, { name: "info", args: [] }] },
|
|
321
|
+
{ name: "stop-reactor", kind: "function", args: ["face"], refinements: [{ name: "deep", args: [] }] },
|
|
322
|
+
{ name: "strict-equal?", kind: "native", args: ["value1", "value2"], refinements: [] },
|
|
323
|
+
{ name: "string?", kind: "function", args: ["value"], refinements: [] },
|
|
324
|
+
{ name: "subtract", kind: "action", args: ["value1", "value2"], refinements: [] },
|
|
325
|
+
{ name: "suffix?", kind: "function", args: ["path"], refinements: [] },
|
|
326
|
+
{ name: "sum", kind: "function", args: ["values"], refinements: [] },
|
|
327
|
+
{ name: "swap", kind: "action", args: ["series1", "series2"], refinements: [] },
|
|
328
|
+
{ name: "switch", kind: "native", args: ["value", "cases"], refinements: [{ name: "default", args: ["case"] }] },
|
|
329
|
+
{ name: "tag?", kind: "function", args: ["value"], refinements: [] },
|
|
330
|
+
{ name: "tail", kind: "action", args: ["series"], refinements: [] },
|
|
331
|
+
{ name: "tail?", kind: "action", args: ["series"], refinements: [] },
|
|
332
|
+
{ name: "take", kind: "action", args: ["series"], refinements: [{ name: "part", args: ["length"] }, { name: "deep", args: [] }, { name: "last", args: [] }] },
|
|
333
|
+
{ name: "tan", kind: "function", args: ["angle"], refinements: [] },
|
|
334
|
+
{ name: "tangent", kind: "native", args: ["angle"], refinements: [{ name: "radians", args: [] }] },
|
|
335
|
+
{ name: "third", kind: "function", args: ["s"], refinements: [] },
|
|
336
|
+
{ name: "throw", kind: "native", args: ["value"], refinements: [{ name: "name", args: ["word"] }] },
|
|
337
|
+
{ name: "time?", kind: "function", args: ["value"], refinements: [] },
|
|
338
|
+
{ name: "to", kind: "action", args: ["type", "spec"], refinements: [] },
|
|
339
|
+
{ name: "to-binary", kind: "function", args: ["value"], refinements: [] },
|
|
340
|
+
{ name: "to-bitset", kind: "function", args: ["value"], refinements: [] },
|
|
341
|
+
{ name: "to-block", kind: "function", args: ["value"], refinements: [] },
|
|
342
|
+
{ name: "to-char", kind: "function", args: ["value"], refinements: [] },
|
|
343
|
+
{ name: "to-date", kind: "function", args: ["value"], refinements: [] },
|
|
344
|
+
{ name: "to-email", kind: "function", args: ["value"], refinements: [] },
|
|
345
|
+
{ name: "to-file", kind: "function", args: ["value"], refinements: [] },
|
|
346
|
+
{ name: "to-float", kind: "function", args: ["value"], refinements: [] },
|
|
347
|
+
{ name: "to-get-path", kind: "function", args: ["value"], refinements: [] },
|
|
348
|
+
{ name: "to-get-word", kind: "function", args: ["value"], refinements: [] },
|
|
349
|
+
{ name: "to-hash", kind: "function", args: ["value"], refinements: [] },
|
|
350
|
+
{ name: "to-hex", kind: "native", args: ["value"], refinements: [{ name: "size", args: ["length"] }] },
|
|
351
|
+
{ name: "to-image", kind: "function", args: ["value"], refinements: [] },
|
|
352
|
+
{ name: "to-integer", kind: "function", args: ["value"], refinements: [] },
|
|
353
|
+
{ name: "to-issue", kind: "function", args: ["value"], refinements: [] },
|
|
354
|
+
{ name: "to-lit-path", kind: "function", args: ["value"], refinements: [] },
|
|
355
|
+
{ name: "to-lit-word", kind: "function", args: ["value"], refinements: [] },
|
|
356
|
+
{ name: "to-local-date", kind: "function", args: ["date"], refinements: [] },
|
|
357
|
+
{ name: "to-local-file", kind: "native", args: ["path"], refinements: [{ name: "full", args: [] }] },
|
|
358
|
+
{ name: "to-logic", kind: "function", args: ["value"], refinements: [] },
|
|
359
|
+
{ name: "to-map", kind: "function", args: ["value"], refinements: [] },
|
|
360
|
+
{ name: "to-money", kind: "function", args: ["value"], refinements: [] },
|
|
361
|
+
{ name: "to-none", kind: "function", args: ["value"], refinements: [] },
|
|
362
|
+
{ name: "to-pair", kind: "function", args: ["value"], refinements: [] },
|
|
363
|
+
{ name: "to-paren", kind: "function", args: ["value"], refinements: [] },
|
|
364
|
+
{ name: "to-path", kind: "function", args: ["value"], refinements: [] },
|
|
365
|
+
{ name: "to-percent", kind: "function", args: ["value"], refinements: [] },
|
|
366
|
+
{ name: "to-point2D", kind: "function", args: ["value"], refinements: [] },
|
|
367
|
+
{ name: "to-point3D", kind: "function", args: ["value"], refinements: [] },
|
|
368
|
+
{ name: "to-red-file", kind: "function", args: ["path"], refinements: [] },
|
|
369
|
+
{ name: "to-ref", kind: "function", args: ["value"], refinements: [] },
|
|
370
|
+
{ name: "to-refinement", kind: "function", args: ["value"], refinements: [] },
|
|
371
|
+
{ name: "to-set-path", kind: "function", args: ["value"], refinements: [] },
|
|
372
|
+
{ name: "to-set-word", kind: "function", args: ["value"], refinements: [] },
|
|
373
|
+
{ name: "to-string", kind: "function", args: ["value"], refinements: [] },
|
|
374
|
+
{ name: "to-tag", kind: "function", args: ["value"], refinements: [] },
|
|
375
|
+
{ name: "to-time", kind: "function", args: ["value"], refinements: [] },
|
|
376
|
+
{ name: "to-tuple", kind: "function", args: ["value"], refinements: [] },
|
|
377
|
+
{ name: "to-typeset", kind: "function", args: ["value"], refinements: [] },
|
|
378
|
+
{ name: "to-unset", kind: "function", args: ["value"], refinements: [] },
|
|
379
|
+
{ name: "to-url", kind: "function", args: ["value"], refinements: [] },
|
|
380
|
+
{ name: "to-UTC-date", kind: "function", args: ["date"], refinements: [] },
|
|
381
|
+
{ name: "to-word", kind: "function", args: ["value"], refinements: [] },
|
|
382
|
+
{ name: "trace", kind: "function", args: ["code"], refinements: [{ name: "raw", args: [] }, { name: "deep", args: [] }, { name: "all", args: [] }, { name: "debug", args: [] }] },
|
|
383
|
+
{ name: "transcode", kind: "native", args: ["src"], refinements: [{ name: "next", args: [] }, { name: "one", args: [] }, { name: "prescan", args: [] }, { name: "scan", args: [] }, { name: "part", args: ["length"] }, { name: "into", args: ["dst"] }, { name: "trace", args: ["callback"] }] },
|
|
384
|
+
{ name: "trim", kind: "action", args: ["series"], refinements: [{ name: "head", args: [] }, { name: "tail", args: [] }, { name: "auto", args: [] }, { name: "lines", args: [] }, { name: "all", args: [] }, { name: "with", args: ["str"] }] },
|
|
385
|
+
{ name: "try", kind: "native", args: ["block"], refinements: [{ name: "all", args: [] }, { name: "keep", args: [] }] },
|
|
386
|
+
{ name: "tuple?", kind: "function", args: ["value"], refinements: [] },
|
|
387
|
+
{ name: "type?", kind: "native", args: ["value"], refinements: [{ name: "word", args: [] }] },
|
|
388
|
+
{ name: "typeset?", kind: "function", args: ["value"], refinements: [] },
|
|
389
|
+
{ name: "union", kind: "native", args: ["set1", "set2"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }] },
|
|
390
|
+
{ name: "unique", kind: "native", args: ["set"], refinements: [{ name: "case", args: [] }, { name: "skip", args: ["size"] }] },
|
|
391
|
+
{ name: "unless", kind: "native", args: ["cond", "then-blk"], refinements: [] },
|
|
392
|
+
{ name: "unset", kind: "native", args: ["word"], refinements: [] },
|
|
393
|
+
{ name: "unset?", kind: "function", args: ["value"], refinements: [] },
|
|
394
|
+
{ name: "until", kind: "native", args: ["body"], refinements: [] },
|
|
395
|
+
{ name: "update", kind: "action", args: ["port"], refinements: [] },
|
|
396
|
+
{ name: "uppercase", kind: "native", args: ["string"], refinements: [{ name: "part", args: ["limit"] }] },
|
|
397
|
+
{ name: "url?", kind: "function", args: ["value"], refinements: [] },
|
|
398
|
+
{ name: "value?", kind: "native", args: ["value"], refinements: [] },
|
|
399
|
+
{ name: "values-of", kind: "function", args: ["value"], refinements: [] },
|
|
400
|
+
{ name: "vector?", kind: "function", args: ["value"], refinements: [] },
|
|
401
|
+
{ name: "wait", kind: "native", args: ["value"], refinements: [{ name: "all", args: [] }] },
|
|
402
|
+
{ name: "what", kind: "function", args: [], refinements: [{ name: "with", args: ["text"] }, { name: "spec", args: [] }, { name: "buffer", args: [] }] },
|
|
403
|
+
{ name: "what-dir", kind: "function", args: [], refinements: [] },
|
|
404
|
+
{ name: "while", kind: "native", args: ["cond", "body"], refinements: [] },
|
|
405
|
+
{ name: "word?", kind: "function", args: ["value"], refinements: [] },
|
|
406
|
+
{ name: "words-of", kind: "function", args: ["value"], refinements: [] },
|
|
407
|
+
{ name: "write", kind: "action", args: ["destination", "data"], refinements: [{ name: "binary", args: [] }, { name: "lines", args: [] }, { name: "info", args: [] }, { name: "append", args: [] }, { name: "part", args: ["length"] }, { name: "seek", args: ["index"] }, { name: "allow", args: ["access"] }, { name: "as", args: ["encoding"] }] },
|
|
408
|
+
{ name: "xor", kind: "op", args: [], refinements: [] },
|
|
409
|
+
{ name: "zero?", kind: "native", args: ["value"], refinements: [] },
|
|
410
|
+
];
|
|
411
|
+
const redDatatypes = [
|
|
412
|
+
"action!",
|
|
413
|
+
"all-word!",
|
|
414
|
+
"any-block!",
|
|
415
|
+
"any-function!",
|
|
416
|
+
"any-list!",
|
|
417
|
+
"any-object!",
|
|
418
|
+
"any-path!",
|
|
419
|
+
"any-point!",
|
|
420
|
+
"any-string!",
|
|
421
|
+
"any-word!",
|
|
422
|
+
"binary!",
|
|
423
|
+
"bitset!",
|
|
424
|
+
"block!",
|
|
425
|
+
"char!",
|
|
426
|
+
"datatype!",
|
|
427
|
+
"date!",
|
|
428
|
+
"email!",
|
|
429
|
+
"error!",
|
|
430
|
+
"file!",
|
|
431
|
+
"float!",
|
|
432
|
+
"function!",
|
|
433
|
+
"get-path!",
|
|
434
|
+
"get-word!",
|
|
435
|
+
"handle!",
|
|
436
|
+
"hash!",
|
|
437
|
+
"image!",
|
|
438
|
+
"immediate!",
|
|
439
|
+
"integer!",
|
|
440
|
+
"issue!",
|
|
441
|
+
"lit-path!",
|
|
442
|
+
"lit-word!",
|
|
443
|
+
"logic!",
|
|
444
|
+
"map!",
|
|
445
|
+
"money!",
|
|
446
|
+
"native!",
|
|
447
|
+
"none!",
|
|
448
|
+
"number!",
|
|
449
|
+
"object!",
|
|
450
|
+
"op!",
|
|
451
|
+
"pair!",
|
|
452
|
+
"paren!",
|
|
453
|
+
"path!",
|
|
454
|
+
"percent!",
|
|
455
|
+
"planar!",
|
|
456
|
+
"point2D!",
|
|
457
|
+
"point3D!",
|
|
458
|
+
"port!",
|
|
459
|
+
"ref!",
|
|
460
|
+
"refinement!",
|
|
461
|
+
"routine!",
|
|
462
|
+
"scalar!",
|
|
463
|
+
"series!",
|
|
464
|
+
"set-path!",
|
|
465
|
+
"set-word!",
|
|
466
|
+
"string!",
|
|
467
|
+
"tag!",
|
|
468
|
+
"time!",
|
|
469
|
+
"triple!",
|
|
470
|
+
"tuple!",
|
|
471
|
+
"typeset!",
|
|
472
|
+
"unset!",
|
|
473
|
+
"url!",
|
|
474
|
+
"vector!",
|
|
475
|
+
"word!",
|
|
476
|
+
];
|
|
477
|
+
|
|
478
|
+
// How a run of characters is told from every other run of characters, which
|
|
479
|
+
// in Rebol is the whole of the language's syntax. `rebol.grammar` says why
|
|
480
|
+
// none of this can live in a grammar rule; this is the answer to the one
|
|
481
|
+
// question it asks, which is what the thing starting here is.
|
|
482
|
+
//
|
|
483
|
+
// The shape of the answer is Rebol's own. Read forward to the next delimiter,
|
|
484
|
+
// then look at what came back and decide. A left-to-right reader cannot do
|
|
485
|
+
// it, because the first character of `1-Jan-2020` and of `1.2.3` and of
|
|
486
|
+
// `1x2` and of `10:30` is the same character, and so is the first character
|
|
487
|
+
// of `-` and of `-42`.
|
|
488
|
+
//
|
|
489
|
+
// The regular expressions below were checked against Oldes' Sublime syntax
|
|
490
|
+
// for Rebol and for Red, which is what GitHub itself colours these two
|
|
491
|
+
// languages with, and against Pygments' `rebol.py`. Where the two disagreed,
|
|
492
|
+
// the corpus settled it.
|
|
493
|
+
/**
|
|
494
|
+
The characters this file asks about, as an object rather than an enum so
|
|
495
|
+
that node can run the tests without compiling them.
|
|
496
|
+
*/
|
|
497
|
+
const Ch = {
|
|
498
|
+
AngleClose: 62,
|
|
499
|
+
AngleOpen: 60,
|
|
500
|
+
Apostrophe: 39,
|
|
501
|
+
At: 64,
|
|
502
|
+
Bang: 33,
|
|
503
|
+
BraceClose: 125,
|
|
504
|
+
BraceOpen: 123,
|
|
505
|
+
BracketClose: 93,
|
|
506
|
+
BracketOpen: 91,
|
|
507
|
+
Caret: 94,
|
|
508
|
+
Colon: 58,
|
|
509
|
+
EOF: -1,
|
|
510
|
+
Formfeed: 12,
|
|
511
|
+
Hash: 35,
|
|
512
|
+
Newline: 10,
|
|
513
|
+
ParenClose: 41,
|
|
514
|
+
ParenOpen: 40,
|
|
515
|
+
Percent: 37,
|
|
516
|
+
Quote: 34,
|
|
517
|
+
Return: 13,
|
|
518
|
+
Semicolon: 59,
|
|
519
|
+
Slash: 47,
|
|
520
|
+
Space: 32,
|
|
521
|
+
Tab: 9
|
|
522
|
+
};
|
|
523
|
+
function isSpace(ch) {
|
|
524
|
+
return (ch == Ch.Space ||
|
|
525
|
+
ch == Ch.Tab ||
|
|
526
|
+
ch == Ch.Newline ||
|
|
527
|
+
ch == Ch.Return ||
|
|
528
|
+
ch == Ch.Formfeed);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
What ends a run by starting something else. Rebol's scanner calls these
|
|
532
|
+
the delimiters, and everything printable that is not one of them belongs
|
|
533
|
+
to whatever word or number is being read: `?`, `!`, `+`, `<`, `.` and `$`
|
|
534
|
+
are all ordinary letters here, which is why the classification below
|
|
535
|
+
cannot be a set of regular expressions applied left to right.
|
|
536
|
+
|
|
537
|
+
The slash is deliberately absent. It ends a token in Rebol's scanner and
|
|
538
|
+
starts a path, and reading the whole path as one run is what lets `a/b`
|
|
539
|
+
be told from the division in `a / b`, which is the same character with
|
|
540
|
+
space around it.
|
|
541
|
+
*/
|
|
542
|
+
function isRunEnd(ch) {
|
|
543
|
+
return (ch == Ch.EOF ||
|
|
544
|
+
isSpace(ch) ||
|
|
545
|
+
ch == Ch.BracketOpen ||
|
|
546
|
+
ch == Ch.BracketClose ||
|
|
547
|
+
ch == Ch.ParenOpen ||
|
|
548
|
+
ch == Ch.ParenClose ||
|
|
549
|
+
ch == Ch.BraceOpen ||
|
|
550
|
+
ch == Ch.BraceClose ||
|
|
551
|
+
ch == Ch.Quote ||
|
|
552
|
+
ch == Ch.Semicolon);
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
The characters an arrow word is made of. `<`, `>=`, `<>`, `-->` and `<|`
|
|
556
|
+
are words like any other, and a `<` followed by one of these is one of
|
|
557
|
+
them rather than the start of a tag.
|
|
558
|
+
*/
|
|
559
|
+
function isArrowChar(ch) {
|
|
560
|
+
return (ch == Ch.AngleOpen ||
|
|
561
|
+
ch == Ch.AngleClose ||
|
|
562
|
+
ch == 45 /* - */ ||
|
|
563
|
+
ch == 61 /* = */ ||
|
|
564
|
+
ch == 124 /* | */);
|
|
565
|
+
}
|
|
566
|
+
const INTEGER = /^[+-]?\d+(?:'\d+)*$/;
|
|
567
|
+
const DECIMAL = /^[+-]?(?:\d+(?:'\d+)*)?[.,]\d*(?:[eE][+-]?\d+)?$|^[+-]?\d+(?:'\d+)*[eE][+-]?\d+$/;
|
|
568
|
+
const NOT_A_NUMBER = /^[+-]?1\.#(?:inf|nan)$/i;
|
|
569
|
+
const BASED = /^(?:2#[01]+|8#[0-7]+|10#\d+|(?:16|0)#[0-9A-Fa-f]+)$/;
|
|
570
|
+
const HEX = /^(?:[0-9A-F]{2})+h$/;
|
|
571
|
+
const MONEY = /^[+-]?[A-Za-z]{0,3}\$\d+(?:[.,]\d+)?$/;
|
|
572
|
+
const PAIR = /^[+-]?\d+(?:[.,]\d+)?[xX][+-]?\d+(?:[.,]\d+)?$/;
|
|
573
|
+
const TUPLE = /^\d{1,3}(?:\.\d{1,3}){2,11}$/;
|
|
574
|
+
const TIME = /^[+-]?(?:\d+:)?\d+:\d+(?:[.,]\d+)?(?:[aApP][mM])?$/;
|
|
575
|
+
const DATE = /^\d{1,4}[-/](?:\d{1,2}|[A-Za-z]{3,9})[-/]\d{1,4}(?:\/\d{1,2}:\d{1,2}(?::\d{1,2}(?:[.,]\d+)?)?(?:[+-]\d{1,2}:\d{1,2}|[zZ])?)?$/;
|
|
576
|
+
const URL = /^[A-Za-z][A-Za-z0-9+.-]*:\S*$/;
|
|
577
|
+
/**
|
|
578
|
+
Words that decide what runs next. Every one of them is an ordinary word
|
|
579
|
+
bound to a function, and a script may rebind any of them; see the head of
|
|
580
|
+
`rebol.grammar`.
|
|
581
|
+
*/
|
|
582
|
+
const CONTROL = new Set([
|
|
583
|
+
"all",
|
|
584
|
+
"also",
|
|
585
|
+
"any",
|
|
586
|
+
"attempt",
|
|
587
|
+
"break",
|
|
588
|
+
"case",
|
|
589
|
+
"catch",
|
|
590
|
+
"continue",
|
|
591
|
+
"either",
|
|
592
|
+
"else",
|
|
593
|
+
"exit",
|
|
594
|
+
"for",
|
|
595
|
+
"forall",
|
|
596
|
+
"foreach",
|
|
597
|
+
"forever",
|
|
598
|
+
"forskip",
|
|
599
|
+
"halt",
|
|
600
|
+
"if",
|
|
601
|
+
"loop",
|
|
602
|
+
"map-each",
|
|
603
|
+
"quit",
|
|
604
|
+
"remove-each",
|
|
605
|
+
"repeat",
|
|
606
|
+
"return",
|
|
607
|
+
"switch",
|
|
608
|
+
"throw",
|
|
609
|
+
"try",
|
|
610
|
+
"unless",
|
|
611
|
+
"until",
|
|
612
|
+
"while"
|
|
613
|
+
]);
|
|
614
|
+
/**
|
|
615
|
+
The declaration words that take a spec block and a body block. The
|
|
616
|
+
grammar reads the spec, so that the arguments are definitions.
|
|
617
|
+
*/
|
|
618
|
+
const FUNCTION = new Set(["closure", "func", "funct", "function", "has"]);
|
|
619
|
+
/**
|
|
620
|
+
The loops whose first argument is a word, or a block of words, that the
|
|
621
|
+
loop sets on each pass. `forall` and `forskip` are left out, because
|
|
622
|
+
their word names a series that already exists.
|
|
623
|
+
*/
|
|
624
|
+
const LOOP = new Set(["for", "foreach", "map-each", "remove-each", "repeat"]);
|
|
625
|
+
/**
|
|
626
|
+
Words that make a thing rather than do one, which is what a reader is
|
|
627
|
+
scanning a file for when they want to know what is in it.
|
|
628
|
+
*/
|
|
629
|
+
const DECLARATION = new Set([
|
|
630
|
+
"action",
|
|
631
|
+
"closure",
|
|
632
|
+
"construct",
|
|
633
|
+
"context",
|
|
634
|
+
"declare",
|
|
635
|
+
"does",
|
|
636
|
+
"func",
|
|
637
|
+
"funct",
|
|
638
|
+
"function",
|
|
639
|
+
"has",
|
|
640
|
+
"make",
|
|
641
|
+
"module",
|
|
642
|
+
"native",
|
|
643
|
+
"object",
|
|
644
|
+
"op",
|
|
645
|
+
"routine"
|
|
646
|
+
]);
|
|
647
|
+
/**
|
|
648
|
+
The values that have a spelling but no syntax of their own.
|
|
649
|
+
*/
|
|
650
|
+
const CONSTANT = new Set([
|
|
651
|
+
"cr",
|
|
652
|
+
"escape",
|
|
653
|
+
"false",
|
|
654
|
+
"lf",
|
|
655
|
+
"newline",
|
|
656
|
+
"no",
|
|
657
|
+
"none",
|
|
658
|
+
"null",
|
|
659
|
+
"off",
|
|
660
|
+
"on",
|
|
661
|
+
"space",
|
|
662
|
+
"tab",
|
|
663
|
+
"true",
|
|
664
|
+
"yes"
|
|
665
|
+
]);
|
|
666
|
+
/**
|
|
667
|
+
The words the interpreter starts with bound to something. A word missing
|
|
668
|
+
from this list is not thereby a variable, and a word in it is not thereby
|
|
669
|
+
a function; both are guesses, and the guess is worth making because a
|
|
670
|
+
reader scanning a script is making the same one.
|
|
671
|
+
*/
|
|
672
|
+
const STANDARD = new Set([
|
|
673
|
+
"abs",
|
|
674
|
+
"absolute",
|
|
675
|
+
"add",
|
|
676
|
+
"ajoin",
|
|
677
|
+
"alter",
|
|
678
|
+
"append",
|
|
679
|
+
"apply",
|
|
680
|
+
"arccosine",
|
|
681
|
+
"arcsine",
|
|
682
|
+
"arctangent",
|
|
683
|
+
"array",
|
|
684
|
+
"as",
|
|
685
|
+
"as-byte",
|
|
686
|
+
"as-float",
|
|
687
|
+
"as-integer",
|
|
688
|
+
"as-logic",
|
|
689
|
+
"ask",
|
|
690
|
+
"at",
|
|
691
|
+
"back",
|
|
692
|
+
"bind",
|
|
693
|
+
"bitset",
|
|
694
|
+
"browse",
|
|
695
|
+
"change",
|
|
696
|
+
"charset",
|
|
697
|
+
"checksum",
|
|
698
|
+
"clear",
|
|
699
|
+
"close",
|
|
700
|
+
"collect",
|
|
701
|
+
"compose",
|
|
702
|
+
"compress",
|
|
703
|
+
"confirm",
|
|
704
|
+
"copy",
|
|
705
|
+
"cosine",
|
|
706
|
+
"debase",
|
|
707
|
+
"decompress",
|
|
708
|
+
"dehex",
|
|
709
|
+
"delete",
|
|
710
|
+
"detab",
|
|
711
|
+
"difference",
|
|
712
|
+
"divide",
|
|
713
|
+
"do",
|
|
714
|
+
"dump",
|
|
715
|
+
"enbase",
|
|
716
|
+
"entab",
|
|
717
|
+
"exclude",
|
|
718
|
+
"exists?",
|
|
719
|
+
"exp",
|
|
720
|
+
"extract",
|
|
721
|
+
"find",
|
|
722
|
+
"first",
|
|
723
|
+
"form",
|
|
724
|
+
"free",
|
|
725
|
+
"get",
|
|
726
|
+
"head",
|
|
727
|
+
"help",
|
|
728
|
+
"in",
|
|
729
|
+
"index?",
|
|
730
|
+
"input",
|
|
731
|
+
"insert",
|
|
732
|
+
"intersect",
|
|
733
|
+
"join",
|
|
734
|
+
"last",
|
|
735
|
+
"length?",
|
|
736
|
+
"list-dir",
|
|
737
|
+
"load",
|
|
738
|
+
"log-10",
|
|
739
|
+
"log-2",
|
|
740
|
+
"log-e",
|
|
741
|
+
"lowercase",
|
|
742
|
+
"max",
|
|
743
|
+
"maximum",
|
|
744
|
+
"min",
|
|
745
|
+
"minimum",
|
|
746
|
+
"mold",
|
|
747
|
+
"multiply",
|
|
748
|
+
"negate",
|
|
749
|
+
"next",
|
|
750
|
+
"not",
|
|
751
|
+
"now",
|
|
752
|
+
"open",
|
|
753
|
+
"parse",
|
|
754
|
+
"pick",
|
|
755
|
+
"poke",
|
|
756
|
+
"power",
|
|
757
|
+
"prin",
|
|
758
|
+
"print",
|
|
759
|
+
"probe",
|
|
760
|
+
"protect",
|
|
761
|
+
"query",
|
|
762
|
+
"random",
|
|
763
|
+
"read",
|
|
764
|
+
"reduce",
|
|
765
|
+
"rejoin",
|
|
766
|
+
"remainder",
|
|
767
|
+
"remove",
|
|
768
|
+
"repend",
|
|
769
|
+
"replace",
|
|
770
|
+
"reverse",
|
|
771
|
+
"round",
|
|
772
|
+
"save",
|
|
773
|
+
"second",
|
|
774
|
+
"select",
|
|
775
|
+
"set",
|
|
776
|
+
"shift",
|
|
777
|
+
"sine",
|
|
778
|
+
"skip",
|
|
779
|
+
"sort",
|
|
780
|
+
"split",
|
|
781
|
+
"square-root",
|
|
782
|
+
"subtract",
|
|
783
|
+
"swap",
|
|
784
|
+
"tail",
|
|
785
|
+
"take",
|
|
786
|
+
"tangent",
|
|
787
|
+
"third",
|
|
788
|
+
"to",
|
|
789
|
+
"trim",
|
|
790
|
+
"union",
|
|
791
|
+
"unique",
|
|
792
|
+
"unprotect",
|
|
793
|
+
"unset",
|
|
794
|
+
"uppercase",
|
|
795
|
+
"use",
|
|
796
|
+
"wait",
|
|
797
|
+
"write"
|
|
798
|
+
]);
|
|
799
|
+
/**
|
|
800
|
+
Every function a Red console starts with, read from Red's source by
|
|
801
|
+
`scripts/red-words.mjs`. In Red, these colour as builtins as well.
|
|
802
|
+
*/
|
|
803
|
+
const RED_STANDARD = new Set(redFunctions.map(f => f.name.toLowerCase()));
|
|
804
|
+
/**
|
|
805
|
+
The words spelled like operators. Rebol's `op!` values are words whose
|
|
806
|
+
first argument sits to their left, and they are spelled out of the
|
|
807
|
+
punctuation nobody else wanted.
|
|
808
|
+
*/
|
|
809
|
+
const OPERATOR = new Set([
|
|
810
|
+
"!=",
|
|
811
|
+
"!==",
|
|
812
|
+
"%",
|
|
813
|
+
"&",
|
|
814
|
+
"*",
|
|
815
|
+
"**",
|
|
816
|
+
"+",
|
|
817
|
+
"-",
|
|
818
|
+
"->",
|
|
819
|
+
"//",
|
|
820
|
+
"/",
|
|
821
|
+
"<",
|
|
822
|
+
"<-",
|
|
823
|
+
"<=",
|
|
824
|
+
"<>",
|
|
825
|
+
"<|",
|
|
826
|
+
"=",
|
|
827
|
+
"=?",
|
|
828
|
+
"==",
|
|
829
|
+
">",
|
|
830
|
+
">=",
|
|
831
|
+
">>",
|
|
832
|
+
">>>",
|
|
833
|
+
"and",
|
|
834
|
+
"and~",
|
|
835
|
+
"or",
|
|
836
|
+
"or~",
|
|
837
|
+
"xor",
|
|
838
|
+
"xor~",
|
|
839
|
+
"|",
|
|
840
|
+
"|>"
|
|
841
|
+
]);
|
|
842
|
+
/**
|
|
843
|
+
Red's preprocessor, which runs over the loaded block before anything is
|
|
844
|
+
evaluated. Every one of these is spelled like an issue and none of them
|
|
845
|
+
is one, so Rebol reads the same spellings as issues and is right to.
|
|
846
|
+
*/
|
|
847
|
+
const DIRECTIVE = new Set([
|
|
848
|
+
"#build-date",
|
|
849
|
+
"#call",
|
|
850
|
+
"#case",
|
|
851
|
+
"#custom",
|
|
852
|
+
"#default",
|
|
853
|
+
"#define",
|
|
854
|
+
"#do",
|
|
855
|
+
"#either",
|
|
856
|
+
"#enum",
|
|
857
|
+
"#export",
|
|
858
|
+
"#get",
|
|
859
|
+
"#get-definition",
|
|
860
|
+
"#if",
|
|
861
|
+
"#import",
|
|
862
|
+
"#in",
|
|
863
|
+
"#include",
|
|
864
|
+
"#inline",
|
|
865
|
+
"#inject",
|
|
866
|
+
"#local",
|
|
867
|
+
"#macro",
|
|
868
|
+
"#process",
|
|
869
|
+
"#reset",
|
|
870
|
+
"#script",
|
|
871
|
+
"#switch",
|
|
872
|
+
"#syscall",
|
|
873
|
+
"#system",
|
|
874
|
+
"#system-global",
|
|
875
|
+
"#trace",
|
|
876
|
+
"#typecheck",
|
|
877
|
+
"#u16",
|
|
878
|
+
"#user-code",
|
|
879
|
+
"#verbose"
|
|
880
|
+
]);
|
|
881
|
+
/**
|
|
882
|
+
What a run of characters turned out to be. Order is the whole of the
|
|
883
|
+
logic: a form that could be read as two things is listed under the one
|
|
884
|
+
Rebol's scanner picks.
|
|
885
|
+
*/
|
|
886
|
+
function classify(run, red) {
|
|
887
|
+
const length = run.length;
|
|
888
|
+
const first = run.charCodeAt(0);
|
|
889
|
+
// A trailing colon is the one suffix that survives everything, because
|
|
890
|
+
// `a:` cannot be anything but an assignment. `a:b` has no trailing colon
|
|
891
|
+
// and is a url, which is the rule that catches every reader out once.
|
|
892
|
+
if (length > 1 && run.charCodeAt(length - 1) == Ch.Colon) {
|
|
893
|
+
const body = run.slice(0, -1);
|
|
894
|
+
if (body.indexOf(":") < 0)
|
|
895
|
+
return body.indexOf("/") < 0 ? SetWord : SetPath;
|
|
896
|
+
}
|
|
897
|
+
if (first == Ch.Colon && length > 1) {
|
|
898
|
+
return run.indexOf("/") < 0 ? GetWord : GetPath;
|
|
899
|
+
}
|
|
900
|
+
if (first == Ch.Apostrophe && length > 1) {
|
|
901
|
+
return run.indexOf("/") < 0 ? LitWord : LitPath;
|
|
902
|
+
}
|
|
903
|
+
if (first == Ch.Percent && length > 1)
|
|
904
|
+
return File;
|
|
905
|
+
if (first == Ch.At && length > 1)
|
|
906
|
+
return Ref;
|
|
907
|
+
if (first == Ch.Hash && length > 1) {
|
|
908
|
+
return red && DIRECTIVE.has(run.toLowerCase()) ? Directive : Issue;
|
|
909
|
+
}
|
|
910
|
+
// Numbers, dates and times before anything that reads letters, because
|
|
911
|
+
// `1-Jan-2020` is spelled out of the characters a word is spelled out of.
|
|
912
|
+
if (INTEGER.test(run))
|
|
913
|
+
return Integer;
|
|
914
|
+
// An integer written in a base other than ten puts the base in front of
|
|
915
|
+
// the hash, so this is not one of the forms the hash above catches.
|
|
916
|
+
if (BASED.test(run))
|
|
917
|
+
return Integer;
|
|
918
|
+
if (DATE.test(run))
|
|
919
|
+
return Date;
|
|
920
|
+
if (TIME.test(run))
|
|
921
|
+
return Time;
|
|
922
|
+
if (TUPLE.test(run))
|
|
923
|
+
return Tuple;
|
|
924
|
+
if (PAIR.test(run))
|
|
925
|
+
return Pair;
|
|
926
|
+
if (MONEY.test(run))
|
|
927
|
+
return Money;
|
|
928
|
+
if (NOT_A_NUMBER.test(run))
|
|
929
|
+
return Decimal;
|
|
930
|
+
if (DECIMAL.test(run))
|
|
931
|
+
return Decimal;
|
|
932
|
+
if (red && HEX.test(run))
|
|
933
|
+
return Integer;
|
|
934
|
+
// A url before an email, because a url is allowed to hold one: the whole
|
|
935
|
+
// of `pop://user:pass@host.dom/` is one value, and so is the `@` in a
|
|
936
|
+
// path that names a person rather than a mailbox.
|
|
937
|
+
if (run.indexOf(":") > 0 && URL.test(run))
|
|
938
|
+
return Url;
|
|
939
|
+
if (run.indexOf("@") > 0)
|
|
940
|
+
return Email;
|
|
941
|
+
if (first == Ch.Slash)
|
|
942
|
+
return length > 1 ? Refinement : Operator;
|
|
943
|
+
const lower = run.toLowerCase();
|
|
944
|
+
if (OPERATOR.has(lower))
|
|
945
|
+
return Operator;
|
|
946
|
+
if (isArrowWord(run))
|
|
947
|
+
return Operator;
|
|
948
|
+
// `integer!` and `empty?` are ordinary words, and the two suffixes are a
|
|
949
|
+
// convention the whole language keeps: a word ending in `!` names a type,
|
|
950
|
+
// and one ending in `?` asks a question and answers with a logic value.
|
|
951
|
+
if (length > 1 && run.charCodeAt(length - 1) == Ch.Bang)
|
|
952
|
+
return Datatype;
|
|
953
|
+
if (length > 1 && run.charCodeAt(length - 1) == 63 /* ? */)
|
|
954
|
+
return QueryWord;
|
|
955
|
+
if (run.indexOf("/") > 0)
|
|
956
|
+
return Path;
|
|
957
|
+
if (CONSTANT.has(lower))
|
|
958
|
+
return Constant;
|
|
959
|
+
if (LOOP.has(lower))
|
|
960
|
+
return LoopWord;
|
|
961
|
+
if (CONTROL.has(lower))
|
|
962
|
+
return ControlWord;
|
|
963
|
+
if (FUNCTION.has(lower))
|
|
964
|
+
return FuncWord;
|
|
965
|
+
if (DECLARATION.has(lower))
|
|
966
|
+
return DeclWord;
|
|
967
|
+
if (STANDARD.has(lower))
|
|
968
|
+
return StandardWord;
|
|
969
|
+
if (red && RED_STANDARD.has(lower))
|
|
970
|
+
return StandardWord;
|
|
971
|
+
return Word;
|
|
972
|
+
}
|
|
973
|
+
function isArrowWord(run) {
|
|
974
|
+
for (let i = 0; i < run.length; i++)
|
|
975
|
+
if (!isArrowChar(run.charCodeAt(i)))
|
|
976
|
+
return false;
|
|
977
|
+
return run.length > 0;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
Every value in the language, read as one token each.
|
|
981
|
+
*/
|
|
982
|
+
const values = new lr.ExternalTokenizer((input, stack) => {
|
|
983
|
+
const first = input.next;
|
|
984
|
+
if (first == Ch.EOF || isSpace(first))
|
|
985
|
+
return;
|
|
986
|
+
// The brackets are the grammar's, and the two of them are the only
|
|
987
|
+
// structure Rebol has.
|
|
988
|
+
if (first == Ch.BracketOpen ||
|
|
989
|
+
first == Ch.BracketClose ||
|
|
990
|
+
first == Ch.ParenOpen ||
|
|
991
|
+
first == Ch.ParenClose ||
|
|
992
|
+
first == Ch.BraceClose) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
if (first == Ch.Semicolon)
|
|
996
|
+
return lineComment(input);
|
|
997
|
+
if (first == Ch.Quote)
|
|
998
|
+
return quoted(input, String$1);
|
|
999
|
+
if (first == Ch.BraceOpen)
|
|
1000
|
+
return braced(input, String$1);
|
|
1001
|
+
if (first == Ch.Hash) {
|
|
1002
|
+
const after = input.peek(1);
|
|
1003
|
+
// A shebang is an issue that the shell got to first, and only on the
|
|
1004
|
+
// line where a shell would look. Elsewhere `#!date!` is the issue it
|
|
1005
|
+
// looks like, and reading it as a comment eats the rest of the line.
|
|
1006
|
+
if (after == Ch.Bang && input.pos == 0)
|
|
1007
|
+
return lineComment(input);
|
|
1008
|
+
if (after == Ch.Quote)
|
|
1009
|
+
return character(input);
|
|
1010
|
+
if (after == Ch.BraceOpen) {
|
|
1011
|
+
input.advance(2);
|
|
1012
|
+
return binaryBody(input);
|
|
1013
|
+
}
|
|
1014
|
+
if (after == Ch.ParenOpen) {
|
|
1015
|
+
input.advance(2);
|
|
1016
|
+
return input.acceptToken(MapStart);
|
|
1017
|
+
}
|
|
1018
|
+
if (after == Ch.BracketOpen) {
|
|
1019
|
+
input.advance(2);
|
|
1020
|
+
return input.acceptToken(ConstructStart);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
// A `<` opens a tag unless what follows it makes a word out of it. Rebol
|
|
1024
|
+
// decides this the same way and for the same reason, which is why
|
|
1025
|
+
// `if a <b [...]` is a syntax error in a language with no syntax.
|
|
1026
|
+
if (first == Ch.AngleOpen) {
|
|
1027
|
+
const after = input.peek(1);
|
|
1028
|
+
if (!isArrowChar(after) && !isRunEnd(after))
|
|
1029
|
+
return tag(input);
|
|
1030
|
+
}
|
|
1031
|
+
let run = "";
|
|
1032
|
+
while (!isRunEnd(input.next)) {
|
|
1033
|
+
run += String.fromCharCode(input.next);
|
|
1034
|
+
input.advance();
|
|
1035
|
+
}
|
|
1036
|
+
if (!run)
|
|
1037
|
+
return;
|
|
1038
|
+
// Three forms end in a delimiter, so the run stops one character short of
|
|
1039
|
+
// what it is: `%"a file"`, and a binary in any of its four bases.
|
|
1040
|
+
if (input.next == Ch.BraceOpen && run.charCodeAt(run.length - 1) == Ch.Hash) {
|
|
1041
|
+
input.advance();
|
|
1042
|
+
return binaryBody(input);
|
|
1043
|
+
}
|
|
1044
|
+
if (input.next == Ch.Quote && run == "%")
|
|
1045
|
+
return quoted(input, File);
|
|
1046
|
+
return input.acceptToken(classify(run, stack.dialectEnabled(Dialect_red)));
|
|
1047
|
+
});
|
|
1048
|
+
function lineComment(input) {
|
|
1049
|
+
while (input.next != Ch.EOF && input.next != Ch.Newline)
|
|
1050
|
+
input.advance();
|
|
1051
|
+
return input.acceptToken(Comment);
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
`"..."`, which Rebol will not let cross a line. An unterminated one is
|
|
1055
|
+
accepted to the end of the line anyway, so that one missing quote costs
|
|
1056
|
+
the reader one line instead of the rest of the file.
|
|
1057
|
+
*/
|
|
1058
|
+
function quoted(input, term) {
|
|
1059
|
+
input.advance();
|
|
1060
|
+
for (;;) {
|
|
1061
|
+
if (input.next == Ch.EOF || input.next == Ch.Newline)
|
|
1062
|
+
return input.acceptToken(term);
|
|
1063
|
+
if (input.next == Ch.Caret) {
|
|
1064
|
+
input.advance();
|
|
1065
|
+
if (input.next != Ch.EOF)
|
|
1066
|
+
input.advance();
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
if (input.next == Ch.Quote) {
|
|
1070
|
+
input.advance();
|
|
1071
|
+
return input.acceptToken(term);
|
|
1072
|
+
}
|
|
1073
|
+
input.advance();
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
`{...}`, which is how a string that holds a line break is written. The
|
|
1078
|
+
braces count, so a string may hold as many as it closes, and `^{` is the
|
|
1079
|
+
one that does not count.
|
|
1080
|
+
*/
|
|
1081
|
+
function braced(input, term) {
|
|
1082
|
+
let depth = 0;
|
|
1083
|
+
for (;;) {
|
|
1084
|
+
if (input.next == Ch.EOF)
|
|
1085
|
+
return input.acceptToken(term);
|
|
1086
|
+
if (input.next == Ch.Caret) {
|
|
1087
|
+
input.advance();
|
|
1088
|
+
if (input.next != Ch.EOF)
|
|
1089
|
+
input.advance();
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
if (input.next == Ch.BraceOpen)
|
|
1093
|
+
depth++;
|
|
1094
|
+
else if (input.next == Ch.BraceClose && --depth == 0) {
|
|
1095
|
+
input.advance();
|
|
1096
|
+
return input.acceptToken(term);
|
|
1097
|
+
}
|
|
1098
|
+
input.advance();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
`#"a"`, and the escapes that make one character out of several: `^/` is
|
|
1103
|
+
a newline, `^(1234)` a codepoint, `^^` a caret.
|
|
1104
|
+
*/
|
|
1105
|
+
function character(input) {
|
|
1106
|
+
input.advance(2);
|
|
1107
|
+
for (;;) {
|
|
1108
|
+
if (input.next == Ch.EOF || input.next == Ch.Newline)
|
|
1109
|
+
return input.acceptToken(Char);
|
|
1110
|
+
if (input.next == Ch.Caret) {
|
|
1111
|
+
input.advance();
|
|
1112
|
+
if (input.next != Ch.EOF)
|
|
1113
|
+
input.advance();
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (input.next == Ch.Quote) {
|
|
1117
|
+
input.advance();
|
|
1118
|
+
return input.acceptToken(Char);
|
|
1119
|
+
}
|
|
1120
|
+
input.advance();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
What follows the brace of `#{`, `2#{`, `16#{` or `64#{`. The bases differ
|
|
1125
|
+
in what they allow and not in where they stop.
|
|
1126
|
+
*/
|
|
1127
|
+
function binaryBody(input) {
|
|
1128
|
+
for (;;) {
|
|
1129
|
+
if (input.next == Ch.EOF)
|
|
1130
|
+
return input.acceptToken(Binary);
|
|
1131
|
+
if (input.next == Ch.BraceClose) {
|
|
1132
|
+
input.advance();
|
|
1133
|
+
return input.acceptToken(Binary);
|
|
1134
|
+
}
|
|
1135
|
+
input.advance();
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
`<a href="x">`, which is one value and not markup. A quote inside it
|
|
1140
|
+
hides the `>` that would otherwise end it, which is the only reason this
|
|
1141
|
+
is not a scan for the next `>`.
|
|
1142
|
+
*/
|
|
1143
|
+
function tag(input) {
|
|
1144
|
+
input.advance();
|
|
1145
|
+
for (;;) {
|
|
1146
|
+
if (input.next == Ch.EOF || input.next == Ch.Newline)
|
|
1147
|
+
return input.acceptToken(Tag);
|
|
1148
|
+
if (input.next == Ch.Quote || input.next == Ch.Apostrophe) {
|
|
1149
|
+
const quote = input.next;
|
|
1150
|
+
input.advance();
|
|
1151
|
+
while (input.next != Ch.EOF && input.next != Ch.Newline && input.next != quote) {
|
|
1152
|
+
input.advance();
|
|
1153
|
+
}
|
|
1154
|
+
if (input.next == quote)
|
|
1155
|
+
input.advance();
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
if (input.next == Ch.AngleClose) {
|
|
1159
|
+
input.advance();
|
|
1160
|
+
return input.acceptToken(Tag);
|
|
1161
|
+
}
|
|
1162
|
+
input.advance();
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
1167
|
+
const parser = lr.LRParser.deserialize({
|
|
1168
|
+
version: 14,
|
|
1169
|
+
states: "'OQYQROOO#uQRO'#DWO#|QRO'#DXO$TQRO'#D^O$[QRO'#D`O$cQRO'#DYO'mQRO'#DbOOQQ'#Dk'#DkOOQQ'#De'#DeQYQROOOOQQ,59r,59rO*RQRO,59rOOQQ,59s,59sO*YQRO,59sOOQQ,59x,59xO*aQRO,59xOOQQ,59z,59zO*hQRO,59zO*oQRO'#DZO,wQRO,59tOOQQ'#Dl'#DlOOQQ'#Dc'#DcO/mQRO'#DdOOQQ,59|,59|OOQQ-E7c-E7cOOQQ1G/^1G/^OOQQ1G/_1G/_OOQQ1G/d1G/dOOQQ1G/f1G/fOOQQ'#D['#D[OOQQ'#Dm'#DmOOQQ'#Df'#DfO/tQRO,59uOOQQ,59u,59uO1|QRO'#DaOOQQ1G/`1G/`OOQQ'#Dg'#DgO2TQRO,5:OOOQQ,5:O,5:OOOQQ-E7d-E7dOOQQ1G/a1G/aOOQQ,59{,59{O2[QRO,59{OOQQ-E7e-E7eOOQQ1G/j1G/jOOQQ1G/g1G/g",
|
|
1170
|
+
stateData: "2c~O!^OSROS~OPVOQVOSVOTQOUVOVVOWVOXVOYVOZVO[VO]VO^TO_VO`VOaVObVOcVOdVOeUOfROgVOhVOiVOjVOkVOlVOmVOnVOoVOpVOqVOrVOsVOtVOuVOvVOyPO!RSO~OxYO~PYOx[O~PYO!P^O~PYO!P`O~PYOybOP|XQ|XS|XT|XU|XV|XW|XX|XY|XZ|X[|X]|X^|X_|X`|Xa|Xb|Xc|Xd|Xe|Xf|Xg|Xh|Xi|Xj|Xk|Xl|Xm|Xn|Xo|Xp|Xq|Xr|Xs|Xt|Xu|Xv|X!R|X![|Xx|X!P|X~OSdOUdOYdOkdOpdOvdO~OyfOP!UXQ!UXT!UXV!UXW!UXX!UXZ!UX[!UX]!UX^!UX_!UX`!UXa!UXb!UXc!UXd!UXe!UXf!UXg!UXh!UXi!UXj!UXl!UXm!UXn!UXo!UXq!UXr!UXs!UXt!UXu!UX!R!UX![!UXx!UX!P!UX~P'XOxiO~PYOxjO~PYO!PkO~PYO!PlO~PYOPnOQnOTQOVnOWnOXnOZnO[nO]nO_nO`mOanObnOcnOdmOfROgnOhnOinOjnOlnOmnOnnOonOqnOrnOsnOtnOunOxqOyPO!RSO~P'XOyrOP|aQ|aS|aT|aU|aV|aW|aX|aY|aZ|a[|a]|a^|a_|a`|aa|ab|ac|ad|ae|af|ag|ah|ai|aj|ak|al|am|an|ao|ap|aq|ar|as|at|au|av|a!R|a![|ax|a!P|a~OxvO~P'XOPnOQnOTQOVnOWnOXnOZnO[nO]nO_nO`mOanObnOcnOdmOfROgnOhnOinOjnOlnOmnOnnOonOqnOrnOsnOtnOunOxxOyPO!RSO~P'XOxyO~PYOx|O~P'XOx}O~PYO",
|
|
1171
|
+
goto: "$x!bPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP!c!c!u#T#WP!cP!c#[!u#_#f#i$T$ZPPP$a$o#WhVOPQRSXZ]_arzTnbpiVOPQRSXZ]_arzRcTTobpRscQgUTtfuRgUQXOQZPQ]QQ_RQaS[hXZ]_azRzrQpbRwpQufR{uiWOPQRSXZ]_arzUeUfuTmbp",
|
|
1172
|
+
nodeNames: "⚠ Binary Char Comment Constant ConstructStart ControlWord Datatype Date Decimal DeclWord Directive Email File FuncWord GetPath GetWord Integer Issue LitPath LitWord LoopWord MapStart Money Operator Pair Path QueryWord Ref Refinement SetPath SetWord StandardWord String Tag Time Tuple Url Word Program ] [ Block Construct Function ParamList Param ) Map ( Paren Body Loop LoopVar LoopVars",
|
|
1173
|
+
maxTerm: 63,
|
|
1174
|
+
nodeProps: [
|
|
1175
|
+
["openedBy", 40,"[",47,"("],
|
|
1176
|
+
["closedBy", 41,"]",49,")"]
|
|
1177
|
+
],
|
|
1178
|
+
skippedNodes: [0,3],
|
|
1179
|
+
repeatNodeCount: 3,
|
|
1180
|
+
tokenData: "!h~RXXYnYZn[]n]^npqnxy!Syz!X!}#O!^#P#Q!c~sT!^~XYnYZn[]n]^npqn~!XO!R~~!^O!P~~!cOy~~!hOx~",
|
|
1181
|
+
tokenizers: [0, values],
|
|
1182
|
+
topRules: {"Program":[0,39]},
|
|
1183
|
+
dialects: {red: 0},
|
|
1184
|
+
tokenPrec: 0
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
The tokens a person types a word into. In any other token, such as a
|
|
1189
|
+
string or a comment, nothing is offered.
|
|
1190
|
+
*/
|
|
1191
|
+
const wordTokens = new Set([
|
|
1192
|
+
"Constant",
|
|
1193
|
+
"ControlWord",
|
|
1194
|
+
"Datatype",
|
|
1195
|
+
"DeclWord",
|
|
1196
|
+
"FuncWord",
|
|
1197
|
+
"GetWord",
|
|
1198
|
+
"LitWord",
|
|
1199
|
+
"LoopWord",
|
|
1200
|
+
"Path",
|
|
1201
|
+
"QueryWord",
|
|
1202
|
+
"StandardWord",
|
|
1203
|
+
"Word"
|
|
1204
|
+
]);
|
|
1205
|
+
/**
|
|
1206
|
+
The nodes that hold other nodes. With the cursor between values, the
|
|
1207
|
+
innermost node is one of these.
|
|
1208
|
+
*/
|
|
1209
|
+
const containers = new Set([
|
|
1210
|
+
"Program",
|
|
1211
|
+
"Block",
|
|
1212
|
+
"Body",
|
|
1213
|
+
"Paren",
|
|
1214
|
+
"ParamList",
|
|
1215
|
+
"LoopVars",
|
|
1216
|
+
"Map",
|
|
1217
|
+
"Construct",
|
|
1218
|
+
"Function",
|
|
1219
|
+
"Loop"
|
|
1220
|
+
]);
|
|
1221
|
+
/**
|
|
1222
|
+
Words that hold a value from the start, and the ones a script reads
|
|
1223
|
+
about itself.
|
|
1224
|
+
*/
|
|
1225
|
+
const constants = [
|
|
1226
|
+
"true", "false", "none", "yes", "no", "on", "off",
|
|
1227
|
+
"newline", "tab", "space", "lf", "cr", "null", "escape", "system"
|
|
1228
|
+
];
|
|
1229
|
+
/**
|
|
1230
|
+
The words of `parse`'s dialect, offered inside the rules of a `parse`.
|
|
1231
|
+
*/
|
|
1232
|
+
const parseKeywords = [
|
|
1233
|
+
"ahead", "any", "break", "change", "collect", "copy", "end", "fail", "if",
|
|
1234
|
+
"insert", "into", "keep", "none", "not", "opt", "quote", "reject",
|
|
1235
|
+
"remove", "set", "skip", "some", "thru", "to", "while"
|
|
1236
|
+
];
|
|
1237
|
+
const snippets = [
|
|
1238
|
+
autocomplete.snippetCompletion("func [${args}] [\n\t${}\n]", { label: "func", detail: "definition", type: "keyword" }),
|
|
1239
|
+
autocomplete.snippetCompletion("function [${args}] [\n\t${}\n]", { label: "function", detail: "definition", type: "keyword" }),
|
|
1240
|
+
autocomplete.snippetCompletion("does [\n\t${}\n]", { label: "does", detail: "definition", type: "keyword" }),
|
|
1241
|
+
autocomplete.snippetCompletion("has [${locals}] [\n\t${}\n]", { label: "has", detail: "definition", type: "keyword" }),
|
|
1242
|
+
autocomplete.snippetCompletion("make object! [\n\t${}\n]", { label: "object", detail: "make object!", type: "keyword" }),
|
|
1243
|
+
autocomplete.snippetCompletion("if ${condition} [\n\t${}\n]", { label: "if", detail: "block", type: "keyword" }),
|
|
1244
|
+
autocomplete.snippetCompletion("unless ${condition} [\n\t${}\n]", { label: "unless", detail: "block", type: "keyword" }),
|
|
1245
|
+
autocomplete.snippetCompletion("either ${condition} [\n\t${}\n] [\n\t\n]", { label: "either", detail: "/ else block", type: "keyword" }),
|
|
1246
|
+
autocomplete.snippetCompletion("case [\n\t${condition} [${}]\n\ttrue [\n]", { label: "case", detail: "block", type: "keyword" }),
|
|
1247
|
+
autocomplete.snippetCompletion("switch ${value} [\n\t${case} [${}]\n]", { label: "switch", detail: "block", type: "keyword" }),
|
|
1248
|
+
autocomplete.snippetCompletion("foreach ${item} ${series} [\n\t${}\n]", { label: "foreach", detail: "loop", type: "keyword" }),
|
|
1249
|
+
autocomplete.snippetCompletion("repeat ${i} ${count} [\n\t${}\n]", { label: "repeat", detail: "loop", type: "keyword" }),
|
|
1250
|
+
autocomplete.snippetCompletion("loop ${count} [\n\t${}\n]", { label: "loop", detail: "loop", type: "keyword" }),
|
|
1251
|
+
autocomplete.snippetCompletion("while [${condition}] [\n\t${}\n]", { label: "while", detail: "loop", type: "keyword" }),
|
|
1252
|
+
autocomplete.snippetCompletion("until [\n\t${}\n\t${condition}\n]", { label: "until", detail: "loop", type: "keyword" }),
|
|
1253
|
+
autocomplete.snippetCompletion("collect [\n\t${}keep \n]", { label: "collect", detail: "block", type: "keyword" }),
|
|
1254
|
+
autocomplete.snippetCompletion("parse ${input} [\n\t${rules}\n]", { label: "parse", detail: "rules", type: "keyword" })
|
|
1255
|
+
];
|
|
1256
|
+
function signature(f) {
|
|
1257
|
+
return [...f.args.map(a => a.replace(/^['":]/, "")), ...f.refinements.map(r => "/" + r.name)].join(" ");
|
|
1258
|
+
}
|
|
1259
|
+
const redOptions = [
|
|
1260
|
+
...redFunctions.map(f => ({
|
|
1261
|
+
label: f.name,
|
|
1262
|
+
type: f.kind == "op" ? "operator" : "function",
|
|
1263
|
+
detail: signature(f)
|
|
1264
|
+
})),
|
|
1265
|
+
...redDatatypes.map(d => ({ label: d, type: "type" })),
|
|
1266
|
+
...constants.map(c => ({ label: c, type: "constant" }))
|
|
1267
|
+
];
|
|
1268
|
+
const builtins = new Map(redFunctions.map(f => [f.name, f]));
|
|
1269
|
+
const parseOptions = parseKeywords.map(k => ({
|
|
1270
|
+
label: k,
|
|
1271
|
+
type: "keyword",
|
|
1272
|
+
detail: "parse",
|
|
1273
|
+
boost: 1
|
|
1274
|
+
}));
|
|
1275
|
+
const keepOption = { label: "keep", type: "function", detail: "value /only", boost: 1 };
|
|
1276
|
+
const text = (state, node) => state.sliceDoc(node.from, node.to);
|
|
1277
|
+
/**
|
|
1278
|
+
The word a node starts with, lowercased, so `parse/case` reads as
|
|
1279
|
+
`parse`.
|
|
1280
|
+
*/
|
|
1281
|
+
const headWord = (state, node) => node ? text(state, node).toLowerCase().split("/")[0] : "";
|
|
1282
|
+
/**
|
|
1283
|
+
Whether a block is the header of the script, `Red [...]`, whose
|
|
1284
|
+
set-words name the header's fields.
|
|
1285
|
+
*/
|
|
1286
|
+
function isHeader(state, node) {
|
|
1287
|
+
var _a;
|
|
1288
|
+
const prev = node.prevSibling;
|
|
1289
|
+
return (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.name) == "Program" &&
|
|
1290
|
+
prev != null &&
|
|
1291
|
+
prev.prevSibling == null &&
|
|
1292
|
+
/^(red|rebol)$/i.test(text(state, prev)));
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
Whether a function collects the set-words in its body as locals, as
|
|
1296
|
+
Red's `function` does. In a `func`, a set-word in the body sets a word
|
|
1297
|
+
outside it.
|
|
1298
|
+
*/
|
|
1299
|
+
function collectsLocals(state, fn) {
|
|
1300
|
+
const word = fn.firstChild;
|
|
1301
|
+
return word != null && /^(function|funct)$/i.test(text(state, word));
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
A function's parameters, its refinements and its locals, with the
|
|
1305
|
+
function's own name taken from the set-word in front of it.
|
|
1306
|
+
*/
|
|
1307
|
+
function specNames(state, spec, out) {
|
|
1308
|
+
for (let c = spec.firstChild; c; c = c.nextSibling) {
|
|
1309
|
+
if (c.name == "Param") {
|
|
1310
|
+
out.push({ label: text(state, c).replace(/^['":]/, ""), type: "variable" });
|
|
1311
|
+
}
|
|
1312
|
+
else if (c.name == "Refinement") {
|
|
1313
|
+
const name = text(state, c).slice(1);
|
|
1314
|
+
if (name != "local")
|
|
1315
|
+
out.push({ label: name, type: "variable", detail: "refinement" });
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
/**
|
|
1320
|
+
The names set inside `node`: set-words and loop words. A `function`
|
|
1321
|
+
keeps its own, so its body is skipped, and so is the header.
|
|
1322
|
+
*/
|
|
1323
|
+
function setNames(state, node, out) {
|
|
1324
|
+
for (let c = node.firstChild; c; c = c.nextSibling) {
|
|
1325
|
+
if (c.name == "SetWord") {
|
|
1326
|
+
const next = c.nextSibling;
|
|
1327
|
+
const isFn = (next === null || next === void 0 ? void 0 : next.name) == "Function";
|
|
1328
|
+
const option = { label: text(state, c).slice(0, -1), type: isFn ? "function" : "variable" };
|
|
1329
|
+
const spec = isFn ? next.getChild("ParamList") : null;
|
|
1330
|
+
if (spec)
|
|
1331
|
+
option.detail = signature(userSignature(state, spec));
|
|
1332
|
+
out.push(option);
|
|
1333
|
+
}
|
|
1334
|
+
else if (c.name == "LoopVar") {
|
|
1335
|
+
out.push({ label: text(state, c), type: "variable" });
|
|
1336
|
+
}
|
|
1337
|
+
else if (c.name == "Function") {
|
|
1338
|
+
if (!collectsLocals(state, c)) {
|
|
1339
|
+
const body = c.getChild("Body");
|
|
1340
|
+
if (body)
|
|
1341
|
+
setNames(state, body, out);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
else if (c.name == "ParamList" || (c.name == "Block" && isHeader(state, c))) {
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
else if (c.firstChild) {
|
|
1348
|
+
setNames(state, c, out);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
function userSignature(state, spec) {
|
|
1353
|
+
const args = [], refinements = [];
|
|
1354
|
+
let local = false;
|
|
1355
|
+
for (let c = spec.firstChild; c; c = c.nextSibling) {
|
|
1356
|
+
if (c.name == "Refinement") {
|
|
1357
|
+
const name = text(state, c).slice(1);
|
|
1358
|
+
local = name == "local";
|
|
1359
|
+
if (!local)
|
|
1360
|
+
refinements.push({ name, args: [] });
|
|
1361
|
+
}
|
|
1362
|
+
else if (c.name == "Param" && !local) {
|
|
1363
|
+
if (refinements.length)
|
|
1364
|
+
refinements[refinements.length - 1].args.push(text(state, c));
|
|
1365
|
+
else
|
|
1366
|
+
args.push(text(state, c));
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return { args, refinements };
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
Every name in scope at `node`: the file's top-level names, and for each
|
|
1373
|
+
function around the cursor, its spec and, for a `function`, its locals.
|
|
1374
|
+
*/
|
|
1375
|
+
function namesInScope(state, node) {
|
|
1376
|
+
var _a;
|
|
1377
|
+
const out = [];
|
|
1378
|
+
const top = language.syntaxTree(state).topNode;
|
|
1379
|
+
setNames(state, top, out);
|
|
1380
|
+
for (let p = node; p; p = p.parent) {
|
|
1381
|
+
if (p.name != "Body" || ((_a = p.parent) === null || _a === void 0 ? void 0 : _a.name) != "Function")
|
|
1382
|
+
continue;
|
|
1383
|
+
const fn = p.parent;
|
|
1384
|
+
const spec = fn.getChild("ParamList");
|
|
1385
|
+
if (spec)
|
|
1386
|
+
specNames(state, spec, out);
|
|
1387
|
+
if (collectsLocals(state, fn))
|
|
1388
|
+
setNames(state, p, out);
|
|
1389
|
+
}
|
|
1390
|
+
const seen = new Set();
|
|
1391
|
+
return out.filter(o => !seen.has(o.label) && seen.add(o.label));
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
The user functions in the file, by name, with their specs, so that a
|
|
1395
|
+
path such as `greet/` can offer the refinements of `greet`.
|
|
1396
|
+
*/
|
|
1397
|
+
function userFunctions(state) {
|
|
1398
|
+
const found = new Map();
|
|
1399
|
+
language.syntaxTree(state).iterate({
|
|
1400
|
+
enter(n) {
|
|
1401
|
+
if (n.name != "SetWord")
|
|
1402
|
+
return;
|
|
1403
|
+
const next = n.node.nextSibling;
|
|
1404
|
+
const spec = (next === null || next === void 0 ? void 0 : next.name) == "Function" ? next.getChild("ParamList") : null;
|
|
1405
|
+
if (!spec)
|
|
1406
|
+
return;
|
|
1407
|
+
const name = text(state, n.node).slice(0, -1).toLowerCase();
|
|
1408
|
+
found.set(name, Object.assign({ name }, userSignature(state, spec)));
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
return found;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
Whether a block holds `parse` rules: the block after `parse input`, a
|
|
1415
|
+
block inside one, or a block set to a word that a rule uses.
|
|
1416
|
+
*/
|
|
1417
|
+
function inParseRules(state, node) {
|
|
1418
|
+
// The input of a `parse` is one to three values, and may itself be a
|
|
1419
|
+
// block, so in `if parse s [rules] [body]` the body is not a rule.
|
|
1420
|
+
const followsParse = (block) => {
|
|
1421
|
+
const between = [];
|
|
1422
|
+
for (let prev = block.prevSibling; prev && between.length < 3; prev = prev.prevSibling) {
|
|
1423
|
+
if (headWord(state, prev) == "parse") {
|
|
1424
|
+
return between.length > 0 && between.slice(0, -1).every(n => n.name != "Block");
|
|
1425
|
+
}
|
|
1426
|
+
between.push(prev);
|
|
1427
|
+
}
|
|
1428
|
+
return false;
|
|
1429
|
+
};
|
|
1430
|
+
const ruleNames = new Set();
|
|
1431
|
+
const tree = language.syntaxTree(state);
|
|
1432
|
+
tree.iterate({
|
|
1433
|
+
enter(n) {
|
|
1434
|
+
if (n.name != "Block" || !followsParse(n.node))
|
|
1435
|
+
return;
|
|
1436
|
+
// The words used inside `parse` rules name other rules.
|
|
1437
|
+
tree.iterate({
|
|
1438
|
+
from: n.from,
|
|
1439
|
+
to: n.to,
|
|
1440
|
+
enter(w) {
|
|
1441
|
+
if (w.name == "Word" && w.from >= n.from)
|
|
1442
|
+
ruleNames.add(state.sliceDoc(w.from, w.to).toLowerCase());
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
const isRuleBlock = (block) => {
|
|
1449
|
+
if (followsParse(block))
|
|
1450
|
+
return true;
|
|
1451
|
+
const setWord = block.prevSibling;
|
|
1452
|
+
return (setWord === null || setWord === void 0 ? void 0 : setWord.name) == "SetWord" && ruleNames.has(text(state, setWord).slice(0, -1).toLowerCase());
|
|
1453
|
+
};
|
|
1454
|
+
for (let p = node; p; p = p.parent) {
|
|
1455
|
+
if (p.name == "Paren" || p.name == "Body" || p.name == "ParamList")
|
|
1456
|
+
return false;
|
|
1457
|
+
if (p.name == "Block" && isRuleBlock(p))
|
|
1458
|
+
return true;
|
|
1459
|
+
}
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
Whether the cursor is in the body of a `collect`, where `keep` is bound.
|
|
1464
|
+
*/
|
|
1465
|
+
function inCollect(state, node) {
|
|
1466
|
+
for (let p = node; p; p = p.parent) {
|
|
1467
|
+
if (p.name != "Block")
|
|
1468
|
+
continue;
|
|
1469
|
+
const prev = p.prevSibling;
|
|
1470
|
+
if (headWord(state, prev) == "collect")
|
|
1471
|
+
return true;
|
|
1472
|
+
if (prev && headWord(state, prev.prevSibling) == "collect")
|
|
1473
|
+
return true;
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
Refinements for a path such as `append/` or `greet/on`.
|
|
1479
|
+
*/
|
|
1480
|
+
function refinementCompletion(context, node) {
|
|
1481
|
+
var _a;
|
|
1482
|
+
const typed = context.state.sliceDoc(node.from, context.pos);
|
|
1483
|
+
const parts = typed.split("/");
|
|
1484
|
+
const head = parts[0].toLowerCase();
|
|
1485
|
+
const fn = (_a = builtins.get(head)) !== null && _a !== void 0 ? _a : userFunctions(context.state).get(head);
|
|
1486
|
+
if (!fn)
|
|
1487
|
+
return null;
|
|
1488
|
+
const used = new Set(parts.slice(1, -1));
|
|
1489
|
+
return {
|
|
1490
|
+
from: context.pos - parts[parts.length - 1].length,
|
|
1491
|
+
options: fn.refinements
|
|
1492
|
+
.filter(r => !used.has(r.name))
|
|
1493
|
+
.map(r => ({ label: r.name, type: "property", detail: r.args.join(" ") })),
|
|
1494
|
+
validFor: /^[\w?!*+-]*$/
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
const wordChars = /^[\w?!*+~&=<>-]*$/;
|
|
1498
|
+
/**
|
|
1499
|
+
Completion for Red and Rebol: names in scope, then, for Red, the words
|
|
1500
|
+
Red starts with, the snippets and the dialect words of `parse` and
|
|
1501
|
+
`collect`.
|
|
1502
|
+
*/
|
|
1503
|
+
function completionSource(withRed) {
|
|
1504
|
+
return (context) => {
|
|
1505
|
+
const node = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
1506
|
+
let from = context.pos;
|
|
1507
|
+
let plain = true;
|
|
1508
|
+
if (wordTokens.has(node.name)) {
|
|
1509
|
+
const typed = context.state.sliceDoc(node.from, context.pos);
|
|
1510
|
+
if (node.name == "Path" || typed.includes("/"))
|
|
1511
|
+
return refinementCompletion(context, node);
|
|
1512
|
+
if (node.name == "GetWord" || node.name == "LitWord") {
|
|
1513
|
+
from = node.from + 1;
|
|
1514
|
+
plain = false;
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
from = node.from;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
else if (!containers.has(node.name) || !context.explicit) {
|
|
1521
|
+
return null;
|
|
1522
|
+
}
|
|
1523
|
+
const options = namesInScope(context.state, node);
|
|
1524
|
+
if (withRed) {
|
|
1525
|
+
options.push(...redOptions);
|
|
1526
|
+
if (plain) {
|
|
1527
|
+
options.push(...snippets);
|
|
1528
|
+
if (inParseRules(context.state, node))
|
|
1529
|
+
options.push(...parseOptions);
|
|
1530
|
+
if (inCollect(context.state, node))
|
|
1531
|
+
options.push(keepOption);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
return { from, options, validFor: wordChars };
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
Rebol, in the sense of every interpreter that reads this syntax:
|
|
1540
|
+
Rebol 2, Rebol 3 and the forks that continue it. `redLanguage` is the
|
|
1541
|
+
other dialect.
|
|
1542
|
+
*/
|
|
1543
|
+
const rebolLanguage = language.LRLanguage.define({
|
|
1544
|
+
name: "rebol",
|
|
1545
|
+
parser: parser.configure({
|
|
1546
|
+
props: [
|
|
1547
|
+
highlight.styleTags({
|
|
1548
|
+
"( )": highlight.tags.paren,
|
|
1549
|
+
"[ ]": highlight.tags.squareBracket,
|
|
1550
|
+
Binary: highlight.tags.string,
|
|
1551
|
+
Char: highlight.tags.character,
|
|
1552
|
+
Comment: highlight.tags.lineComment,
|
|
1553
|
+
// `true`, `false` and `none` are words the interpreter starts with
|
|
1554
|
+
// bound to values, and so are `tab` and `newline`. Nothing about
|
|
1555
|
+
// their spelling says so, which is why they are here and not in the
|
|
1556
|
+
// grammar.
|
|
1557
|
+
Constant: highlight.tags.bool,
|
|
1558
|
+
ConstructStart: highlight.tags.squareBracket,
|
|
1559
|
+
ControlWord: highlight.tags.controlKeyword,
|
|
1560
|
+
// A word ending in `!` names a type by a convention the whole
|
|
1561
|
+
// language keeps, including the parts of it nobody has written yet.
|
|
1562
|
+
Datatype: highlight.tags.typeName,
|
|
1563
|
+
Date: highlight.tags.literal,
|
|
1564
|
+
Decimal: highlight.tags.float,
|
|
1565
|
+
DeclWord: highlight.tags.definitionKeyword,
|
|
1566
|
+
// Red's preprocessor, which rewrites the block before anything runs.
|
|
1567
|
+
// Rebol reads the same spellings as issues, and is right to.
|
|
1568
|
+
Directive: highlight.tags.meta,
|
|
1569
|
+
Email: highlight.tags.link,
|
|
1570
|
+
File: highlight.tags.special(highlight.tags.string),
|
|
1571
|
+
FuncWord: highlight.tags.definitionKeyword,
|
|
1572
|
+
GetPath: highlight.tags.special(highlight.tags.variableName),
|
|
1573
|
+
// `:word` is what the word holds without calling it, which is the
|
|
1574
|
+
// one way to pass a function around rather than run it.
|
|
1575
|
+
GetWord: highlight.tags.special(highlight.tags.variableName),
|
|
1576
|
+
Integer: highlight.tags.integer,
|
|
1577
|
+
Issue: highlight.tags.labelName,
|
|
1578
|
+
LitPath: highlight.tags.atom,
|
|
1579
|
+
// `'word` is the word itself rather than what it stands for.
|
|
1580
|
+
LitWord: highlight.tags.atom,
|
|
1581
|
+
LoopWord: highlight.tags.controlKeyword,
|
|
1582
|
+
// The words a spec or a loop sets are definitions, whichever list
|
|
1583
|
+
// their spelling puts them in. `!` keeps the inner token's colour
|
|
1584
|
+
// from showing through.
|
|
1585
|
+
"LoopVar! Param!": highlight.tags.definition(highlight.tags.variableName),
|
|
1586
|
+
MapStart: highlight.tags.paren,
|
|
1587
|
+
Money: highlight.tags.literal,
|
|
1588
|
+
Operator: highlight.tags.operator,
|
|
1589
|
+
Pair: highlight.tags.literal,
|
|
1590
|
+
Path: highlight.tags.variableName,
|
|
1591
|
+
// A word ending in `?` asks a question and answers with a logic
|
|
1592
|
+
// value, by the same convention `!` follows.
|
|
1593
|
+
QueryWord: highlight.tags.function(highlight.tags.variableName),
|
|
1594
|
+
Ref: highlight.tags.link,
|
|
1595
|
+
// `/only` and the `b` of `a/b` are the same character doing the same
|
|
1596
|
+
// work, which is picking a branch out of something.
|
|
1597
|
+
Refinement: highlight.tags.propertyName,
|
|
1598
|
+
SetPath: highlight.tags.definition(highlight.tags.variableName),
|
|
1599
|
+
SetWord: highlight.tags.definition(highlight.tags.variableName),
|
|
1600
|
+
StandardWord: highlight.tags.standard(highlight.tags.variableName),
|
|
1601
|
+
String: highlight.tags.string,
|
|
1602
|
+
// A tag is a value and not markup. Rebol reads `<html>` a century
|
|
1603
|
+
// before anything renders it.
|
|
1604
|
+
Tag: highlight.tags.tagName,
|
|
1605
|
+
Time: highlight.tags.literal,
|
|
1606
|
+
Tuple: highlight.tags.literal,
|
|
1607
|
+
Url: highlight.tags.url,
|
|
1608
|
+
Word: highlight.tags.variableName
|
|
1609
|
+
}),
|
|
1610
|
+
language.foldNodeProp.add({
|
|
1611
|
+
Block: language.foldInside,
|
|
1612
|
+
Body: language.foldInside,
|
|
1613
|
+
LoopVars: language.foldInside,
|
|
1614
|
+
ParamList: language.foldInside,
|
|
1615
|
+
Construct: language.foldInside,
|
|
1616
|
+
Map: language.foldInside,
|
|
1617
|
+
Paren: language.foldInside
|
|
1618
|
+
}),
|
|
1619
|
+
language.indentNodeProp.add({
|
|
1620
|
+
Block: language.delimitedIndent({ closing: "]" }),
|
|
1621
|
+
Body: language.delimitedIndent({ closing: "]" }),
|
|
1622
|
+
LoopVars: language.delimitedIndent({ closing: "]" }),
|
|
1623
|
+
ParamList: language.delimitedIndent({ closing: "]" }),
|
|
1624
|
+
Construct: language.delimitedIndent({ closing: "]" }),
|
|
1625
|
+
Map: language.delimitedIndent({ closing: ")" }),
|
|
1626
|
+
Paren: language.delimitedIndent({ closing: ")" })
|
|
1627
|
+
})
|
|
1628
|
+
]
|
|
1629
|
+
}),
|
|
1630
|
+
languageData: {
|
|
1631
|
+
closeBrackets: { brackets: ["(", "[", "{", '"'] },
|
|
1632
|
+
commentTokens: { line: ";" }
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
/**
|
|
1636
|
+
Red, which is a second language with the same lexer and a preprocessor
|
|
1637
|
+
of its own. Red/System, the dialect a `.reds` file is written in, is the
|
|
1638
|
+
same syntax again with other words in it, so it reads here too.
|
|
1639
|
+
*/
|
|
1640
|
+
const redLanguage = rebolLanguage.configure({ dialect: "red" }, "red");
|
|
1641
|
+
/**
|
|
1642
|
+
Rebol support, with the names set in the file offered as completions.
|
|
1643
|
+
*/
|
|
1644
|
+
function rebol() {
|
|
1645
|
+
return new language.LanguageSupport(rebolLanguage, rebolLanguage.data.of({ autocomplete: completionSource(false) }));
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
Red support. Completion offers the names in scope, the functions and
|
|
1649
|
+
datatypes Red starts with, the refinements after a `/`, snippets, and
|
|
1650
|
+
the words of `parse` and `collect` inside their blocks.
|
|
1651
|
+
*/
|
|
1652
|
+
function red() {
|
|
1653
|
+
return new language.LanguageSupport(redLanguage, redLanguage.data.of({ autocomplete: completionSource(true) }));
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
exports.completionSource = completionSource;
|
|
1657
|
+
exports.parser = parser;
|
|
1658
|
+
exports.rebol = rebol;
|
|
1659
|
+
exports.rebolLanguage = rebolLanguage;
|
|
1660
|
+
exports.red = red;
|
|
1661
|
+
exports.redLanguage = redLanguage;
|
|
1662
|
+
exports.snippets = snippets;
|