Skip to content

Commit 850f114

Browse files
committed
Cleanup grammar.ne
1 parent 95fe1ac commit 850f114

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

packages/cursorless-vscode/src/keyboard/KeyboardHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export default class KeyboardHandler {
146146

147147
isDisposed = true;
148148
const index = this.listeners.indexOf(listenerEntry);
149+
// Call handleCancelled on all listeners that were pushed after this
150+
// one. Eg if you're in the middle of typing a command and we turn off
151+
// the modal mode, we want to cancel the command
149152
this.listeners
150153
.slice(index + 1)
151154
.reverse()

packages/cursorless-vscode/src/keyboard/grammar/generated/grammar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// @ts-ignore
55
function id(d: any[]): any { return d[0]; }
66
declare var makeRange: any;
7-
declare var vscodeCommand: any;
87
declare var relative: any;
98
declare var action: any;
9+
declare var vscodeCommand: any;
1010
declare var simpleScopeTypeType: any;
1111
declare var color: any;
1212
declare var shape: any;
@@ -51,7 +51,7 @@ const grammar: Grammar = {
5151
{"name": "main", "symbols": [(lexer.has("makeRange") ? {type: "makeRange"} : makeRange), "decoratedMark"], "postprocess":
5252
command("targetDecoratedMarkExtend", [null, "decoratedMark"])
5353
},
54-
{"name": "main", "symbols": [(lexer.has("vscodeCommand") ? {type: "vscodeCommand"} : vscodeCommand)], "postprocess": command("vscodeCommand", ["command"])},
54+
{"name": "main", "symbols": ["scopeType"], "postprocess": command("targetScopeType", ["scopeType"])},
5555
{"name": "main$ebnf$1", "symbols": ["offset"], "postprocess": id},
5656
{"name": "main$ebnf$1", "symbols": [], "postprocess": () => null},
5757
{"name": "main$ebnf$2", "symbols": ["number"], "postprocess": id},
@@ -63,7 +63,7 @@ const grammar: Grammar = {
6363
)
6464
},
6565
{"name": "main", "symbols": [(lexer.has("action") ? {type: "action"} : action)], "postprocess": command("performSimpleActionOnTarget", ["actionName"])},
66-
{"name": "main", "symbols": ["scopeType"], "postprocess": command("targetScopeType", ["scopeType"])},
66+
{"name": "main", "symbols": [(lexer.has("vscodeCommand") ? {type: "vscodeCommand"} : vscodeCommand)], "postprocess": command("vscodeCommand", ["command"])},
6767
{"name": "scopeType", "symbols": [(lexer.has("simpleScopeTypeType") ? {type: "simpleScopeTypeType"} : simpleScopeTypeType)], "postprocess": capture("type")},
6868
{"name": "decoratedMark", "symbols": [(lexer.has("color") ? {type: "color"} : color)], "postprocess": capture("color")},
6969
{"name": "decoratedMark", "symbols": [(lexer.has("shape") ? {type: "shape"} : shape)], "postprocess": capture("shape")},

packages/cursorless-vscode/src/keyboard/grammar/getAcceptableTokenTypes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ function getMetadata(state: nearley.State) {
4747
function getRootStates(state: nearley.State) {
4848
/** A queue of states to process; ensures we don't try to process state twice */
4949
const queue = new WorkQueue(state);
50-
const roots = new Set<State>();
50+
const roots: State[] = [];
5151

5252
for (const state of queue) {
5353
queue.push(...state.wantedBy);
5454

5555
if (state.wantedBy.length === 0) {
56-
roots.add(state);
56+
roots.push(state);
5757
}
5858
}
5959

60-
return [...roots];
60+
return roots;
6161
}
6262

6363
/**
@@ -69,7 +69,7 @@ function getRootStates(state: nearley.State) {
6969
*/
7070
function computePartialArg(state: nearley.State) {
7171
const { argNames } = getMetadata(state);
72-
let currentState: State = state;
72+
let currentState = state;
7373
const partialArg: Record<string, any> = {};
7474

7575
while (currentState.dot > 0) {

packages/cursorless-vscode/src/keyboard/grammar/grammar.ne

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@ import { lexer } from "../lexer";
55
%}
66
@lexer lexer
77

8+
# ===================== Top-level commands ===================
9+
# "air"
810
main -> decoratedMark {% command("targetDecoratedMarkReplace", ["decoratedMark"]) %}
911

12+
# "past air"
1013
main -> %makeRange decoratedMark {%
1114
command("targetDecoratedMarkExtend", [null, "decoratedMark"])
1215
%}
1316

14-
main -> %vscodeCommand {% command("vscodeCommand", ["command"]) %}
17+
# "funk"
18+
main -> scopeType {% command("targetScopeType", ["scopeType"]) %}
1519

20+
# "third next two funks"
21+
# "third previous two funks"
1622
main -> offset:? %relative number:? scopeType {%
1723
command(
1824
"targetRelativeScope",
1925
["offset", null, "length", "scopeType"],
2026
)
2127
%}
2228

29+
# "chuck"
2330
main -> %action {% command("performSimpleActionOnTarget", ["actionName"]) %}
2431

25-
main -> scopeType {% command("targetScopeType", ["scopeType"]) %}
32+
# Custom vscode command
33+
main -> %vscodeCommand {% command("vscodeCommand", ["command"]) %}
2634

35+
# ========================== Captures =========================
2736
scopeType -> %simpleScopeTypeType {% capture("type") %}
2837

2938
decoratedMark -> %color {% capture("color") %}
@@ -35,6 +44,7 @@ decoratedMark -> %combineColorAndShape %shape %color {%
3544
capture(null, "shape", "color")
3645
%}
3746

47+
# Contains a direction and a number for use with relative and ordinal
3848
offset -> %direction:? number {% capture("direction", "number") %}
3949
offset -> number %direction {% capture("number", "direction") %}
4050
offset -> %direction {% capture("direction") %}

0 commit comments

Comments
 (0)