Skip to content

Commit 7c4814f

Browse files
Merge branch 'grammar_test' of github.com:cursorless-dev/cursorless into grammar_test
2 parents 5bf2aa5 + a8957d0 commit 7c4814f

File tree

18 files changed

+1470
-57
lines changed

18 files changed

+1470
-57
lines changed

packages/common/src/errors.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ export class NoContainingScopeError extends Error {
3636
this.name = "NoContainingScopeError";
3737
}
3838
}
39+
40+
export class NoSpokenFormError extends Error {
41+
constructor(type: string) {
42+
super(`No spoken form for: ${type}`);
43+
}
44+
}
45+
46+
export class AmbiguousSpokenFormError extends Error {
47+
constructor(type: string) {
48+
super(`Ambiguous spoken form for: ${type}`);
49+
}
50+
}

packages/common/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ export * from "./getFakeCommandServerApi";
8686
export * from "./types/TestCaseFixture";
8787
export * from "./util/getEnvironmentVariableStrict";
8888
export * from "./util/CompositeKeyDefaultMap";
89+
export * from "./spokenForms/actions";
90+
export * from "./spokenForms/characters";
91+
export * from "./spokenForms/connectives";
92+
export * from "./spokenForms/marks";
93+
export * from "./spokenForms/modifiers";
94+
export * from "./spokenForms/numbers";
95+
export * from "./spokenForms/snippets";
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ActionType } from "..";
2+
3+
const actions: Record<ActionType, string | null> = {
4+
scrollToBottom: "bottom",
5+
toggleLineBreakpoint: "break point",
6+
cutToClipboard: "carve",
7+
scrollToCenter: "center",
8+
clearAndSetSelection: "change",
9+
remove: "chuck",
10+
insertCopyBefore: "clone up",
11+
insertCopyAfter: "clone",
12+
toggleLineComment: "comment",
13+
copyToClipboard: "copy",
14+
scrollToTop: "crown",
15+
outdentLine: "dedent",
16+
revealDefinition: "define",
17+
editNewLineBefore: "drink",
18+
insertEmptyLineBefore: "drop",
19+
extractVariable: "extract",
20+
insertEmptyLineAfter: "float",
21+
foldRegion: "fold",
22+
followLink: "follow",
23+
deselect: "give",
24+
highlight: "highlight",
25+
showHover: "hover",
26+
indentLine: "indent",
27+
showDebugHover: "inspect",
28+
setSelectionAfter: "post",
29+
editNewLineAfter: "pour",
30+
setSelectionBefore: "pre",
31+
insertEmptyLinesAround: "puff",
32+
showQuickFix: "quick fix",
33+
showReferences: "reference",
34+
rename: "rename",
35+
reverseTargets: "reverse",
36+
findInWorkspace: "scout all",
37+
randomizeTargets: "shuffle",
38+
generateSnippet: "snippet make",
39+
sortTargets: "sort",
40+
setSelection: "take",
41+
revealTypeDefinition: "type deaf",
42+
unfoldRegion: "unfold",
43+
callAsFunction: "call",
44+
swapTargets: "swap",
45+
replaceWithTarget: "bring",
46+
moveToTarget: "move",
47+
wrapWithPairedDelimiter: "wrap",
48+
wrapWithSnippet: "wrap",
49+
rewrapWithPairedDelimiter: "repack",
50+
insertSnippet: "snippet",
51+
pasteFromClipboard: "paste",
52+
53+
["experimental.setInstanceReference"]: "from",
54+
55+
editNew: null,
56+
executeCommand: null,
57+
getText: null,
58+
replace: null,
59+
60+
// applyFormatter: "format",
61+
// findInDocument: "scout",
62+
// nextHomophone: "phones",
63+
};
64+
65+
export function actionToSpokenForm(name: ActionType): string {
66+
if (name === "wrapWithSnippet") {
67+
name = "wrapWithPairedDelimiter";
68+
}
69+
const result = actions[name];
70+
if (result == null) {
71+
throw Error(`Unknown action '${name}'`);
72+
}
73+
return result;
74+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import { NoSpokenFormError } from "..";
4+
5+
// https://github.com/talonhub/community/blob/9acb6c9659bb0c9b794a7b7126d025603b4ed726/core/keys/keys.py
6+
7+
const alphabet =
8+
"air bat cap drum each fine gust harp sit jury crunch look made near odd pit quench red sun trap urge vest whale plex yank zip"
9+
.split(" ")
10+
.reduce<Record<string, string>>((result, phrase, index) => {
11+
const letter = String.fromCharCode("a".charCodeAt(0) + index);
12+
result[letter] = phrase;
13+
return result;
14+
}, {});
15+
16+
const digits = "zero one two three four five six seven eight nine"
17+
.split(" ")
18+
.reduce<Record<string, string>>((result, phrase, index) => {
19+
result[index.toString()] = phrase;
20+
return result;
21+
}, {});
22+
23+
const symbols = {
24+
".": "dot",
25+
",": "comma",
26+
";": "semicolon",
27+
":": "colon",
28+
"!": "bang",
29+
"*": "asterisk",
30+
"@": "at sign",
31+
"&": "ampersand",
32+
"?": "question",
33+
"/": "slash",
34+
"\\": "backslash",
35+
"-": "dash",
36+
"=": "equals",
37+
"+": "plus",
38+
"~": "tilde",
39+
_: "underscore",
40+
"#": "hash",
41+
"%": "percent",
42+
"^": "caret",
43+
"|": "pipe",
44+
$: "dollar",
45+
"£": "pound",
46+
47+
"'": "quote",
48+
'"': "double quote",
49+
"`": "back tick",
50+
51+
"(": "paren",
52+
")": "right paren",
53+
"{": "brace",
54+
"}": "right brace",
55+
"[": "square",
56+
"]": "right square",
57+
"<": "angle",
58+
">": "right angle",
59+
};
60+
61+
const characters: Record<string, string> = {
62+
...alphabet,
63+
...digits,
64+
...symbols,
65+
};
66+
67+
export function characterToSpokenForm(char: string): string {
68+
const result = characters[char];
69+
if (result == null) {
70+
throw new NoSpokenFormError(`Unknown character '${char}'`);
71+
}
72+
return result;
73+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const connectives = {
2+
rangeExclusive: "between",
3+
rangeInclusive: "past",
4+
// "rangeExcludingStart": "-",
5+
rangeExcludingEnd: "until",
6+
listConnective: "and",
7+
swapConnective: "with",
8+
sourceDestinationConnective: "to",
9+
before: "before",
10+
after: "after",
11+
verticalRange: "slice",
12+
13+
previous: "previous",
14+
next: "next",
15+
forward: "forward",
16+
backward: "backward",
17+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const hatColors: Record<string, string> = {
2+
blue: "blue",
3+
green: "green",
4+
red: "red",
5+
pink: "pink",
6+
yellow: "yellow",
7+
userColor1: "navy",
8+
userColor2: "apricot",
9+
};
10+
11+
const hatShapes: Record<string, string> = {
12+
ex: "ex",
13+
fox: "fox",
14+
wing: "wing",
15+
hole: "hole",
16+
frame: "frame",
17+
curve: "curve",
18+
eye: "eye",
19+
play: "play",
20+
crosshairs: "cross",
21+
bolt: "bolt",
22+
};
23+
24+
const marks: Record<string, string | null> = {
25+
cursor: "this",
26+
that: "that",
27+
source: "source",
28+
nothing: "nothing",
29+
30+
explicit: null,
31+
};
32+
33+
export const lineDirections = {
34+
modulo100: "row",
35+
relativeUp: "up",
36+
relativeDown: "down",
37+
};
38+
39+
export function hatColorToSpokenForm(color: string): string {
40+
const result = hatColors[color];
41+
if (result == null) {
42+
throw Error(`Unknown hat color '${color}'`);
43+
}
44+
return result;
45+
}
46+
47+
export function hatShapeToSpokenForm(shape: string): string {
48+
const result = hatShapes[shape];
49+
if (result == null) {
50+
throw Error(`Unknown hat shape '${shape}'`);
51+
}
52+
return result;
53+
}
54+
55+
export function markTypeToSpokenForm(mark: string): string {
56+
const result = marks[mark];
57+
if (result == null) {
58+
throw Error(`Unknown mark '${mark}'`);
59+
}
60+
return result;
61+
}

0 commit comments

Comments
 (0)