Skip to content

Commit

Permalink
Merge branch 'master' into parse-before-load
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak authored Aug 8, 2023
2 parents 2e077a7 + 63ed00f commit d62adff
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 140 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ heck = "0.4.0"
lexiclean = "0.0.1"
libc = "0.2.0"
log = "0.4.4"
num_cpus = "1.15.0"
regex = "1.5.4"
serde = { version = "1.0.130", features = ["derive", "rc"] }
serde_json = "1.0.68"
Expand Down
263 changes: 135 additions & 128 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,134 +113,140 @@ You can also set the shell using command-line arguments. For example, to use Pow
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://forge.rust-lang.org/release/platform-support.html">Various</a></td>
<td><a href="https://www.rust-lang.org">Cargo</a></td>
<td><a href="https://crates.io/crates/just">just</a></td>
<td><code>cargo install just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a></td>
<td><a href="https://scoop.sh">Scoop</a></td>
<td><a href="https://github.com/ScoopInstaller/Main/blob/master/bucket/just.json">just</a></td>
<td><code>scoop install just</code></td>
</tr>
<tr>
<td><a href="https://docs.brew.sh/Installation">Various</a></td>
<td><a href="https://brew.sh">Homebrew</a></td>
<td><a href="https://formulae.brew.sh/formula/just">just</a></td>
<td><code>brew install just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/MacOS">macOS</a></td>
<td><a href="https://www.macports.org">MacPorts</a></td>
<td><a href="https://ports.macports.org/port/just/summary">just</a></td>
<td><code>port install just</code></td>
</tr>
<tr>
<td><a href="https://www.archlinux.org">Arch Linux</a></td>
<td><a href="https://wiki.archlinux.org/title/Pacman">pacman</a></td>
<td><a href="https://archlinux.org/packages/community/x86_64/just/">just</a></td>
<td><code>pacman -S just</code></td>
</tr>
<tr>
<td><a href="https://nixos.org/download.html#download-nix">Various</a></td>
<td><a href="https://nixos.org/nix/">Nix</a></td>
<td><a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix">just</a></td>
<td><code>nix-env -iA nixpkgs.just</code></td>
</tr>
<tr>
<td><a href="https://nixos.org/nixos/">NixOS</a></td>
<td><a href="https://nixos.org/nix/">Nix</a></td>
<td><a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix">just</a></td>
<td><code>nix-env -iA nixos.just</code></td>
</tr>
<tr>
<td><a href="https://getsol.us">Solus</a></td>
<td><a href="https://getsol.us/articles/package-management/basics/en">eopkg</a></td>
<td><a href="https://dev.getsol.us/source/just/">just</a></td>
<td><code>eopkg install just</code></td>
</tr>
<tr>
<td><a href="https://voidlinux.org">Void Linux</a></td>
<td><a href="https://wiki.voidlinux.org/XBPS">XBPS</a></td>
<td><a href="https://github.com/void-linux/void-packages/blob/master/srcpkgs/just/template">just</a></td>
<td><code>xbps-install -S just</code></td>
</tr>
<tr>
<td><a href="https://www.freebsd.org">FreeBSD</a></td>
<td><a href="https://www.freebsd.org/doc/handbook/pkgng-intro.html">pkg</a></td>
<td><a href="https://www.freshports.org/deskutils/just/">just</a></td>
<td><code>pkg install just</code></td>
</tr>
<tr>
<td><a href="https://alpinelinux.org">Alpine Linux</a></td>
<td><a href="https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management">apk-tools</a></td>
<td><a href="https://pkgs.alpinelinux.org/package/edge/community/x86_64/just">just</a></td>
<td><code>apk add just</code></td>
</tr>
<tr>
<td><a href="https://getfedora.org">Fedora Linux</a></td>
<td><a href="https://dnf.readthedocs.io/en/latest/">DNF</a></td>
<td><a href="https://src.fedoraproject.org/rpms/rust-just">just</a></td>
<td><code>dnf install just</code></td>
</tr>
<tr>
<td><a href="https://www.gentoo.org">Gentoo Linux</a></td>
<td><a href="https://wiki.gentoo.org/wiki/Portage">Portage</a></td>
<td><a href="https://github.com/gentoo-mirror/dm9pZCAq/tree/master/sys-devel/just">dm9pZCAq/sys-devel/just</a></td>
<td>
<code>eselect repository enable dm9pZCAq</code><br>
<code>emerge --sync dm9pZCAq</code><br>
<code>emerge sys-devel/just</code>
</td>
</tr>
<tr>
<td><a href="https://docs.conda.io/en/latest/miniconda.html#system-requirements">Various</a></td>
<td><a href="https://docs.conda.io/projects/conda/en/latest/index.html">Conda</a></td>
<td><a href="https://anaconda.org/conda-forge/just">just</a></td>
<td><code>conda install -c conda-forge just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a></td>
<td><a href="https://chocolatey.org">Chocolatey</a></td>
<td><a href="https://github.com/michidk/just-choco">just</a></td>
<td><code>choco install just</code></td>
</tr>
<tr>
<td><a href="https://snapcraft.io/docs/installing-snapd">Various</a></td>
<td><a href="https://snapcraft.io">Snap</a></td>
<td><a href="https://snapcraft.io/just">just</a></td>
<td><code>snap install --edge --classic just</code></td>
</tr>
<tr>
<td><a href="https://github.com/casey/just/releases">Various</a></td>
<td><a href="https://asdf-vm.com">asdf</a></td>
<td><a href="https://github.com/olofvndrhr/asdf-just">just</a></td>
<td>
<code>asdf plugin add just</code><br>
<code>asdf install just &lt;version&gt;</code>
</td>
</tr>
<tr>
<td><a href="https://debian.org">Debian</a> and <a href="https://ubuntu.com">Ubuntu</a> derivatives</td>
<td><a href="https://mpr.makedeb.org">MPR</a></td>
<td><a href="https://mpr.makedeb.org/packages/just">just</a></td>
<td>
<code>git clone 'https://mpr.makedeb.org/just'</code><br>
<code>cd just</code><br>
<code>makedeb -si</code>
</td>
</tr>
<tr>
<td><a href="https://debian.org">Debian</a> and <a href="https://ubuntu.com">Ubuntu</a> derivatives</td>
<td><a href="https://docs.makedeb.org/prebuilt-mpr">Prebuilt-MPR</a></td>
<td><a href="https://mpr.makedeb.org/packages/just">just</a></td>
<td>
<sup><b>You must have the <a href="https://docs.makedeb.org/prebuilt-mpr/getting-started/#setting-up-the-repository">Prebuilt-MPR set up</a> on your system in order to run this command.</b></sup><br>
<code>sudo apt install just</code>
</td>
</tr>
<tr>
<td><a href="https://forge.rust-lang.org/release/platform-support.html">Various</a></td>
<td><a href="https://www.rust-lang.org">Cargo</a></td>
<td><a href="https://crates.io/crates/just">just</a></td>
<td><code>cargo install just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a></td>
<td><a href="https://scoop.sh">Scoop</a></td>
<td><a href="https://github.com/ScoopInstaller/Main/blob/master/bucket/just.json">just</a></td>
<td><code>scoop install just</code></td>
</tr>
<tr>
<td><a href="https://docs.brew.sh/Installation">Various</a></td>
<td><a href="https://brew.sh">Homebrew</a></td>
<td><a href="https://formulae.brew.sh/formula/just">just</a></td>
<td><code>brew install just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/MacOS">macOS</a></td>
<td><a href="https://www.macports.org">MacPorts</a></td>
<td><a href="https://ports.macports.org/port/just/summary">just</a></td>
<td><code>port install just</code></td>
</tr>
<tr>
<td><a href="https://www.archlinux.org">Arch Linux</a></td>
<td><a href="https://wiki.archlinux.org/title/Pacman">pacman</a></td>
<td><a href="https://archlinux.org/packages/community/x86_64/just/">just</a></td>
<td><code>pacman -S just</code></td>
</tr>
<tr>
<td><a href="https://nixos.org/download.html#download-nix">Various</a></td>
<td><a href="https://nixos.org/nix/">Nix</a></td>
<td><a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix">just</a></td>
<td><code>nix-env -iA nixpkgs.just</code></td>
</tr>
<tr>
<td><a href="https://nixos.org/nixos/">NixOS</a></td>
<td><a href="https://nixos.org/nix/">Nix</a></td>
<td><a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix">just</a></td>
<td><code>nix-env -iA nixos.just</code></td>
</tr>
<tr>
<td><a href="https://getsol.us">Solus</a></td>
<td><a href="https://getsol.us/articles/package-management/basics/en">eopkg</a></td>
<td><a href="https://dev.getsol.us/source/just/">just</a></td>
<td><code>eopkg install just</code></td>
</tr>
<tr>
<td><a href="https://voidlinux.org">Void Linux</a></td>
<td><a href="https://wiki.voidlinux.org/XBPS">XBPS</a></td>
<td><a href="https://github.com/void-linux/void-packages/blob/master/srcpkgs/just/template">just</a></td>
<td><code>xbps-install -S just</code></td>
</tr>
<tr>
<td><a href="https://www.freebsd.org">FreeBSD</a></td>
<td><a href="https://www.freebsd.org/doc/handbook/pkgng-intro.html">pkg</a></td>
<td><a href="https://www.freshports.org/deskutils/just/">just</a></td>
<td><code>pkg install just</code></td>
</tr>
<tr>
<td><a href="https://alpinelinux.org">Alpine Linux</a></td>
<td><a href="https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management">apk-tools</a></td>
<td><a href="https://pkgs.alpinelinux.org/package/edge/community/x86_64/just">just</a></td>
<td><code>apk add just</code></td>
</tr>
<tr>
<td><a href="https://getfedora.org">Fedora Linux</a></td>
<td><a href="https://dnf.readthedocs.io/en/latest/">DNF</a></td>
<td><a href="https://src.fedoraproject.org/rpms/rust-just">just</a></td>
<td><code>dnf install just</code></td>
</tr>
<tr>
<td><a href="https://www.gentoo.org">Gentoo Linux</a></td>
<td><a href="https://wiki.gentoo.org/wiki/Portage">Portage</a></td>
<td><a href="https://github.com/gentoo-mirror/dm9pZCAq/tree/master/sys-devel/just">dm9pZCAq/sys-devel/just</a></td>
<td>
<code>eselect repository enable dm9pZCAq</code><br>
<code>emerge --sync dm9pZCAq</code><br>
<code>emerge sys-devel/just</code>
</td>
</tr>
<tr>
<td><a href="https://docs.conda.io/en/latest/miniconda.html#system-requirements">Various</a></td>
<td><a href="https://docs.conda.io/projects/conda/en/latest/index.html">Conda</a></td>
<td><a href="https://anaconda.org/conda-forge/just">just</a></td>
<td><code>conda install -c conda-forge just</code></td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a></td>
<td><a href="https://chocolatey.org">Chocolatey</a></td>
<td><a href="https://github.com/michidk/just-choco">just</a></td>
<td><code>choco install just</code></td>
</tr>
<tr>
<td><a href="https://snapcraft.io/docs/installing-snapd">Various</a></td>
<td><a href="https://snapcraft.io">Snap</a></td>
<td><a href="https://snapcraft.io/just">just</a></td>
<td><code>snap install --edge --classic just</code></td>
</tr>
<tr>
<td><a href="https://github.com/casey/just/releases">Various</a></td>
<td><a href="https://asdf-vm.com">asdf</a></td>
<td><a href="https://github.com/olofvndrhr/asdf-just">just</a></td>
<td>
<code>asdf plugin add just</code><br>
<code>asdf install just &lt;version&gt;</code>
</td>
</tr>
<tr>
<td><a href="https://debian.org">Debian</a> and <a href="https://ubuntu.com">Ubuntu</a> derivatives</td>
<td><a href="https://mpr.makedeb.org">MPR</a></td>
<td><a href="https://mpr.makedeb.org/packages/just">just</a></td>
<td>
<code>git clone 'https://mpr.makedeb.org/just'</code><br>
<code>cd just</code><br>
<code>makedeb -si</code>
</td>
</tr>
<tr>
<td><a href="https://debian.org">Debian</a> and <a href="https://ubuntu.com">Ubuntu</a> derivatives</td>
<td><a href="https://docs.makedeb.org/prebuilt-mpr">Prebuilt-MPR</a></td>
<td><a href="https://mpr.makedeb.org/packages/just">just</a></td>
<td>
<sup><b>You must have the <a href="https://docs.makedeb.org/prebuilt-mpr/getting-started/#setting-up-the-repository">Prebuilt-MPR set up</a> on your system in order to run this command.</b></sup><br>
<code>sudo apt install just</code>
</td>
</tr>
<tr>
<td><a href="https://en.wikipedia.org/wiki/Microsoft_Windows">Microsoft Windows</a></td>
<td><a href="https://learn.microsoft.com/en-us/windows/package-manager/">Windows Package Manager</a></td>
<td><a href="https://github.com/microsoft/winget-pkgs/tree/master/manifests/c/Casey/Just">Casey/Just</a></td>
<td><code>winget install --id Casey.Just --exact</code></td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -1073,6 +1079,7 @@ Done!
#### System Information

- `arch()` — Instruction set architecture. Possible values are: `"aarch64"`, `"arm"`, `"asmjs"`, `"hexagon"`, `"mips"`, `"msp430"`, `"powerpc"`, `"powerpc64"`, `"s390x"`, `"sparc"`, `"wasm32"`, `"x86"`, `"x86_64"`, and `"xcore"`.
- `num_cpus()` - Number of logical CPUs.
- `os()` — Operating system. Possible values are: `"android"`, `"bitrig"`, `"dragonfly"`, `"emscripten"`, `"freebsd"`, `"haiku"`, `"ios"`, `"linux"`, `"macos"`, `"netbsd"`, `"openbsd"`, `"solaris"`, and `"windows"`.
- `os_family()` — Operating system family; possible values are: `"unix"` and `"windows"`.

Expand Down
6 changes: 6 additions & 0 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub(crate) fn get(name: &str) -> Option<Function> {
"kebabcase" => Unary(kebabcase),
"lowercamelcase" => Unary(lowercamelcase),
"lowercase" => Unary(lowercase),
"num_cpus" => Nullary(num_cpus),
"os" => Nullary(os),
"os_family" => Nullary(os_family),
"parent_directory" => Unary(parent_directory),
Expand Down Expand Up @@ -270,6 +271,11 @@ fn lowercase(_context: &FunctionContext, s: &str) -> Result<String, String> {
Ok(s.to_lowercase())
}

fn num_cpus(_context: &FunctionContext) -> Result<String, String> {
let num = num_cpus::get();
Ok(num.to_string())
}

fn os(_context: &FunctionContext) -> Result<String, String> {
Ok(target::os().to_owned())
}
Expand Down
4 changes: 2 additions & 2 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,11 @@ c := a + b + a + b",
x := arch()
a:
{{os()}} {{os_family()}}",
{{os()}} {{os_family()}} {{num_cpus()}}",
"x := arch()
a:
{{ os() }} {{ os_family() }}",
{{ os() }} {{ os_family() }} {{ num_cpus() }}",
}

test! {
Expand Down
26 changes: 26 additions & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl<'src> Lexer<'src> {
',' => self.lex_single(Comma),
'/' => self.lex_single(Slash),
':' => self.lex_colon(),
'\\' => self.lex_escape(),
'=' => self.lex_choices('=', &[('=', EqualsEquals), ('~', EqualsTilde)], Equals),
'@' => self.lex_single(At),
'[' => self.lex_delimiter(BracketL),
Expand Down Expand Up @@ -747,6 +748,31 @@ impl<'src> Lexer<'src> {
Ok(())
}

/// Lex an token starting with '\' escape
fn lex_escape(&mut self) -> CompileResult<'src, ()> {
self.presume('\\')?;

// Treat newline escaped with \ as whitespace
if self.accepted('\n')? {
while self.next_is_whitespace() {
self.advance()?;
}
self.token(Whitespace);
} else if self.accepted('\r')? {
if !self.accepted('\n')? {
return Err(self.error(UnpairedCarriageReturn));
}
while self.next_is_whitespace() {
self.advance()?;
}
self.token(Whitespace);
} else if let Some(character) = self.next {
return Err(self.error(CompileErrorKind::InvalidEscapeSequence { character }));
}

Ok(())
}

/// Lex a carriage return and line feed
fn lex_eol(&mut self) -> CompileResult<'src, ()> {
if self.accepted('\r')? {
Expand Down
Loading

0 comments on commit d62adff

Please sign in to comment.