cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.09k stars 77 forks source link

Extending custom grammar #2436

Closed AndreasArvidsson closed 2 weeks ago

AndreasArvidsson commented 2 weeks ago

Extending custom grammar with actions

https://github.com/cursorless-dev/cursorless/issues/492

Checklist

AndreasArvidsson commented 2 weeks ago

@pokey I wonder where we want to put the place where we evaluate the input text and merge with eventual input target? TargetMark expects a full target descriptor not a partial one. That kind of means it needs to go into TargetPipelineRunner.ts

pokey commented 2 weeks ago

Can't we just do it right after inference? Or during inference?

AndreasArvidsson commented 2 weeks ago

That is probably the earliest possible.

pokey commented 2 weeks ago

Ignore the rest of this message; I have an idea. I'll take a swing after lunch so leave this for now unless you are already working on it or have a good way forward


Ok I think what you want to do is add a new PartialTargetMark that is equivalent to TargetMark but with a partial target

Then if you encounter a parsed action, you will get an ActionDescriptor back from the parser. You look in that descriptor for placeholders, and fill them in with the partial targets you have from the parsed action, then recursively call run action on the ActionDescriptor

In inferFullTargets, you

AndreasArvidsson commented 2 weeks ago

I don't have time to look at this today so please go ahead!

pokey commented 2 weeks ago

Thought about it some more and I wonder if the way we automatically infer placeholder index is too fancy. I wonder if it will make it harder to do things where we reuse a target. For example, what if we wanted to do "take past next line ". We could do that by just passing the same target twice in the input target list, but that feels a bit strange, and makes it slightly more awkward to do other fancy things I was thinking like using target templates to create custom modifiers, eg " past next line " could be used as a modifier via a special csv, or in keyboard config

We could handle that in the same way, by just passing a bunch of copies of the input, but it feels weird

pokey commented 2 weeks ago

I'd be tempted to just switch to talon-style placeholder numbering

AndreasArvidsson commented 2 weeks ago

Let's make it private and ship it so we can try it out

pokey commented 2 weeks ago

idk something's not right here. I almost feel like the $1 token should indicate what type of thing it is. For example, what if the user just uses "take $1 $2 $3" as the content to parse. How is our parser supposed to know what type each of those things are supposed to be? It could be "take <number> <scope>s <target>" or "take <scope> <scope> <target>" or probably plenty of other things. Idk something doesn't feel right

AndreasArvidsson commented 2 weeks ago

Yeah if this makes the grammar become ambiguous we definite to have a problem