Modify the lexer to keep track of opening `({[` and closing `]})` delimiters.
When the lexer would emit an eol or indent outside of a recipe when there
is at least one open delimiter, emit a whitespace token instead.
This allows expressions to be split on multiple lines, like so:
x := if 'a' == 'b' {
'x'
} else {
'y'
}
This does not work inside of recipe body interpolations, although this
restriction might relaxed in the future.
Remove all manual tracking of which tokens would have been accepted by
the parser in favor of having the parser add tokens that it checks for
to a set of expected tokens, clearing them when it accepts a token, and
using the current contents of the set in error messages.
This is a massive improvement, and will make the parser easier to
modify going forward.
And, this actually solves my sole issue with hand-written parsers.
Thanks to matklad on reddit for suggesting this!
If an environment variable exists with the same key as a variable from a
`.env` file, skip the variable from the `.env` file in favor fo the key
from the environment.
Improve indentation handling in preparation for implementing inline
submodules. This changes the lexer to only parse freeform text inside
the first indent after a ':', so that just can be extended with new
indented constructs which are not recipe bodies. In addition, the lexer
should now handle multiple levels of indentation correctly.
Modifies parsing to return strongly-typed `Thunk`s, which contain both
the function implementation, as well as the correct number of arguments.
This moves unknown function and function argument count mismatch errors
to parse time.
During analysis, resolve alias targets from `Name`s to `Rc<Recipe>`,
giving us type-level assurance that alias resolution was performed, and
avoiding the need to look up alias targets in a separate table when
running.
Make analysis resolve recipe dependencies from names (`Name`) to recipes
(`Rc<Recipe>`), to give type-level certainty that resolution was performed
correctly and remove the need to look up dependencies on run.
Add a `set SETTING := VALUE` construct.
This construct is intended to be extended as needed with new settings,
but for now we're starting with `set shell := [COMMAND, ARG1, ...]`,
which allows setting the shell to use for recipe and backtick execution
in a justfile.
One of the primary reasons for adding this feature is to have a better
story on windows, where users are forced to scrounge up an `sh` binary
if they want to use `just`. This should allow them to use cmd.exe or
powershell in their justfiles, making just optionally dependency-free.
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
Just's first parser performed both parsing, i.e the transformation of a
token stream according to the language grammar, and a number of consistency
checks and analysis passes.
This made parsing and analysis quite complex, so this diff introduces a
new, much cleaner `Parser`, and moves existing analysis into a dedicated
`Analyzer`.
run::run() is pretty unwieldy. As a first step in improving it, this
commit pulls most of the argument parsing into the `config` module.
It also renames `Configuration` to `Config`, just to be easier to type.
Previously, warnings upon encountering a deprecated use `=` in
assignments, exports, and aliases would print a message without any
indication of where the offending `=` was. This diff adds a proper
`Warning` enum, and uses it to report context, as is done with
compilation and runtime errors.
Eventually, there will probably be a `crate` visibility specifier that
does the same thing as `pub(crate)`. This commit replaces `pub` with
`pub(crate)`, so when `crate` is available we can easily switch to it.
Just's dependency on brev was the cause of a
fairly deep branch of the transitive dependency
tree. To decrease build time and make the life of
packagers easier, this diff moves the functionality
that Just was using in Brev into Just itself, and
removes the dependency on Brev.
Fortunately, the only functionality that Just was
using was the output function and OutputError
enum, so this was easily done.
Color logic is fairly complicated, so moved it into its own
module.
A `Color` object now encapsulates the --color setting, which
stream we are printing to, and what color we are painting.
This way, Color::paint can just do the right thing when asked to
paint text.
Also added tests to make sure that --list and --highlight colors
are using the correct color codes.
We use EXEPATH, which points to the root of the MinGW installation
and can be used as a base for translating the unix path to the
executable in the shebang line.
If we're not on MinGW, well, we just throw up our hands and hope
for the best.
I was reusing TmpdirIoError for a few cases, but one of them
usually has more to do with the contents of the shebang line than
an actual io error involving the tmpdir. Pull it out into its own
RunError variant and improve the message.
* Run integration tests on multiple shells
To make sure that I don't break tests for shells other than my
dev-box's `sh` and the `sh` on travis, each integration test case
now runs using `sh`, `dash`, and `bash.
Moves platform specific functionality into its own module.
Thanks to @Meralis40 for starting this!
This also gets just building on windows \^_^/
Although a lot of tests still fail (✖╭╮✖)
The `PlatformInterface` trait contains functions which abstract
over platform specific functionality, with implementations for
different platforms behind #[cfg(*)] attributes.
- `make_shebang_command()` constructs a command which will execute
the given script as if by a shebang. On linux this executes the
file, on windows it runs the interpreter directly.
- `set_execute_permission()` sets the execute permission on a
file. This is a nop on windows, since all files are executable.
- `signal_from_exit_status()` extracts the signal a process was
halted by from its exit status, if it was halted by a signal.
Mostly for debugging purposes, so I can make sure behavior is
consistent across different shells. Although I suppose this might
also be of use if you've got a mega weird `sh` that you'd like to
avoid.
Defaults to `sh` so current behavior is preserved.
This is done for two reasons:
1. Such names cannot be given on the command line, since clap will
intercept them and wrongly interpret them as flags.
2. The name '---' can conflict with yaml document delimiters. Kind of
speculative, but I was thinking that it would be nice to make sure that
'---' and '...' are illegal in a justfile, so that that one can be
included in a yaml document stream. Is this silly? I am really not sure.
This is backwards incompatible, but I don't think anyone will notice,
since names that start with '-' are likely to be rare.
The recipe dependency resolver had a bug which caused it to not resolve
dependencies after the first.
This caused the parameter check later in the program to crash.
Added a test and fixed it.
Fixes#148.
Previously, only one recipe with parameters could be passed on the
command line. This was to avoid confusion in case the number of
parameters a recipe took changed, and wound up using as an argument was
was once a recipe.
However, I don't think this is actually particularly confusing in
practice, and could be a slightly annoying limitation.
Now, any number of recipes with parameters may be given on the command
line.
Fixes#70
Recipes may now have a final variadic parameter:
```make
foo bar+:
@echo {{bar}}
```
Variadic parameters accept one or more arguments, and expand to a string containing those arguments separated by spaces:
```sh
$ just foo a b c d e
a b c d e
```
I elected to accept one or more arguments instead of zero or more arguments since unexpectedly empty arguments can sometimes be dangerous.
```make
clean dir:
rm -rf {{dir}}/bin
```
If `dir` is empty in the above recipe, you'll delete `/bin`, which is probably not what was intended.
The grammar now permits blank lines in recipes.
Note that inside of recipes, the token `NEWLINE` is used instead of the
non-terminal `eol`. This is because an `eol` optionally includes a
comment, whereas inside recipes bodies comments get no special
treatment.
Blank lines were being ignored by the parser, so lines would be reported
incorrectly in error messages from shebang recipes. Blank lines are now
included by the parser, so shebang recipes expand to have the non-blank
lines in the expected place in the file.
Causes all recipe lines to be printed, regardless of --quiet or `@`.
Prints the name of each recipe before running it. Hopefully useful for
diagnosing problems.
If a `#...` comment appears on the line immediately before a recipe, it
is considered to be a doc comment for that recipe.
Doc comments will be printed when recipes are `--list`ed or `--dump`ed.
Also adds some color to the `--list`ing.
Fixes#84
Some ugly code, but not as bad as I thought.
Elected not to go with indentation based line continuations. Too many
weird edge cases and feels like a gratuitious incompatibility with make.
Fixes#9
Looks like this:
```make
recipe argument default-argument='default value':
echo argument is {{argument}}
echo default-argument is {{default-argument}}
```
Thanks @deckarep for the feature request!
Fixes#49
Input may contain tabs and other characters whose byte widths do not
correspond to their display widths. This causes error context
underlining to be off when lines contain those characters
Fixed by properly accounting for the display width of characters, as
well as replacing tabs with spaces when printing error messages.
This is a pretty gross commit, since it also includes a lot of
unrelated refactoring, especially of how error messages are printed.
Also adds a lint recipe that prints lines over 100 characters
To test, I added a `--color=[auto|always|never]` option that defaults to
auto in normal use, but can be forced to `always` for testing. In `auto`
mode it defers to `atty` to figure out if the current stream is a
terminal and uses color if so.
Color printing is controlled by the `alternate` formatting flag.
When printing an error message, using `{:#}` will print it with colors
and `{}` will print it normally.
I was using the width of the index of the line, not the displayed line
number, which is the index + 1, which could cause the error message to
be misaligned.
Fixed it, and added a test that checks for this.
I had previously not included the line for some error messages, but I
don't think that I had a good reason why, and they look pretty good,
so adding them back for consistency.
Surround variables with backticks, capitalize first letter of error
message, inflect properly depending on number of unknown overrides, and
improve wording.
Also added build dependency to `filter` recipe.