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

Deprecate = in assignments, aliases, and exports in favor of := #413

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions GRAMMAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ item : recipe
eol : NEWLINE
| COMMENT NEWLINE

assignment : NAME '=' expression eol
alias : 'alias' NAME ':=' NAME

alias : 'alias' NAME '=' NAME
assignment : NAME ':=' expression eol

export : 'export' assignment

expression : value '+' expression
| value

value : NAME '(' arguments? ')'
value : NAME '(' sequence? ')'
| STRING
| RAW_STRING
| BACKTICK
| NAME
| '(' expression ')'

arguments : expression ',' arguments
sequence : expression ',' sequence
| expression ','?

recipe : '@'? NAME parameter* ('+' parameter)? ':' dependencies? body?
Expand Down
46 changes: 23 additions & 23 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ build test deploy lint
Aliases allow recipes to be invoked with alternative names:

```make
alias b = build
alias b := build

build:
echo 'Building!'
Expand Down Expand Up @@ -249,9 +249,9 @@ Available recipes:
Variables, strings, concatenation, and substitution using `{{...}}` are supported:

```make
version = "0.2.7"
tardir = "awesomesauce-" + version
tarball = tardir + ".tar.gz"
version := "0.2.7"
tardir := "awesomesauce-" + version
tarball := tardir + ".tar.gz"

publish:
rm -f {{tarball}}
Expand Down Expand Up @@ -285,29 +285,29 @@ braces:
Double-quoted strings support escape sequences:

```make
string-with-tab = "\t"
string-with-newline = "\n"
string-with-carriage-return = "\r"
string-with-double-quote = "\""
string-with-slash = "\\"
string-with-tab := "\t"
string-with-newline := "\n"
string-with-carriage-return := "\r"
string-with-double-quote := "\""
string-with-slash := "\\"
```

```sh
$ just --evaluate
"tring-with-carriage-return = "
string-with-double-quote = """
string-with-newline = "
"tring-with-carriage-return := "
string-with-double-quote := """
string-with-newline := "
"
string-with-slash = "\"
string-with-tab = " "
string-with-slash := "\"
string-with-tab := " "
```

Single-quoted strings do not recognize escape sequences and may contain line breaks:

```make
escapes = '\t\n\r\"\\'
escapes := '\t\n\r\"\\'

line-breaks = 'hello
line-breaks := 'hello
this
is
a
Expand All @@ -318,9 +318,9 @@ string!

```sh
$ just --evaluate
escapes = "\t\n\r\"\\"
escapes := "\t\n\r\"\\"

line-breaks = "hello
line-breaks := "hello
this
is
a
Expand Down Expand Up @@ -410,7 +410,7 @@ Starting server with database localhost:6379 on port 1337...
Backticks can be used to store the result of commands:

```make
localhost = `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`
localhost := `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`

serve:
./serve {{localhost}} 8080
Expand All @@ -421,7 +421,7 @@ serve:
Variables can be overridden from the command line.

```make
os = "linux"
os := "linux"

test: build
./test --test {{os}}
Expand Down Expand Up @@ -457,7 +457,7 @@ $ just --set os bsd
Assignments prefixed with the `export` keyword will be exported to recipes as environment variables:

```make
export RUST_BACKTRACE = "1"
export RUST_BACKTRACE := "1"

test:
# will print a stack trace if it crashes
Expand Down Expand Up @@ -487,7 +487,7 @@ cd my-awesome-project && make
Parameters may have default values:

```make
default = 'all'
default := 'all'

test target tests=default:
@echo 'Testing {{target}}:{{tests}}...'
Expand All @@ -513,7 +513,7 @@ Testing server:unit...
Default values may be arbitrary expressions, but concatenations must be parenthesized:

```make
arch = "wasm"
arch := "wasm"

test triple=(arch + "-unknown-unknown"):
./test {{triple}}
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# ^ A shebang isn't required, but allows a justfile to be executed
# like a script, with `./justfile test`, for example.

bt='0'
bt = '0'

export RUST_BACKTRACE=bt
export RUST_BACKTRACE = bt

alias t = test

Expand Down
2 changes: 1 addition & 1 deletion src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub struct Alias<'a> {

impl<'a> Display for Alias<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "alias {} = {}", self.name, self.target)
write!(f, "alias {} := {}", self.name, self.target)
}
}
4 changes: 4 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl Color {
self.restyle(Style::new().fg(Red).bold())
}

pub fn warning(self) -> Color {
self.restyle(Style::new().fg(Yellow).bold())
}

pub fn banner(self) -> Color {
self.restyle(Style::new().fg(Cyan).bold())
}
Expand Down
5 changes: 3 additions & 2 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Justfile<'a> {
pub assignments: BTreeMap<&'a str, Expression<'a>>,
pub exports: BTreeSet<&'a str>,
pub aliases: BTreeMap<&'a str, Alias<'a>>,
pub deprecated_equals: bool,
}

impl<'a> Justfile<'a> where {
Expand Down Expand Up @@ -80,7 +81,7 @@ impl<'a> Justfile<'a> where {
}

for (name, value) in scope {
println!("{0:1$} = \"{2}\"", name, width, value);
println!("{0:1$} := \"{2}\"", name, width, value);
}
return Ok(());
}
Expand Down Expand Up @@ -175,7 +176,7 @@ impl<'a> Display for Justfile<'a> {
if self.exports.contains(name) {
write!(f, "export ")?;
}
write!(f, "{} = {}", name, expression)?;
write!(f, "{} := {}", name, expression)?;
items -= 1;
if items != 0 {
write!(f, "\n\n")?;
Expand Down
16 changes: 15 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl<'a> Lexer<'a> {
'@' => self.lex_single(At),
'=' => self.lex_single(Equals),
',' => self.lex_single(Comma),
':' => self.lex_single(Colon),
':' => self.lex_colon(),
'(' => self.lex_single(ParenL),
')' => self.lex_single(ParenR),
'{' => self.lex_brace_l(),
Expand Down Expand Up @@ -442,6 +442,20 @@ impl<'a> Lexer<'a> {
Ok(())
}

/// Lex a token starting with ':'
fn lex_colon(&mut self) -> CompilationResult<'a, ()> {
self.advance()?;

if let Some('=') = self.next {
self.advance()?;
self.token(ColonEquals);
} else {
self.token(Colon);
}

Ok(())
}

/// Lex a token starting with '{'
fn lex_brace_l(&mut self) -> CompilationResult<'a, ()> {
if !self.rest_starts_with("{{") {
Expand Down
Loading