-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathlexer.ts
More file actions
119 lines (105 loc) · 2.9 KB
/
Copy pathlexer.ts
File metadata and controls
119 lines (105 loc) · 2.9 KB
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
import type {
BringMoveActionDescriptor,
InsertionMode,
} from "@cursorless/common";
import {
simpleActionNames,
simpleScopeTypeTypes,
surroundingPairNames,
} from "@cursorless/common";
import { marks } from "../generateSpokenForm/defaultSpokenForms/marks";
import { defaultSpokenFormMap } from "../spokenForms/defaultSpokenFormMap";
import { connectives } from "../generateSpokenForm/defaultSpokenForms/connectives";
import { CommandLexer } from "./CommandLexer";
interface Token {
type: string;
value: string;
}
const tokens: Record<string, Token> = {};
// FIXME: Remove the duplication below?
for (const simpleActionName of simpleActionNames) {
const { spokenForms } = defaultSpokenFormMap.action[simpleActionName];
for (const spokenForm of spokenForms) {
tokens[spokenForm] = {
type: "simpleActionName",
value: simpleActionName,
};
}
}
const bringMoveActionNames: BringMoveActionDescriptor["name"][] = [
"replaceWithTarget",
"moveToTarget",
];
for (const bringMoveActionName of bringMoveActionNames) {
const { spokenForms } = defaultSpokenFormMap.action[bringMoveActionName];
for (const spokenForm of spokenForms) {
tokens[spokenForm] = {
type: "bringMove",
value: bringMoveActionName,
};
}
}
const insertionModes: InsertionMode[] = ["before", "after", "to"];
for (const insertionMode of insertionModes) {
const spokenForm =
connectives[
insertionMode === "to" ? "sourceDestinationConnective" : insertionMode
];
tokens[spokenForm] = {
type: "insertionMode",
value: insertionMode,
};
}
for (const simpleScopeTypeType of simpleScopeTypeTypes) {
const { spokenForms } =
defaultSpokenFormMap.simpleScopeTypeType[simpleScopeTypeType];
for (const spokenForm of spokenForms) {
tokens[spokenForm] = {
type: "simpleScopeTypeType",
value: simpleScopeTypeType,
};
}
}
for (const pairedDelimiter of surroundingPairNames) {
const { spokenForms } = defaultSpokenFormMap.pairedDelimiter[pairedDelimiter];
for (const spokenForm of spokenForms) {
tokens[spokenForm] = {
type: "pairedDelimiter",
value: pairedDelimiter,
};
}
}
for (const [mark, spokenForm] of Object.entries(marks)) {
if (spokenForm != null) {
tokens[spokenForm] = {
type: "simpleMarkType",
value: mark,
};
}
}
defaultSpokenFormMap.modifierExtra.next.spokenForms.forEach((spokenForm) => {
tokens[spokenForm] = {
type: "direction",
value: "forward",
};
});
defaultSpokenFormMap.modifierExtra.previous.spokenForms.forEach(
(spokenForm) => {
tokens[spokenForm] = {
type: "direction",
value: "backward",
};
},
);
export const lexer = new CommandLexer({
ws: /[ \t]+/,
placeholderTarget: {
match: /<target\d*>/,
value: (text) => text.slice(7, -1),
},
token: {
match: Object.keys(tokens),
type: (text) => tokens[text].type,
value: (text) => tokens[text].value,
},
});