Skip to content

Commit

Permalink
Cleanup grammar.ne
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Nov 24, 2023
1 parent 95fe1ac commit 850f114
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/cursorless-vscode/src/keyboard/KeyboardHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export default class KeyboardHandler {

isDisposed = true;
const index = this.listeners.indexOf(listenerEntry);
// Call handleCancelled on all listeners that were pushed after this
// one. Eg if you're in the middle of typing a command and we turn off
// the modal mode, we want to cancel the command
this.listeners
.slice(index + 1)
.reverse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// @ts-ignore
function id(d: any[]): any { return d[0]; }
declare var makeRange: any;
declare var vscodeCommand: any;
declare var relative: any;
declare var action: any;
declare var vscodeCommand: any;
declare var simpleScopeTypeType: any;
declare var color: any;
declare var shape: any;
Expand Down Expand Up @@ -51,7 +51,7 @@ const grammar: Grammar = {
{"name": "main", "symbols": [(lexer.has("makeRange") ? {type: "makeRange"} : makeRange), "decoratedMark"], "postprocess":
command("targetDecoratedMarkExtend", [null, "decoratedMark"])
},
{"name": "main", "symbols": [(lexer.has("vscodeCommand") ? {type: "vscodeCommand"} : vscodeCommand)], "postprocess": command("vscodeCommand", ["command"])},
{"name": "main", "symbols": ["scopeType"], "postprocess": command("targetScopeType", ["scopeType"])},
{"name": "main$ebnf$1", "symbols": ["offset"], "postprocess": id},
{"name": "main$ebnf$1", "symbols": [], "postprocess": () => null},
{"name": "main$ebnf$2", "symbols": ["number"], "postprocess": id},
Expand All @@ -63,7 +63,7 @@ const grammar: Grammar = {
)
},
{"name": "main", "symbols": [(lexer.has("action") ? {type: "action"} : action)], "postprocess": command("performSimpleActionOnTarget", ["actionName"])},
{"name": "main", "symbols": ["scopeType"], "postprocess": command("targetScopeType", ["scopeType"])},
{"name": "main", "symbols": [(lexer.has("vscodeCommand") ? {type: "vscodeCommand"} : vscodeCommand)], "postprocess": command("vscodeCommand", ["command"])},
{"name": "scopeType", "symbols": [(lexer.has("simpleScopeTypeType") ? {type: "simpleScopeTypeType"} : simpleScopeTypeType)], "postprocess": capture("type")},
{"name": "decoratedMark", "symbols": [(lexer.has("color") ? {type: "color"} : color)], "postprocess": capture("color")},
{"name": "decoratedMark", "symbols": [(lexer.has("shape") ? {type: "shape"} : shape)], "postprocess": capture("shape")},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ function getMetadata(state: nearley.State) {
function getRootStates(state: nearley.State) {
/** A queue of states to process; ensures we don't try to process state twice */
const queue = new WorkQueue(state);
const roots = new Set<State>();
const roots: State[] = [];

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

if (state.wantedBy.length === 0) {
roots.add(state);
roots.push(state);
}
}

return [...roots];
return roots;
}

/**
Expand All @@ -69,7 +69,7 @@ function getRootStates(state: nearley.State) {
*/
function computePartialArg(state: nearley.State) {
const { argNames } = getMetadata(state);
let currentState: State = state;
let currentState = state;
const partialArg: Record<string, any> = {};

while (currentState.dot > 0) {
Expand Down
14 changes: 12 additions & 2 deletions packages/cursorless-vscode/src/keyboard/grammar/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@ import { lexer } from "../lexer";
%}
@lexer lexer

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

# "past air"
main -> %makeRange decoratedMark {%
command("targetDecoratedMarkExtend", [null, "decoratedMark"])
%}

main -> %vscodeCommand {% command("vscodeCommand", ["command"]) %}
# "funk"
main -> scopeType {% command("targetScopeType", ["scopeType"]) %}

# "third next two funks"
# "third previous two funks"
main -> offset:? %relative number:? scopeType {%
command(
"targetRelativeScope",
["offset", null, "length", "scopeType"],
)
%}

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

main -> scopeType {% command("targetScopeType", ["scopeType"]) %}
# Custom vscode command
main -> %vscodeCommand {% command("vscodeCommand", ["command"]) %}

# ========================== Captures =========================
scopeType -> %simpleScopeTypeType {% capture("type") %}

decoratedMark -> %color {% capture("color") %}
Expand All @@ -35,6 +44,7 @@ decoratedMark -> %combineColorAndShape %shape %color {%
capture(null, "shape", "color")
%}

# Contains a direction and a number for use with relative and ordinal
offset -> %direction:? number {% capture("direction", "number") %}
offset -> number %direction {% capture("number", "direction") %}
offset -> %direction {% capture("direction") %}
Expand Down

0 comments on commit 850f114

Please sign in to comment.