Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline annotations #453

Open
nvasilakis opened this issue Feb 2, 2022 · 7 comments
Open

Inline annotations #453

nvasilakis opened this issue Feb 2, 2022 · 7 comments
Assignees
Labels
good first issue! Good for newcomers

Comments

@nvasilakis
Copy link
Collaborator

There are cases when a user might want to provide an annotation for a custom command or even override (force) a behavior on an existing command. In these cases, writing a full JSON in a custom directory is inconvenient. A more convenient approach would be to provide an inline annotation, which PaSh could read and expand appropriately during its pre-processing stage:

# bigram_aux_map :: (pure, args[0], args[1:4])
bigram_aux_map() {
  #...
}

Most annotations will fall under a few distinct categories, and thus expressiveness can be optimized towards the common case—after all, developers can always fall back to the JSON for the full expressive power of the annotation subsystem. This infrastructure and associated annotation economy may accelerate research in annotations.

@nvasilakis nvasilakis added the good first issue! Good for newcomers label Feb 2, 2022
@angelhof
Copy link
Member

angelhof commented Feb 2, 2022

That is a great idea! A thought:

To start quickly (and avoid implementing a parser), we could just make a few nop bash functions that express the annotation and then wrap commands with them. PaSh could then simply determine the class based on the wrapper function and remove it before execution. Example:

## pash_stateless could be a `nop` function where 
## its first argument indicates the following command's inputs, 
## and the second argument indicates the following command's outputs.
pash_stateless stdin stdout grep ...

## or
pash_pure args[:] stdout sort ...

@nvasilakis
Copy link
Collaborator Author

This is a great idea. My only (minor) worry is that if this script is not executed by PaSh, but rather by bash or zsh, it would break. A cool feature of annotations (both as JSON or comments) is that they live "on the side", not interfering with the normal execution of the script (a script that could, for example, be sourced by another Bash script).

@angelhof
Copy link
Member

angelhof commented Feb 2, 2022

That is true, however, it could be easily solved by sourcing a pash-annotation.sh library at the beginning of scripts that use that, that instantiate these functions as nops. I agree that this is still not ideal though, it is just a first solution that would enable solving the PaSh internal issues related to annotations, and only then moving to the parsing issues.

If parsing is simple, we should go straight to it :)

@nvasilakis
Copy link
Collaborator Author

This is a great idea!

(Reading your message I also realized you're talking about the simplest way to get started whereas I was talking about something closer to the final design — so I fully agree with you!)

@mgree
Copy link
Collaborator

mgree commented Feb 9, 2022

I see two options that keep compliance:

(1) use environment variables, e.g., PASH_ANNOTATIONS in some format that lets you extend it, like the path
(2) overload the noop command : so that commands of the form : pash-annotate ... will get interpreted by us.

@angelhof
Copy link
Member

In the same vein like this, we could configure other PaSh related stuff too like this (like set but for PaSh). For example, toggling PaSh's assert compiler success on and off.

@mgree
Copy link
Collaborator

mgree commented Apr 19, 2022

Yes, agreed! I think the : form is the absolute simplest, though it would add a form of invisible dynamic scoping (i.e., the last : pash-config FOO command wins). The variables pollute the environment, but you can lexically override them (PASH_CONFIG=FOO op will scope just to the function/command op) which is nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue! Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants